Skip to content

Commit af8f5bf

Browse files
committed
tests
1 parent 5779997 commit af8f5bf

File tree

29 files changed

+123
-63
lines changed

29 files changed

+123
-63
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
#include "AudioTools.h"
1313

14-
15-
1614
/**
1715
* @brief We use a ADS1015 I2S microphone as input and send the data to A2DP
1816
* Unfortunatly the data type from the microphone (int32_t) does not match with the required data type by A2DP (int16_t),
@@ -21,7 +19,6 @@
2119

2220
BluetoothA2DPSource a2dp_source;
2321
I2S<int32_t> i2s;
24-
ChannelConverter<int32_t> converter(&NumberConverter::convertFrom32To16);
2522
ConverterFillLeftAndRight<int32_t> bothChannels;
2623
const size_t max_buffer_len = 1024;
2724
int32_t buffer[max_buffer_len][2];

examples/examples-desktop/generator/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ endif()
3636
add_executable (generator generator.cpp)
3737

3838
# use main() from arduino_emulator
39-
target_compile_definitions(arduino_emulator PUBLIC -DDEFINE_MAIN)
39+
target_compile_definitions(arduino_emulator PUBLIC -©)
4040

4141
# OS/X might need this setting for core audio
4242
#target_compile_definitions(portaudio PUBLIC -DPA_USE_COREAUDIO=1)

src/AudioLibs/AudioA2DP.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ namespace audio_tools {
2525
*/
2626

2727
template<typename T>
28-
class ChannelConverter {
28+
class A2DPChannelConverter {
2929
public:
30-
ChannelConverter( int16_t (*convert_ptr)(T from)){
30+
A2DPChannelConverter( int16_t (*convert_ptr)(T from)){
3131
this->convert_ptr = convert_ptr;
3232
}
3333

src/AudioTools/AudioRuntime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
* @copyright Copyright (c) 2022
99
*
1010
*/
11+
#include "Arduino.h"
1112
#include "AudioConfig.h"
1213
#include "AudioTools/AudioLogger.h"
1314

1415
#if defined(ARDUINO_ARCH_RP2040) && defined(FIX_SYNC_SYNCHRONIZE)
1516
extern "C" void __sync_synchronize(){
1617
LOGE("__sync_synchronize not implemented")
1718
}
18-
#endif
19+
#endif
20+

src/AudioTools/Converter.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,49 @@ class ConverterToInternalDACFormat : public BaseConverter<T> {
343343
int channels;
344344
};
345345

346+
/**
347+
* @brief We combine a datastream which consists of multiple channels into less channels. E.g. 2 to 1
348+
* The last target channel will contain the combined values of the exceeding source channels.
349+
*
350+
* @tparam T
351+
*/
352+
template<typename T>
353+
class ChannelReducer : public BaseConverter<T> {
354+
public:
355+
ChannelReducer(int channelCountOfSource, int channelCountOfTarget=1){
356+
from_channels = channelCountOfSource;
357+
to_channels = channelCountOfTarget;
358+
}
359+
360+
size_t convert(uint8_t*src, size_t size) {
361+
int frame_count = size/(sizeof(T)*from_channels);
362+
size_t result_size=0;
363+
T* result = (T*)src;
364+
T* source = (T*)src;
365+
int reduceDiv = from_channels-to_channels+1;
366+
367+
for(int i=0; i < frame_count; i++){
368+
// copy first to_channels-1
369+
for (int j=0;j<to_channels-1;j++){
370+
*result++ = *source++;
371+
result_size += sizeof(T);
372+
}
373+
// commbined last channels
374+
T total = 0;
375+
for (int j=to_channels-1;j<from_channels;j++){
376+
total += *source++ / reduceDiv;
377+
}
378+
*result++ = total;
379+
result_size += sizeof(T);
380+
}
381+
return result_size;
382+
}
383+
384+
protected:
385+
int from_channels;
386+
int to_channels;
387+
};
388+
346389

347390
/**
348391
* @brief Combines multiple converters

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313
include(FetchContent)
1414

1515
# Build with Portaudio
16-
FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG master )
16+
FetchContent_Declare(portaudio GIT_REPOSITORY "https://github.com/PortAudio/portaudio.git" GIT_TAG v19.7.0 )
1717
FetchContent_GetProperties(portaudio)
1818
if(NOT portaudio_POPULATED)
1919
FetchContent_Populate(portaudio)
@@ -28,7 +28,7 @@ if(NOT arduino_emulator_POPULATED)
2828
add_subdirectory(${arduino_emulator_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/emulator)
2929
endif()
3030

31-
31+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generator ${CMAKE_CURRENT_BINARY_DIR}/generator)
3232
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/effects ${CMAKE_CURRENT_BINARY_DIR}/effects)
3333
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/filter ${CMAKE_CURRENT_BINARY_DIR}/filter)
3434
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mp3-helix ${CMAKE_CURRENT_BINARY_DIR}/mp3-helix)

tests/aac-fdk-encode/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if(NOT fdk_aac_POPULATED)
2020
endif()
2121

2222
# build sketch as executable
23-
add_executable (aac-fdk-encode aac-fdk-encode.cpp)
23+
add_executable (aac-fdk-encode aac-fdk-encode.cpp ../main.cpp)
2424
# use main() from arduino_emulator
2525
target_compile_definitions(aac-fdk-encode PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_FDK -DIS_DESKTOP)
2626

tests/aac-fdk-encode/aac-fdk-encode.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,3 @@ void loop() {
3232
}
3333
}
3434

35-
int main(){
36-
setup();
37-
while(true) loop();
38-
}

tests/aac-fdk/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if(NOT fdk_aac_POPULATED)
1919
endif()
2020

2121
# build sketch as executable
22-
add_executable (aac-fdk aac-fdk.cpp)
22+
add_executable (aac-fdk aac-fdk.cpp ../main.cpp)
2323

2424
# use main() from arduino_emulator
2525
target_compile_definitions(aac-fdk PUBLIC -DARDUINO -DEXIT_ON_STOP -DUSE_FDK -DUSE_PORTAUDIO -DIS_DESKTOP)

tests/aac-fdk/aac-fdk.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@ void loop(){
3131
}
3232
}
3333

34-
int main(){
35-
setup();
36-
while(true) loop();
37-
}

0 commit comments

Comments
 (0)