diff --git a/CMakeLists.txt b/CMakeLists.txt index 4561bb50e..dc08dbd40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,12 @@ cmake_minimum_required(VERSION 3.0) # set the project name project(arduino-audio-tools) +include(FetchContent) + add_library(arduino-audio-tools INTERFACE) -option(BUILD_TESTS "Build all tests automatically" OFF) +#option(BUILD_TESTS "Build all tests automatically" OFF) +option(ADD_STD_LIB "Add Standard Desktop Libraries" ON) # make include directory available to calling projects @@ -18,8 +21,22 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" # source directory PATTERN "*.h" # select header files ) -if (BUILD_TESTS) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests) -else() - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests EXCLUDE_FROM_ALL) +# Add basic libraries necessary for desktop build +if (ADD_STD_LIB) + + 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) + add_subdirectory(${portaudio_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/portaudio) + endif() + + # Build with Linux Arduino Emulator + FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main ) + FetchContent_GetProperties(arduino_emulator) + if(NOT arduino_emulator_POPULATED) + FetchContent_Populate(arduino_emulator) + add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator) + endif() + endif() diff --git a/examples/examples-desktop/generator/CMakeLists.txt b/examples/examples-desktop/generator/CMakeLists.txt index bb3c76eea..0cc528b7a 100644 --- a/examples/examples-desktop/generator/CMakeLists.txt +++ b/examples/examples-desktop/generator/CMakeLists.txt @@ -25,11 +25,8 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) # endif() # Build with arduino-audio-tools -FetchContent_Declare(arduino_audio_tools GIT_REPOSITORY "https://github.com/pschatzmann/arduino-audio-tools.git" GIT_TAG main ) -FetchContent_GetProperties(arduino_audio_tools) -if(NOT arduino_audio_tools_POPULATED) - FetchContent_Populate(arduino_audio_tools) - add_subdirectory(${arduino_audio_tools_SOURCE_DIR}) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) endif() # build sketch as executable diff --git a/examples/examples-desktop/mp3/CMakeLists.txt b/examples/examples-desktop/mp3/CMakeLists.txt index c54da43a9..9569c6e48 100644 --- a/examples/examples-desktop/mp3/CMakeLists.txt +++ b/examples/examples-desktop/mp3/CMakeLists.txt @@ -8,28 +8,8 @@ set (DCMAKE_CXX_FLAGS "-Werror") include(FetchContent) option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) -# # Build with Portaudio -# FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG master ) -# FetchContent_GetProperties(portaudio) -# if(NOT portaudio_POPULATED) -# FetchContent_Populate(portaudio) -# add_subdirectory(${portaudio_SOURCE_DIR}) -# endif() - -# # Build with Linux Arduino Emulator -# FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main ) -# FetchContent_GetProperties(arduino_emulator) -# if(NOT arduino_emulator_POPULATED) -# FetchContent_Populate(arduino_emulator) -# add_subdirectory(${arduino_emulator_SOURCE_DIR}) -# endif() - -# Build with arduino-audio-tools -FetchContent_Declare(arduino_audio_tools GIT_REPOSITORY "https://github.com/pschatzmann/arduino-audio-tools.git" GIT_TAG main ) -FetchContent_GetProperties(arduino_audio_tools) -if(NOT arduino_audio_tools_POPULATED) - FetchContent_Populate(arduino_audio_tools) - add_subdirectory(${arduino_audio_tools_SOURCE_DIR}) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) endif() # Build with libhelix diff --git a/examples/examples-desktop/ogg/CMakeLists.txt b/examples/examples-desktop/ogg/CMakeLists.txt deleted file mode 100644 index cc5f5950d..000000000 --- a/examples/examples-desktop/ogg/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -cmake_minimum_required(VERSION 3.21) - -# set the project name -project(ogg) -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() - -include(FetchContent) -option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) - - -# Build with Linux Arduino Emulator -FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main ) -FetchContent_GetProperties(arduino_emulator) -if(NOT arduino_emulator_POPULATED) - FetchContent_Populate(arduino_emulator) - add_subdirectory(${arduino_emulator_SOURCE_DIR}) -endif() - -# Build with arduino-audio-tools -FetchContent_Declare(arduino_audio_tools GIT_REPOSITORY "https://github.com/pschatzmann/arduino-audio-tools.git" GIT_TAG main ) -FetchContent_GetProperties(arduino_audio_tools) -if(NOT arduino_audio_tools_POPULATED) - FetchContent_Populate(arduino_audio_tools) - add_subdirectory(${arduino_audio_tools_SOURCE_DIR}) -endif() - -# Build with arduino-audio-tools -FetchContent_Declare(arduino_libopus GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libopus.git" GIT_TAG main ) -FetchContent_GetProperties(arduino_libopus) -if(NOT arduino_libopus_POPULATED) - FetchContent_Populate(arduino_libopus) - add_subdirectory(${arduino_libopus_SOURCE_DIR}) -endif() - -# build sketch as executable -add_executable (ogg ogg.cpp) - -# set preprocessor defines -target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN -DIS_DESKTOP) -target_compile_definitions(ogg PUBLIC -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP) - -# OS/X might need this setting for core audio -#target_compile_definitions(portaudio PUBLIC -DPA_USE_COREAUDIO=1) - -# specify libraries -target_link_libraries(ogg arduino_emulator arduino-audio-tools arduino_libopus) - diff --git a/examples/examples-desktop/ogg/README.md b/examples/examples-desktop/ogg/README.md deleted file mode 100644 index 0cf95185d..000000000 --- a/examples/examples-desktop/ogg/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Playing Sound on your Desktop - -We provide some generic output which will also work on Linux, Windows and OS/X -The cmake is downloading all dependencies and builds an executable from the sketch. - -We use the more comprehensive new EncodedAudioStream class. - -You just need to provide an Arduino Sketch as cpp file. To build the example execute: - -``` -mkdir build -cd build -cmake .. -make -``` - diff --git a/src/AudioCodecs/CodecOpus.h b/src/AudioCodecs/CodecOpus.h index c95254fb5..d44364533 100644 --- a/src/AudioCodecs/CodecOpus.h +++ b/src/AudioCodecs/CodecOpus.h @@ -95,7 +95,7 @@ struct OpusEncoderSettings : public OpusSettings { /// 0, 1 int use_dtx = -1; /// 5, 10, 20, 40, 80, 120, 160, 200, 240 - int frame_sizes_ms_x2 = 10; /* x2 to avoid 2.5 ms */ + int frame_sizes_ms_x2 = -1; /* x2 to avoid 2.5 ms */ }; /** diff --git a/src/AudioCodecs/ContainerOgg.h b/src/AudioCodecs/ContainerOgg.h index 230a541d6..0a442f37c 100644 --- a/src/AudioCodecs/ContainerOgg.h +++ b/src/AudioCodecs/ContainerOgg.h @@ -257,7 +257,7 @@ class OggContainerEncoder : public AudioEncoder { /// Writes Ogg Packet virtual size_t write(const void *in_ptr, size_t in_size) override { if (!is_open || p_print == nullptr) return 0; - LOGD("write: %u", in_size); + LOGD("write: %d", (int) in_size); op.packet = (uint8_t *)in_ptr; op.bytes = in_size; @@ -294,10 +294,10 @@ class OggContainerEncoder : public AudioEncoder { AudioBaseInfo cfg; virtual bool writePacket(ogg_packet &op, int flag = 0) { - LOGD("writePacket: %u", op.bytes); + LOGD("writePacket: %d", (int) op.bytes); long result = oggz_write_feed(p_oggz, &op, serialno, flag, NULL); if (result < 0) { - LOGE("oggz_write_feed: %d", result); + LOGE("oggz_write_feed: %d", (int) result); return false; } return true; @@ -327,7 +327,7 @@ class OggContainerEncoder : public AudioEncoder { // Final Stream Callback static size_t ogg_io_write(void *user_handle, void *buf, size_t n) { - LOGD("ogg_io_write: %u", n); + LOGD("ogg_io_write: %d", (int) n); OggContainerEncoder *self = (OggContainerEncoder *)user_handle; if (self == nullptr) { LOGE("self is null"); diff --git a/src/AudioLibs/PortAudioStream.h b/src/AudioLibs/PortAudioStream.h index e742810c3..1fcf90cff 100644 --- a/src/AudioLibs/PortAudioStream.h +++ b/src/AudioLibs/PortAudioStream.h @@ -40,7 +40,6 @@ class PortAudioStream : public AudioStreamX { public: PortAudioStream() { LOGD(LOG_METHOD); - this->buffer_size = buffer_size; } ~PortAudioStream(){ diff --git a/src/AudioTools/AudioStreams.h b/src/AudioTools/AudioStreams.h index 5d568e9f1..d1176811e 100644 --- a/src/AudioTools/AudioStreams.h +++ b/src/AudioTools/AudioStreams.h @@ -349,13 +349,13 @@ public: } /// Intializes the processing - virtual bool begin(){ + virtual bool begin() override { clear(); temp_audio.resize(default_buffer_size); return true; } - virtual void end() { + virtual void end() override { clear(); } @@ -648,7 +648,7 @@ class NullStream : public BufferedStream { } /// Define object which need to be notified if the basinfo is changing - void setNotifyAudioChange(AudioBaseInfoDependent &bi) {} + void setNotifyAudioChange(AudioBaseInfoDependent &bi) override {} void setAudioInfo(AudioBaseInfo info) override {} @@ -933,7 +933,7 @@ class VolumeStream : public AudioStreamX { return c; } - bool begin(AudioBaseInfo cfg){ + bool begin(AudioBaseInfo cfg) { VolumeStreamConfig cfg1; cfg1.channels = cfg.channels; cfg1.sample_rate = cfg.sample_rate; @@ -943,7 +943,7 @@ class VolumeStream : public AudioStreamX { return begin(cfg1); } - void end() { + void end() override { is_active = false; } diff --git a/src/AudioTools/AudioStreamsConverter.h b/src/AudioTools/AudioStreamsConverter.h index eb7178385..c3fd242f1 100644 --- a/src/AudioTools/AudioStreamsConverter.h +++ b/src/AudioTools/AudioStreamsConverter.h @@ -84,7 +84,7 @@ class ChannelFormatConverterStreamT : public AudioStreamX { buffer.resize(result_samples); result = converter.convert((uint8_t*)buffer.data(),(uint8_t*) in_data, size); if (result!=result_samples*sizeof(T)){ - LOGE("size %d -> result: %d - expeced: %d", size, result, result_samples*sizeof(T)); + LOGE("size %d -> result: %d - expeced: %d", (int) size, (int) result, (int) result_samples*sizeof(T)); } return result; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 96a91d478..66f473d2a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,24 +9,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() - include(FetchContent) -# Build with Portaudio -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) - add_subdirectory(${portaudio_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/portaudio) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) endif() -# Build with Linux Arduino Emulator -FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main ) -FetchContent_GetProperties(arduino_emulator) -if(NOT arduino_emulator_POPULATED) - FetchContent_Populate(arduino_emulator) - add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator) -endif() add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/resample ${CMAKE_CURRENT_BINARY_DIR}/resample) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generator ${CMAKE_CURRENT_BINARY_DIR}/generator) diff --git a/tests/codec/CMakeLists.txt b/tests/codec/CMakeLists.txt index 07e75fe98..4714124dd 100644 --- a/tests/codec/CMakeLists.txt +++ b/tests/codec/CMakeLists.txt @@ -28,11 +28,13 @@ if(NOT arduino_emulator_POPULATED) add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator) endif() -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-helix ${CMAKE_CURRENT_BINARY_DIR}/mp3-helix) -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/aac-helix ${CMAKE_CURRENT_BINARY_DIR}/aac-helix) -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/aac-fdk ${CMAKE_CURRENT_BINARY_DIR}/aac-fdk) -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/aac-fdk-encode ${CMAKE_CURRENT_BINARY_DIR}/aac-fdk-encode) -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-lame ${CMAKE_CURRENT_BINARY_DIR}/mp3-lame) -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-mad ${CMAKE_CURRENT_BINARY_DIR}/mp3-mad) -#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-metadata ${CMAKE_CURRENT_BINARY_DIR}/mp3-metadata) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/aac-fdk ${CMAKE_CURRENT_BINARY_DIR}/aac-fdk) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/aac-fdk-encode ${CMAKE_CURRENT_BINARY_DIR}/aac-fdk-encode) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-helix ${CMAKE_CURRENT_BINARY_DIR}/mp3-helix) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/aac-helix ${CMAKE_CURRENT_BINARY_DIR}/aac-helix) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-lame ${CMAKE_CURRENT_BINARY_DIR}/mp3-lame) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-mad ${CMAKE_CURRENT_BINARY_DIR}/mp3-mad) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-metadata ${CMAKE_CURRENT_BINARY_DIR}/mp3-metadata) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/opus ${CMAKE_CURRENT_BINARY_DIR}/opus) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/opusogg ${CMAKE_CURRENT_BINARY_DIR}/opusogg) diff --git a/tests/codec/aac-fdk-encode/CMakeLists.txt b/tests/codec/aac-fdk-encode/CMakeLists.txt index 1919138fe..2aa7c0bbf 100644 --- a/tests/codec/aac-fdk-encode/CMakeLists.txt +++ b/tests/codec/aac-fdk-encode/CMakeLists.txt @@ -11,6 +11,11 @@ endif() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + # Build with arduino-fdk-aac FetchContent_Declare(fdk_aac GIT_REPOSITORY "https://github.com/pschatzmann/arduino-fdk-aac.git" GIT_TAG main ) FetchContent_GetProperties(fdk_aac) @@ -20,7 +25,7 @@ if(NOT fdk_aac_POPULATED) endif() # build sketch as executable -add_executable (aac-fdk-encode aac-fdk-encode.cpp ../main.cpp) +add_executable (aac-fdk-encode aac-fdk-encode.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(aac-fdk-encode PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_FDK -DIS_DESKTOP) diff --git a/tests/codec/aac-fdk/CMakeLists.txt b/tests/codec/aac-fdk/CMakeLists.txt index 15767995f..77d1a1c52 100644 --- a/tests/codec/aac-fdk/CMakeLists.txt +++ b/tests/codec/aac-fdk/CMakeLists.txt @@ -10,6 +10,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + # Build with arduino-fdk-aac FetchContent_Declare(fdk_aac GIT_REPOSITORY "https://github.com/pschatzmann/arduino-fdk-aac.git" GIT_TAG main ) FetchContent_GetProperties(fdk_aac) @@ -19,7 +24,7 @@ if(NOT fdk_aac_POPULATED) endif() # build sketch as executable -add_executable (aac-fdk aac-fdk.cpp ../main.cpp) +add_executable (aac-fdk aac-fdk.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(aac-fdk PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_FDK -DUSE_PORTAUDIO -DIS_DESKTOP) diff --git a/tests/codec/aac-helix/CMakeLists.txt b/tests/codec/aac-helix/CMakeLists.txt index 88d5253c4..8eaa80d55 100644 --- a/tests/codec/aac-helix/CMakeLists.txt +++ b/tests/codec/aac-helix/CMakeLists.txt @@ -10,6 +10,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + # Build with libhelix FetchContent_Declare(helix GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libhelix.git" GIT_TAG main ) FetchContent_GetProperties(helix) @@ -19,7 +24,7 @@ if(NOT helix_POPULATED) endif() # build sketch as executable -add_executable (aac-helix aac-helix.cpp ../main.cpp) +add_executable (aac-helix aac-helix.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(aac-helix PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_HELIX -DUSE_PORTAUDIO -DIS_DESKTOP) diff --git a/tests/codec/mp3-helix/CMakeLists.txt b/tests/codec/mp3-helix/CMakeLists.txt index 78e500d10..d1ccd2956 100644 --- a/tests/codec/mp3-helix/CMakeLists.txt +++ b/tests/codec/mp3-helix/CMakeLists.txt @@ -11,6 +11,11 @@ endif() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + # Build with helix FetchContent_Declare(helix GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libhelix.git" GIT_TAG main ) FetchContent_GetProperties(helix) @@ -20,7 +25,7 @@ if(NOT helix_POPULATED) endif() # build sketch as executable -add_executable (mp3-helix mp3-helix.cpp ../main.cpp) +add_executable (mp3-helix mp3-helix.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(mp3-helix PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_HELIX -DUSE_PORTAUDIO -DIS_DESKTOP) diff --git a/tests/codec/mp3-lame/CMakeLists.txt b/tests/codec/mp3-lame/CMakeLists.txt index c4737f958..b206eee86 100644 --- a/tests/codec/mp3-lame/CMakeLists.txt +++ b/tests/codec/mp3-lame/CMakeLists.txt @@ -4,13 +4,18 @@ cmake_minimum_required(VERSION 3.20) project(mp3-lame) 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() +#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() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + # Build with liblame FetchContent_Declare(arduino_liblame GIT_REPOSITORY "https://github.com/pschatzmann/arduino-liblame.git" GIT_TAG main ) FetchContent_GetProperties(arduino_liblame) @@ -20,7 +25,7 @@ if(NOT arduino_liblame_POPULATED) endif() # build sketch as executable -add_executable (mp3-lame mp3-lame.cpp ../main.cpp) +add_executable (mp3-lame mp3-lame.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(mp3-lame PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_LAME -DUSE_PORTAUDIO -DIS_DESKTOP) diff --git a/tests/codec/mp3-mad/CMakeLists.txt b/tests/codec/mp3-mad/CMakeLists.txt index fbfaec007..99fe3d835 100644 --- a/tests/codec/mp3-mad/CMakeLists.txt +++ b/tests/codec/mp3-mad/CMakeLists.txt @@ -4,13 +4,19 @@ cmake_minimum_required(VERSION 3.20) project(mp3-mad) 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() +#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() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + + # Build with libmad FetchContent_Declare(arduino_libmad GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libmad.git" GIT_TAG main ) FetchContent_GetProperties(arduino_libmad) @@ -19,8 +25,8 @@ if(NOT arduino_libmad_POPULATED) add_subdirectory(${arduino_libmad_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libmad) endif() -# build sketch as executable -add_executable (mp3-mad mp3-mad.cpp ../main.cpp) +# build sketch as executabl +add_executable (mp3-mad mp3-mad.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(mp3-mad PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_MAD -DUSE_PORTAUDIO -DIS_DESKTOP ) diff --git a/tests/codec/mp3-metadata/CMakeLists.txt b/tests/codec/mp3-metadata/CMakeLists.txt index b834e8fd8..05f205b1c 100644 --- a/tests/codec/mp3-metadata/CMakeLists.txt +++ b/tests/codec/mp3-metadata/CMakeLists.txt @@ -9,9 +9,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() # build sketch as executable -add_executable (mp3-metadata mp3-metadata.cpp ../main.cpp) +add_executable (mp3-metadata mp3-metadata.cpp ../../main.cpp) # set preprocessor defines target_compile_definitions(mp3-metadata PUBLIC -DEXIT_ON_STOP -DIS_DESKTOP) diff --git a/tests/codec/opus/CMakeLists.txt b/tests/codec/opus/CMakeLists.txt new file mode 100644 index 000000000..a320da545 --- /dev/null +++ b/tests/codec/opus/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.20) + +# set the project name +project(opus) +set (CMAKE_CXX_STANDARD 11) +set (DCMAKE_CXX_FLAGS "-Werror") + +include(FetchContent) + +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + +# Build with libmad +FetchContent_Declare(arduino_libopus GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libopus.git" GIT_TAG main ) +FetchContent_GetProperties(arduino_libopus) +if(NOT arduino_libopus_POPULATED) + FetchContent_Populate(arduino_libopus) + add_subdirectory(${arduino_libopus_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libopus) +endif() + +# build sketch as executable +add_executable (opus opus.cpp ../../main.cpp) +# set preprocessor defines +target_compile_definitions(opus PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_PORTAUDIO -DIS_DESKTOP ) + +# specify libraries +target_link_libraries(opus portaudio arduino_emulator arduino_libopus arduino-audio-tools ) +# ESP32: CONFIG_ARDUINO_LOOP_STACK_SIZE 8192 -> so we test it with this setting "-Wl,-z,stack-size=8192" +# add_link_options("-z,stack-size=8192") + diff --git a/tests/codec/opus/opus.cpp b/tests/codec/opus/opus.cpp new file mode 100644 index 000000000..5c7a835a8 --- /dev/null +++ b/tests/codec/opus/opus.cpp @@ -0,0 +1,58 @@ +/** + * @file test-codec-opus.ino + * @author Phil Schatzmann + * @brief generate sine wave -> encoder -> decoder -> audiokit (i2s) + * @version 0.1 + * @date 2022-04-30 + * + * @copyright Copyright (c) 2022 + * + */ +#include "AudioTools.h" +#include "AudioCodecs/CodecOpus.h" + +int sample_rate = 24000; +int channels = 2; // The stream will have 2 channels +int application = OPUS_APPLICATION_AUDIO; // Opus application + +SineWaveGenerator sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000 +GeneratedSoundStream sound( sineWave); // Stream generated from sine wave +CsvStream out(Serial, 2); // Output of sound on desktop +OpusAudioEncoder enc; +EncodedAudioStream decoder(&out, new OpusAudioDecoder()); // encode and write +EncodedAudioStream encoder(&decoder, &enc); // encode and write +StreamCopy copier(encoder, sound); + +void setup() { + Serial.begin(115200); + AudioLogger::instance().begin(Serial, AudioLogger::Debug); + + // start I2S + Serial.println("starting I2S..."); + auto cfgi = out.defaultConfig(TX_MODE); + cfgi.sample_rate = sample_rate; + cfgi.channels = channels; + cfgi.bits_per_sample = 16; + out.begin(cfgi); + + // Setup sine wave + auto cfgs = sineWave.defaultConfig(); + cfgs.sample_rate = sample_rate; + cfgs.channels = channels; + cfgs.bits_per_sample = 16; + sineWave.begin(cfgs, N_B4); + + // Opus decoder needs to know the audio info + decoder.begin(cfgs); + + // configure and start encoder + enc.config().application = application; + encoder.begin(cfgs); + + Serial.println("Test started..."); +} + + +void loop() { + copier.copy(); +} \ No newline at end of file diff --git a/tests/codec/opusogg/CMakeLists.txt b/tests/codec/opusogg/CMakeLists.txt new file mode 100644 index 000000000..7b05cacdd --- /dev/null +++ b/tests/codec/opusogg/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.20) + +# set the project name +project(opusogg) +set (CMAKE_CXX_STANDARD 11) +set (DCMAKE_CXX_FLAGS "-Werror") + +include(FetchContent) + +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + +# Build with libmad +FetchContent_Declare(arduino_libopus GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libopus.git" GIT_TAG main ) +FetchContent_GetProperties(arduino_libopus) +if(NOT arduino_libopus_POPULATED) + FetchContent_Populate(arduino_libopus) + add_subdirectory(${arduino_libopus_SOURCE_DIR}) +endif() + +# build sketch as executable +add_executable (opusogg opusogg.cpp ../../main.cpp) +# set preprocessor defines +target_compile_definitions(opusogg PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_PORTAUDIO -DIS_DESKTOP ) + +# specify libraries +target_link_libraries(opusogg portaudio arduino_emulator arduino_libopus arduino-audio-tools ) +# ESP32: CONFIG_ARDUINO_LOOP_STACK_SIZE 8192 -> so we test it with this setting "-Wl,-z,stack-size=8192" +# add_link_options("-z,stack-size=8192") + diff --git a/examples/examples-desktop/ogg/ogg.cpp b/tests/codec/opusogg/opusogg.cpp similarity index 64% rename from examples/examples-desktop/ogg/ogg.cpp rename to tests/codec/opusogg/opusogg.cpp index 8bde7de06..90dab7fd5 100644 --- a/examples/examples-desktop/ogg/ogg.cpp +++ b/tests/codec/opusogg/opusogg.cpp @@ -1,5 +1,13 @@ -// Simple wrapper for Arduino sketch to compilable with cpp in cmake -#include "Arduino.h" +/** + * @file test-codec-opusogg.ino + * @author Phil Schatzmann + * @brief generate sine wave -> encoder -> decoder -> audiokit (i2s) + * @version 0.1 + * @date 2022-04-30 + * + * @copyright Copyright (c) 2022 + * + */ #include "AudioTools.h" #include "AudioCodecs/CodecOpusOgg.h" @@ -9,7 +17,7 @@ int application = OPUS_APPLICATION_AUDIO; // Opus application SineWaveGenerator sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000 GeneratedSoundStream sound( sineWave); // Stream generated from sine wave -HexDumpStream out(Serial); +CsvStream out(Serial, channels); // Output of sound on desktop OpusOggEncoder enc; EncodedAudioStream decoder(&out, new OpusOggDecoder()); // encode and write EncodedAudioStream encoder(&decoder, &enc); // encode and write @@ -17,9 +25,15 @@ StreamCopy copier(encoder, sound); void setup() { Serial.begin(115200); - AudioLogger::instance().begin(Serial, AudioLogger::Warning); + AudioLogger::instance().begin(Serial, AudioLogger::Debug); - out.begin(); + // start I2S + // Serial.println("starting I2S..."); + // auto cfgi = out.defaultConfig(TX_MODE); + // cfgi.sample_rate = sample_rate; + // cfgi.channels = channels; + // cfgi.bits_per_sample = 16; + // out.begin(cfgi); // Setup sine wave auto cfgs = sineWave.defaultConfig(); diff --git a/tests/effects/CMakeLists.txt b/tests/effects/CMakeLists.txt index 1cc2d5310..cd4879a3f 100644 --- a/tests/effects/CMakeLists.txt +++ b/tests/effects/CMakeLists.txt @@ -9,6 +9,12 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + + # build sketch as executable add_executable (effects effects.cpp ../main.cpp) # set preprocessor defines diff --git a/tests/filter-wav/CMakeLists.txt b/tests/filter-wav/CMakeLists.txt index 5416814d8..9c7a42341 100644 --- a/tests/filter-wav/CMakeLists.txt +++ b/tests/filter-wav/CMakeLists.txt @@ -9,6 +9,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() # build sketch as executable add_executable (filter-wav filter-wav.cpp ../main.cpp ) diff --git a/tests/filter/CMakeLists.txt b/tests/filter/CMakeLists.txt index d40dd6952..18581d5a4 100644 --- a/tests/filter/CMakeLists.txt +++ b/tests/filter/CMakeLists.txt @@ -9,6 +9,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() # build sketch as executable add_executable (filter filter.cpp ../main.cpp) diff --git a/tests/generator/CMakeLists.txt b/tests/generator/CMakeLists.txt index bd66169f0..81bd40b8e 100644 --- a/tests/generator/CMakeLists.txt +++ b/tests/generator/CMakeLists.txt @@ -9,6 +9,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() # build sketch as executable add_executable (generator_test generator.cpp ../main.cpp) diff --git a/tests/resample/CMakeLists.txt b/tests/resample/CMakeLists.txt index 475fd0d36..b3d822ac5 100644 --- a/tests/resample/CMakeLists.txt +++ b/tests/resample/CMakeLists.txt @@ -9,6 +9,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") endif() +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() # build sketch as executable add_executable (resample resample.cpp ../main.cpp) diff --git a/tests/url-test/CMakeLists.txt b/tests/url-test/CMakeLists.txt index 015954ed6..92f8d2578 100644 --- a/tests/url-test/CMakeLists.txt +++ b/tests/url-test/CMakeLists.txt @@ -11,6 +11,11 @@ endif() include(FetchContent) +# Build with arduino-audio-tools +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools ) +endif() + # build sketch as executable add_executable (url-test url-test.cpp ../main.cpp) # set preprocessor defines