snapshot
This commit is contained in:
10
libraries/audio-tools/examples/examples-desktop/README.md
Normal file
10
libraries/audio-tools/examples/examples-desktop/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Desktop
|
||||
|
||||
You can use the AudioTools on the desktop w/o Arduino: Just compile your sketch with the following steps
|
||||
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake ..
|
||||
- make
|
||||
|
||||
Further information can be found in the [Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki)!
|
||||
@@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# set the project name
|
||||
project(generator)
|
||||
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()
|
||||
|
||||
# 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 sketch as executable
|
||||
set_source_files_properties(generator.ino PROPERTIES LANGUAGE CXX)
|
||||
add_executable (generator generator.ino)
|
||||
|
||||
# set preprocessor defines
|
||||
target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN)
|
||||
target_compile_definitions(generator PUBLIC -DARDUINO -DIS_DESKTOP)
|
||||
|
||||
# specify libraries
|
||||
target_link_libraries(generator portaudio arduino_emulator arduino-audio-tools)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# 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.
|
||||
|
||||
You just need to provide an Arduino Sketch as cpp file. In our example we use an example setup that can be compiled both in Arduin and with cmake:
|
||||
|
||||
- the sketch is provided as ino file
|
||||
- the cpp file is including the Arduino.h and the ino file
|
||||
|
||||
To build the example execute
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/PortAudioStream.h"
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in(sineWave); // Stream generated from sine wave
|
||||
PortAudioStream out; // On desktop we use
|
||||
StreamCopy copier(out, in); // copy in to out
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// open output
|
||||
auto config = out.defaultConfig();
|
||||
config.copyFrom(info);
|
||||
out.begin(config);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop
|
||||
void loop() {
|
||||
if (out) copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# set the project name
|
||||
project(min-generator)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (DCMAKE_CXX_FLAGS "-Werror")
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# Deactivate Emulator and Portaudio
|
||||
set(ADD_ARDUINO_EMULATOR OFF CACHE BOOL "Add Arduino Emulator Library")
|
||||
set(ADD_PORTAUDIO OFF CACHE BOOL "Add Portaudio Library")
|
||||
|
||||
# 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
|
||||
set_source_files_properties(min-generator.ino PROPERTIES LANGUAGE CXX)
|
||||
add_executable (min-generator min-generator.ino)
|
||||
|
||||
# set preprocessor defines
|
||||
target_compile_definitions(min-generator PUBLIC -DIS_MIN_DESKTOP)
|
||||
|
||||
# specify libraries
|
||||
target_link_libraries(min-generator arduino-audio-tools)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Minimum Desktop Runtime
|
||||
|
||||
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.
|
||||
|
||||
This example is not using the Arduino-Emulator!
|
||||
|
||||
You just need to provide an Arduino Sketch as cpp file. In our example we use an example setup that can be compiled both in Arduin and with cmake:
|
||||
|
||||
- the sketch is provided as ino file
|
||||
- you must not include Arduino.h since this is not available
|
||||
|
||||
To build the example execute
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in(sineWave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out; // Or use StdOuput
|
||||
StreamCopy copier(out, in); // copy in to out
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// open output
|
||||
auto config = out.defaultConfig();
|
||||
config.copyFrom(info);
|
||||
out.begin(config);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# set the project name
|
||||
project(mp3_dt)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (DCMAKE_CXX_FLAGS "-Werror")
|
||||
|
||||
include(FetchContent)
|
||||
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
|
||||
option(ADD_PORTAUDIO "Add Portaudio Library" ON)
|
||||
|
||||
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(arduino_helix GIT_REPOSITORY "https://github.com/pschatzmann/arduino-libhelix.git" GIT_TAG main )
|
||||
FetchContent_GetProperties(arduino_helix)
|
||||
if(NOT arduino_helix_POPULATED)
|
||||
FetchContent_Populate(arduino_helix)
|
||||
add_subdirectory(${arduino_helix_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# build sketch as executable
|
||||
set_source_files_properties(mp3.ino PROPERTIES LANGUAGE CXX)
|
||||
add_executable (mp3_dt mp3.ino)
|
||||
|
||||
# set preprocessor defines
|
||||
target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN)
|
||||
target_compile_definitions(arduino_helix PUBLIC -DARDUINO -DHELIX_LOGGING_ACTIVE=0)
|
||||
target_compile_definitions(mp3_dt PUBLIC -DIS_DESKTOP)
|
||||
|
||||
# OS/X might need this setting for core audio
|
||||
target_compile_options(portaudio PRIVATE -Wno-deprecated)
|
||||
|
||||
# specify libraries
|
||||
target_link_libraries(mp3_dt portaudio arduino_emulator arduino-audio-tools arduino_helix)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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
|
||||
```
|
||||
|
||||
32
libraries/audio-tools/examples/examples-desktop/mp3/mp3.ino
Normal file
32
libraries/audio-tools/examples/examples-desktop/mp3/mp3.ino
Normal file
@@ -0,0 +1,32 @@
|
||||
// Simple wrapper for Arduino sketch to compilable with cpp in cmake
|
||||
#include "Arduino.h"
|
||||
#include "AudioTools.h"
|
||||
#include "BabyElephantWalk60_mp3.h"
|
||||
#include "AudioTools/AudioLibs/PortAudioStream.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
|
||||
|
||||
MemoryStream mp3(BabyElephantWalk60_mp3, BabyElephantWalk60_mp3_len);
|
||||
PortAudioStream out; // Output of sound on desktop
|
||||
EncodedAudioStream dec(&out, new MP3DecoderHelix()); // MP3 data source
|
||||
StreamCopy copier(dec, mp3); // copy in to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
out.begin();
|
||||
mp3.begin();
|
||||
dec.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if (mp3) {
|
||||
copier.copy();
|
||||
} else {
|
||||
auto info = dec.decoder().audioInfo();
|
||||
LOGI("The audio rate from the mp3 file is %d", info.sample_rate);
|
||||
LOGI("The channels from the mp3 file is %d", info.channels);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user