snapshot
This commit is contained in:
42
libraries/audio-tools/tests-cmake/codec/wav/CMakeLists.txt
Normal file
42
libraries/audio-tools/tests-cmake/codec/wav/CMakeLists.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# set the project name
|
||||
project(wav-test)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (DCMAKE_CXX_FLAGS "-Werror")
|
||||
|
||||
# add_compile_options(-Wstack-usage=1024)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# Add Portaduio for desktop build
|
||||
add_compile_options(-DIS_DESKTOP)
|
||||
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 arduino-adpcm
|
||||
FetchContent_Declare(adpcm_ffmpeg GIT_REPOSITORY "https://github.com/pschatzmann/adpcm" GIT_TAG main )
|
||||
FetchContent_GetProperties(adpcm_ffmpeg)
|
||||
if(NOT adpcm_ffmpeg)
|
||||
FetchContent_Populate(adpcm_ffmpeg)
|
||||
add_subdirectory(${adpcm_ffmpeg_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/adpcm)
|
||||
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 (wav-test wav.cpp)
|
||||
|
||||
# set preprocessor defines
|
||||
target_compile_definitions(wav-test PUBLIC -DARDUINO -DUSE_PORTAUDIO -DIS_DESKTOP)
|
||||
|
||||
# specify libraries
|
||||
target_link_libraries(wav-test portaudio arduino_emulator adpcm_ffmpeg arduino-audio-tools)
|
||||
|
||||
63
libraries/audio-tools/tests-cmake/codec/wav/wav.cpp
Normal file
63
libraries/audio-tools/tests-cmake/codec/wav/wav.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @file test-codec-adpcm.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> PortAudioStream
|
||||
* We can select between PCM and ADPCM
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecWAV.h"
|
||||
#include "AudioTools/AudioCodecs/CodecADPCM.h"
|
||||
#include "AudioTools/AudioLibs/PortAudioStream.h"
|
||||
|
||||
#define USE_ADPCM true
|
||||
|
||||
AudioInfo info(16000, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
//I2SStream out;
|
||||
//PortAudioStream out;
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
#if USE_ADPCM
|
||||
ADPCMDecoder adpcm_decoder(AV_CODEC_ID_ADPCM_IMA_WAV);
|
||||
ADPCMEncoder adpcm_encoder(AV_CODEC_ID_ADPCM_IMA_WAV);
|
||||
EncodedAudioStream decoder(&out, new WAVDecoder(adpcm_decoder, AudioFormat::ADPCM)); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new WAVEncoder(adpcm_encoder, AudioFormat::ADPCM)); // encode and write
|
||||
#else
|
||||
EncodedAudioStream decoder(&out, new WAVDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new WAVEncoder()); // encode and write
|
||||
#endif
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Debug);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting Output...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgs = sineWave.defaultConfig();
|
||||
cfgs.copyFrom(info);
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user