mirror of
https://github.com/pschatzmann/arduino-audio-tools.git
synced 2024-09-22 02:47:31 +00:00
tests
This commit is contained in:
parent
57799975d4
commit
af8f5bf62e
@ -11,8 +11,6 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief We use a ADS1015 I2S microphone as input and send the data to A2DP
|
||||
* Unfortunatly the data type from the microphone (int32_t) does not match with the required data type by A2DP (int16_t),
|
||||
@ -21,7 +19,6 @@
|
||||
|
||||
BluetoothA2DPSource a2dp_source;
|
||||
I2S<int32_t> i2s;
|
||||
ChannelConverter<int32_t> converter(&NumberConverter::convertFrom32To16);
|
||||
ConverterFillLeftAndRight<int32_t> bothChannels;
|
||||
const size_t max_buffer_len = 1024;
|
||||
int32_t buffer[max_buffer_len][2];
|
||||
|
@ -36,7 +36,7 @@ endif()
|
||||
add_executable (generator generator.cpp)
|
||||
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN)
|
||||
target_compile_definitions(arduino_emulator PUBLIC -©)
|
||||
|
||||
# OS/X might need this setting for core audio
|
||||
#target_compile_definitions(portaudio PUBLIC -DPA_USE_COREAUDIO=1)
|
||||
|
@ -25,9 +25,9 @@ namespace audio_tools {
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
class ChannelConverter {
|
||||
class A2DPChannelConverter {
|
||||
public:
|
||||
ChannelConverter( int16_t (*convert_ptr)(T from)){
|
||||
A2DPChannelConverter( int16_t (*convert_ptr)(T from)){
|
||||
this->convert_ptr = convert_ptr;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "Arduino.h"
|
||||
#include "AudioConfig.h"
|
||||
#include "AudioTools/AudioLogger.h"
|
||||
|
||||
@ -16,3 +17,4 @@ extern "C" void __sync_synchronize(){
|
||||
LOGE("__sync_synchronize not implemented")
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -343,6 +343,49 @@ class ConverterToInternalDACFormat : public BaseConverter<T> {
|
||||
int channels;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief We combine a datastream which consists of multiple channels into less channels. E.g. 2 to 1
|
||||
* The last target channel will contain the combined values of the exceeding source channels.
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
template<typename T>
|
||||
class ChannelReducer : public BaseConverter<T> {
|
||||
public:
|
||||
ChannelReducer(int channelCountOfSource, int channelCountOfTarget=1){
|
||||
from_channels = channelCountOfSource;
|
||||
to_channels = channelCountOfTarget;
|
||||
}
|
||||
|
||||
size_t convert(uint8_t*src, size_t size) {
|
||||
int frame_count = size/(sizeof(T)*from_channels);
|
||||
size_t result_size=0;
|
||||
T* result = (T*)src;
|
||||
T* source = (T*)src;
|
||||
int reduceDiv = from_channels-to_channels+1;
|
||||
|
||||
for(int i=0; i < frame_count; i++){
|
||||
// copy first to_channels-1
|
||||
for (int j=0;j<to_channels-1;j++){
|
||||
*result++ = *source++;
|
||||
result_size += sizeof(T);
|
||||
}
|
||||
// commbined last channels
|
||||
T total = 0;
|
||||
for (int j=to_channels-1;j<from_channels;j++){
|
||||
total += *source++ / reduceDiv;
|
||||
}
|
||||
*result++ = total;
|
||||
result_size += sizeof(T);
|
||||
}
|
||||
return result_size;
|
||||
}
|
||||
|
||||
protected:
|
||||
int from_channels;
|
||||
int to_channels;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Combines multiple converters
|
||||
|
@ -13,7 +13,7 @@ endif()
|
||||
include(FetchContent)
|
||||
|
||||
# Build with Portaudio
|
||||
FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG master )
|
||||
FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG v19.7.0 )
|
||||
FetchContent_GetProperties(portaudio)
|
||||
if(NOT portaudio_POPULATED)
|
||||
FetchContent_Populate(portaudio)
|
||||
@ -28,7 +28,7 @@ if(NOT arduino_emulator_POPULATED)
|
||||
add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator)
|
||||
endif()
|
||||
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generator ${CMAKE_CURRENT_BINARY_DIR}/generator)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/effects ${CMAKE_CURRENT_BINARY_DIR}/effects)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/filter ${CMAKE_CURRENT_BINARY_DIR}/filter)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-helix ${CMAKE_CURRENT_BINARY_DIR}/mp3-helix)
|
||||
|
@ -20,7 +20,7 @@ if(NOT fdk_aac_POPULATED)
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (aac-fdk-encode aac-fdk-encode.cpp)
|
||||
add_executable (aac-fdk-encode aac-fdk-encode.cpp ../main.cpp)
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(aac-fdk-encode PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_FDK -DIS_DESKTOP)
|
||||
|
||||
|
@ -32,7 +32,3 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ if(NOT fdk_aac_POPULATED)
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (aac-fdk aac-fdk.cpp)
|
||||
add_executable (aac-fdk aac-fdk.cpp ../main.cpp)
|
||||
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(aac-fdk PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_FDK -DUSE_PORTAUDIO -DIS_DESKTOP)
|
||||
|
@ -31,7 +31,3 @@ void loop(){
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
@ -19,7 +19,7 @@ if(NOT helix_POPULATED)
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (aac-helix aac-helix.cpp)
|
||||
add_executable (aac-helix aac-helix.cpp ../main.cpp)
|
||||
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(aac-helix PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_HELIX -DUSE_PORTAUDIO -DIS_DESKTOP)
|
||||
|
@ -31,7 +31,3 @@ void loop(){
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (effects effects.cpp)
|
||||
add_executable (effects effects.cpp ../main.cpp)
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(effects PUBLIC -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP)
|
||||
|
||||
|
@ -53,8 +53,3 @@ void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ endif()
|
||||
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (filter filter.cpp)
|
||||
add_executable (filter filter.cpp ../main.cpp)
|
||||
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(filter PUBLIC -DEXIT_ON_STOP -DIS_DESKTOP)
|
||||
|
@ -37,7 +37,3 @@ void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
21
tests/generator/CMakeLists.txt
Normal file
21
tests/generator/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# set the project name
|
||||
project(generator)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (DCMAKE_CXX_FLAGS "-Werror")
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
|
||||
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
|
||||
endif()
|
||||
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (generator generator.cpp ../main.cpp)
|
||||
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(generator PUBLIC -DUSE_PORTAUDIO -DEXIT_ON_STOP -DIS_DESKTOP)
|
||||
|
||||
# specify libraries
|
||||
target_link_libraries(generator portaudio arduino_emulator arduino-audio-tools)
|
||||
|
31
tests/generator/generator.cpp
Normal file
31
tests/generator/generator.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
// Simple wrapper for Arduino sketch to compilable with cpp in cmake
|
||||
#include "Arduino.h"
|
||||
#include "AudioTools.h"
|
||||
#include "AudioLibs/PortAudioStream.h"
|
||||
|
||||
uint16_t sample_rate=44100;
|
||||
uint8_t channels = 2; // The stream will have 2 channels
|
||||
SineWaveGenerator<int16_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in_stream(sine_wave); // Stream generated from sine wave
|
||||
PortAudioStream out; // Output to Desktop
|
||||
StreamCopy copier(out, in_stream); // copies sound to out
|
||||
ChannelReducer<int16_t> reducer(channels,1);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial, AudioLogger::Info);
|
||||
|
||||
sine_wave.begin(channels, sample_rate, N_B4);
|
||||
in_stream.begin();
|
||||
|
||||
auto cfg1 = out.defaultConfig();
|
||||
cfg1.sample_rate = sample_rate;
|
||||
cfg1.channels = 1;
|
||||
cfg1.bits_per_sample = 16;
|
||||
out.begin(cfg1);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy(reducer);
|
||||
}
|
||||
|
9
tests/main.cpp
Normal file
9
tests/main.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#ifdef IS_DESKTOP
|
||||
|
||||
#include "Arduino.h"
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
||||
|
||||
#endif
|
@ -20,7 +20,7 @@ if(NOT helix_POPULATED)
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (mp3-helix mp3-helix.cpp)
|
||||
add_executable (mp3-helix mp3-helix.cpp ../main.cpp)
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(mp3-helix PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_HELIX -DUSE_PORTAUDIO -DIS_DESKTOP)
|
||||
|
||||
|
@ -32,7 +32,3 @@ void loop(){
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
@ -20,10 +20,10 @@ if(NOT arduino_liblame_POPULATED)
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (mp3-lame mp3-lame.cpp)
|
||||
add_executable (mp3-lame mp3-lame.cpp ../main.cpp)
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(mp3-lame PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_LAME -DUSE_PORTAUDIO -DIS_DESKTOP)
|
||||
|
||||
# specify libraries
|
||||
target_link_libraries(mp3-lame arduino_emulator arduino_liblame arduino-audio-tools)
|
||||
target_link_libraries(mp3-lame portaudio arduino_emulator arduino_liblame arduino-audio-tools)
|
||||
|
||||
|
@ -31,8 +31,3 @@ void loop() {
|
||||
Serial.println("512 samples of random data written");
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ if(NOT arduino_libmad_POPULATED)
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (mp3-mad mp3-mad.cpp)
|
||||
add_executable (mp3-mad mp3-mad.cpp ../main.cpp)
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(mp3-mad PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_MAD -DUSE_PORTAUDIO -DIS_DESKTOP)
|
||||
|
||||
|
@ -32,7 +32,3 @@ void loop(){
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
@ -11,7 +11,7 @@ endif()
|
||||
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (mp3-metadata mp3-metadata.cpp)
|
||||
add_executable (mp3-metadata mp3-metadata.cpp ../main.cpp)
|
||||
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(mp3-metadata PUBLIC -DEXIT_ON_STOP -DIS_DESKTOP)
|
||||
|
@ -36,8 +36,3 @@ void loop(){
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
@ -12,7 +12,7 @@ endif()
|
||||
include(FetchContent)
|
||||
|
||||
# build sketch as executable
|
||||
add_executable (url-test url-test.cpp)
|
||||
add_executable (url-test url-test.cpp ../main.cpp)
|
||||
# use main() from arduino_emulator
|
||||
target_compile_definitions(url-test PUBLIC -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP)
|
||||
|
||||
|
@ -20,7 +20,3 @@ void loop(){
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
while(true) loop();
|
||||
}
|
Loading…
Reference in New Issue
Block a user