Skip to content

Commit 358c6b6

Browse files
authored
Merge branch 'main' into feature-files
2 parents 5525d85 + 30c9991 commit 358c6b6

File tree

61 files changed

+5242
-629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5242
-629
lines changed

CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ cmake_minimum_required(VERSION 3.0)
33
# set the project name
44
project(arduino-audio-tools)
55

6+
include(FetchContent)
7+
68
add_library(arduino-audio-tools INTERFACE)
79

8-
option(BUILD_TESTS "Build all tests automatically" OFF)
10+
#option(BUILD_TESTS "Build all tests automatically" OFF)
11+
option(ADD_STD_LIB "Add Standard Desktop Libraries" ON)
912

1013

1114
# make include directory available to calling projects
@@ -18,8 +21,22 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" # source directory
1821
PATTERN "*.h" # select header files
1922
)
2023

21-
if (BUILD_TESTS)
22-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
23-
else()
24-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests EXCLUDE_FROM_ALL)
24+
# Add basic libraries necessary for desktop build
25+
if (ADD_STD_LIB)
26+
27+
FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG v19.7.0 )
28+
FetchContent_GetProperties(portaudio)
29+
if(NOT portaudio_POPULATED)
30+
FetchContent_Populate(portaudio)
31+
add_subdirectory(${portaudio_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/portaudio)
32+
endif()
33+
34+
# Build with Linux Arduino Emulator
35+
FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main )
36+
FetchContent_GetProperties(arduino_emulator)
37+
if(NOT arduino_emulator_POPULATED)
38+
FetchContent_Populate(arduino_emulator)
39+
add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator)
40+
endif()
41+
2542
endif()

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ As “Audio Sinks” we will have e.g:
4848
- ID3 Metadata for MP3 - [MetaDataID3](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_meta_data_i_d3.html)
4949
- A Timer based Sink - [TimerCallbackAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_timer_callback_audio_stream.html)
5050
- ESP32 AudioKit - [AudioKitStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_kit_stream.html)
51+
- VS1053 Codec Module - [VS1053Stream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_v_s1053_stream.html)
5152
- Callback integration e.g. with ESP8266Audio [AudioOutputWithCallback](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_output_with_callback.html)
5253
- Output using FIR, IRR Filters - [FilteredStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_filtered_stream.html)
5354
- Determine the Volume - [VolumePrint](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_volume_print.html)
@@ -121,19 +122,19 @@ Dependent on the example you might need to install some of the following librari
121122
- [ESP32-A2DP Library](https://github.com/pschatzmann/ESP32-A2DP) to support A2DP Bluetooth Audio
122123
- [Many Codec Libraries](https://github.com/pschatzmann/arduino-audio-tools/wiki/Encoding-and-Decoding-of-Audio) which are described in the Wiki
123124
- [arduino-audiokit](https://github.com/pschatzmann/arduino-audiokit) Support for the __ESP32 AudioKit__ and decoder chips (ES8388, A1S, etc)
125+
- [arduino-vs1053](https://github.com/pschatzmann/arduino-vs1053) Support for __VS1053 audio modules__
124126
- [arduino-midi](https://github.com/pschatzmann/arduino-midi) A simple __MIDI__ message parser and generator
125127
- [SAM](https://github.com/pschatzmann/arduino-SAM) A Text to Speech Engine
126128
- [TTS](https://github.com/pschatzmann/TTS) A Text to Speech Engine
127129
- [flite](https://github.com/pschatzmann/arduino-flite) A Text to Speech Engine
128-
- [simple-tts](https://github.com/pschatzmann/arduino-simple-tts) A Simple TTS engine which is based on prerecorded audio (Talking Clock, Talking Numbers)
130+
- [simple-tts](https://github.com/pschatzmann/arduino-simple-tts) A Simple TTS engine using prerecorded audio (e.g. to implement Talking Clock, Talking Numbers)
129131
- [arduino-stk](https://github.com/pschatzmann/Arduino-STK) Synthesis ToolKit in C++ (STK)
130132
- [Maximilian](https://github.com/pschatzmann/Maximilian) cross-platform and multi-target audio synthesis and signal processing library
131133
- [Mozzi](https://github.com/pschatzmann/Mozzi) A sound synthesis library for Arduino
132-
- [rp2040-i2s](https://github.com/pschatzmann/rp2040-i2s) I2S library for RP2040 (mbed)
133134
- [Tensorflow Lite](https://github.com/pschatzmann/tflite-micro-arduino-examples) Machine Learning for Arduino
134135
- [KissFFT](https://github.com/pschatzmann/kissfft) Fast Fourier Transform FFT Library
135136
- [esp32-fft](https://github.com/pschatzmann/esp32-fft) Another FFT library (not only for the ESP32)
136-
- [rp2040-i2s](https://github.com/pschatzmann/rp2040-i2s) I2S for MBED RP2040
137+
- [rp2040-i2s](https://github.com/pschatzmann/rp2040-i2s) I2S library for MBED RP2040
137138
- [SdFat Library](https://github.com/greiman/SdFat) to read and write files supporting SD cards with FAT16/FAT32 and exFAT
138139
- [SD Library](https://www.arduino.cc/en/reference/SD) to read and write files supporting SD cards with FAT16 and FAT32
139140

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @file streams-audiokit-sd-audiokit.ino
3+
* @author Phil Schatzmann
4+
* @brief We record the input from the microphone to SPI RAM and constantly repeat to play the file
5+
* The input is triggered by pressing key 1. Recording stops when key 1 is released!
6+
* @version 0.1
7+
* @date 2022-09-01
8+
*
9+
* @copyright Copyright (c) 2022
10+
*
11+
*/
12+
#include "AudioTools.h"
13+
#include "AudioLibs/AudioKit.h"
14+
#include "AudioLibs/MemoryManager.h"
15+
16+
uint16_t sample_rate = 16000;
17+
uint8_t channels = 1; // The stream will have 2 channels
18+
AudioKitStream kit;
19+
MemoryManager memory(500); // Activate SPI RAM for objects > 500 bytes
20+
DynamicMemoryStream recording(true); // Audio stored on heap
21+
StreamCopy copier; // copies data
22+
23+
24+
void record_start(bool pinStatus, int pin, void* ref){
25+
Serial.println("Recording...");
26+
recording.begin();
27+
copier.begin(recording, kit);
28+
}
29+
30+
void record_end(bool pinStatus, int pin, void* ref){
31+
Serial.println("Playing...");
32+
33+
// Remove popping noise, from button: we delete 6 segments at the beginning and end
34+
// and on the resulting audio we slowly raise the volume on the first segment
35+
// end decrease it on the last segment
36+
recording.postProcessSmoothTransition<int16_t>(channels, 0.01, 6);
37+
38+
copier.begin(kit, recording); // start playback
39+
}
40+
41+
void setup(){
42+
Serial.begin(115200);
43+
while(!Serial); // wait for serial to be ready
44+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
45+
46+
// setup input and output
47+
auto cfg = kit.defaultConfig(RXTX_MODE);
48+
cfg.sd_active = true;
49+
cfg.sample_rate = sample_rate;
50+
cfg.channels = channels;
51+
cfg.input_device = AUDIO_HAL_ADC_INPUT_LINE2;
52+
kit.begin(cfg);
53+
kit.setVolume(1.0);
54+
55+
// record when key 1 is pressed
56+
kit.audioActions().add(PIN_KEY1, record_start, record_end);
57+
Serial.println("Press Key 1 to record");
58+
59+
}
60+
61+
void loop(){
62+
63+
// record or play recording
64+
copier.copy();
65+
66+
// Process keys
67+
kit.processActions();
68+
69+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @file streams-audiokit-sd-audiokit.ino
3+
* @author Phil Schatzmann
4+
* @brief We record the input from the microphone to a file and constantly repeat to play the file
5+
* The input is triggered by pressing key 1. Recording stops when key 1 is released!
6+
* @version 0.1
7+
* @date 2022-09-01
8+
*
9+
* @copyright Copyright (c) 2022
10+
*
11+
*/
12+
#include "AudioTools.h"
13+
#include "AudioLibs/AudioKit.h"
14+
#include <SPI.h>
15+
#include <SD.h>
16+
17+
const char *file_name = "/rec.raw";
18+
uint16_t sample_rate = 16000;
19+
uint8_t channels = 1; // The stream will have 2 channels
20+
AudioKitStream kit;
21+
File file; // final output stream
22+
StreamCopy copier; // copies data
23+
bool recording = false; // flag to make sure that close is only executed one
24+
uint64_t end_time; // trigger to call endRecord
25+
26+
27+
void record_start(bool pinStatus, int pin, void* ref){
28+
Serial.println("Recording...");
29+
// open the output file
30+
file = SD.open(file_name, FILE_WRITE);
31+
copier.begin(file, kit);
32+
recording = true;
33+
}
34+
35+
void record_end(bool pinStatus, int pin, void* ref){
36+
if (recording == true){
37+
Serial.println("Playing...");
38+
file.close();
39+
recording = false;
40+
file = SD.open(file_name); // reopen in read mode
41+
copier.begin(kit, file); // start playback
42+
}
43+
}
44+
45+
void setup(){
46+
Serial.begin(115200);
47+
while(!Serial); // wait for serial to be ready
48+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
49+
50+
// Open SD drive
51+
if (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
52+
Serial.println("Initialization failed!");
53+
while (1); // stop
54+
}
55+
Serial.println("Initialization done.");
56+
57+
// setup input and output
58+
auto cfg = kit.defaultConfig(RXTX_MODE);
59+
cfg.sd_active = true;
60+
cfg.sample_rate = sample_rate;
61+
cfg.channels = channels;
62+
cfg.input_device = AUDIO_HAL_ADC_INPUT_LINE2;
63+
kit.begin(cfg);
64+
kit.setVolume(1.0);
65+
66+
// record when key 1 is pressed
67+
kit.audioActions().add(PIN_KEY1, record_start, record_end);
68+
Serial.println("Press Key 1 to record");
69+
70+
}
71+
72+
void loop(){
73+
74+
// record or play file
75+
copier.copy();
76+
77+
// while playing: at end of file -> reposition to beginning
78+
if (!recording && file.size()>0 && file.available()==0){
79+
file.seek(0);
80+
Serial.println("Replay...");
81+
}
82+
83+
// Process keys
84+
kit.processActions();
85+
86+
}

examples/examples-basic-api/base-adc-a2dp/base-adc-a2dp.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ BluetoothA2DPSource a2dp_source;
2222
ConverterScaler<int16_t> scaler(1.0, -26427, 32700 );
2323

2424
// callback used by A2DP to provide the sound data
25-
int32_t get_sound_data(Frame* frames, int32_t count) {
25+
int32_t get_sound_data(Frame* frames, int32_t frameCount) {
2626
uint8_t *data = (uint8_t*)frames;
27-
int channels = 2;
27+
int frameSize = 4;
2828
size_t len = count * channels * sizeof(int16_t);
29-
// the ADC provides data in 16 bits
30-
size_t result_len = adc.readBytes(data, len);
31-
scaler.convert(data, result_len);
32-
return result_len;
29+
size_t resultBytes = adc.readBytes(data, frameCount*frameSize);
30+
scaler.convert(data, resultBytes);
31+
return resultBytes/frameSize;
3332
}
3433

3534
// Arduino Setup
@@ -42,6 +41,7 @@ void setup(void) {
4241

4342
// start the bluetooth
4443
Serial.println("starting A2DP...");
44+
a2dp_source.set_auto_reconnect(false);
4545
a2dp_source.start("MyMusic", get_sound_data);
4646
}
4747

examples/examples-basic-api/base-i2s-a2dp/base-i2s-a2dp.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void setup(void) {
4949

5050
// start the bluetooth
5151
Serial.println("starting A2DP...");
52+
a2dp_source.set_auto_reconnect(false);
5253
a2dp_source.start("LEXON MINO L", get_sound_data);
5354
}
5455

examples/examples-desktop/generator/CMakeLists.txt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,14 @@ set (DCMAKE_CXX_FLAGS "-Werror")
88
include(FetchContent)
99
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
1010

11-
# # Build with Portaudio
12-
# FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG master )
13-
# FetchContent_GetProperties(portaudio)
14-
# if(NOT portaudio_POPULATED)
15-
# FetchContent_Populate(portaudio)
16-
# add_subdirectory(${portaudio_SOURCE_DIR})
17-
# endif()
18-
19-
# # Build with Linux Arduino Emulator
20-
# FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main )
21-
# FetchContent_GetProperties(arduino_emulator)
22-
# if(NOT arduino_emulator_POPULATED)
23-
# FetchContent_Populate(arduino_emulator)
24-
# add_subdirectory(${arduino_emulator_SOURCE_DIR})
25-
# endif()
26-
2711
# Build with arduino-audio-tools
28-
FetchContent_Declare(arduino_audio_tools GIT_REPOSITORY "https://github.com/pschatzmann/arduino-audio-tools.git" GIT_TAG main )
29-
FetchContent_GetProperties(arduino_audio_tools)
30-
if(NOT arduino_audio_tools_POPULATED)
31-
FetchContent_Populate(arduino_audio_tools)
32-
add_subdirectory(${arduino_audio_tools_SOURCE_DIR})
12+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
13+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools )
3314
endif()
3415

3516
# build sketch as executable
36-
add_executable (generator generator.cpp)
17+
set_source_files_properties(generator.ino PROPERTIES LANGUAGE CXX)
18+
add_executable (generator generator.ino)
3719

3820
# set preprocessor defines
3921
target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN)

examples/examples-desktop/generator/generator.cpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/examples-desktop/mp3/CMakeLists.txt

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,8 @@ set (DCMAKE_CXX_FLAGS "-Werror")
88
include(FetchContent)
99
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
1010

11-
# # Build with Portaudio
12-
# FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG master )
13-
# FetchContent_GetProperties(portaudio)
14-
# if(NOT portaudio_POPULATED)
15-
# FetchContent_Populate(portaudio)
16-
# add_subdirectory(${portaudio_SOURCE_DIR})
17-
# endif()
18-
19-
# # Build with Linux Arduino Emulator
20-
# FetchContent_Declare(arduino_emulator GIT_REPOSITORY "https://github.com/pschatzmann/Arduino-Emulator.git" GIT_TAG main )
21-
# FetchContent_GetProperties(arduino_emulator)
22-
# if(NOT arduino_emulator_POPULATED)
23-
# FetchContent_Populate(arduino_emulator)
24-
# add_subdirectory(${arduino_emulator_SOURCE_DIR})
25-
# endif()
26-
27-
# Build with arduino-audio-tools
28-
FetchContent_Declare(arduino_audio_tools GIT_REPOSITORY "https://github.com/pschatzmann/arduino-audio-tools.git" GIT_TAG main )
29-
FetchContent_GetProperties(arduino_audio_tools)
30-
if(NOT arduino_audio_tools_POPULATED)
31-
FetchContent_Populate(arduino_audio_tools)
32-
add_subdirectory(${arduino_audio_tools_SOURCE_DIR})
11+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
12+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_BINARY_DIR}/arduino-audio-tools )
3313
endif()
3414

3515
# Build with libhelix
@@ -41,7 +21,8 @@ if(NOT arduino_helix_POPULATED)
4121
endif()
4222

4323
# build sketch as executable
44-
add_executable (mp3_dt mp3.cpp)
24+
set_source_files_properties(mp3.ino PROPERTIES LANGUAGE CXX)
25+
add_executable (mp3_dt mp3.ino)
4526

4627
# set preprocessor defines
4728
target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN)

0 commit comments

Comments
 (0)