snapshot
This commit is contained in:
32
libraries/audio-tools/tests-cmake/codec/opus/CMakeLists.txt
Normal file
32
libraries/audio-tools/tests-cmake/codec/opus/CMakeLists.txt
Normal file
@@ -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 libopus
|
||||
FetchContent_Declare(arduino_libopus GIT_REPOSITORY "https://github.com/pschatzmann/codec-opus.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)
|
||||
# set preprocessor defines
|
||||
target_compile_definitions(opus PUBLIC -DARDUINO -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")
|
||||
|
||||
51
libraries/audio-tools/tests-cmake/codec/opus/opus.cpp
Normal file
51
libraries/audio-tools/tests-cmake/codec/opus/opus.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @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 "AudioTools/AudioCodecs/CodecOpus.h"
|
||||
|
||||
int sample_rate = 24000;
|
||||
int channels = 1; // The stream will have 2 channels
|
||||
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial, 2); // Output of sound on desktop
|
||||
OpusAudioEncoder enc;
|
||||
OpusAudioDecoder dec;
|
||||
EncodedAudioStream decoder(&out, &dec); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, &enc); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Debug);
|
||||
|
||||
|
||||
// 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 = OPUS_APPLICATION_AUDIO;
|
||||
encoder.begin(cfgs);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user