From bcef45bd117bed7990086d8eb204fc2a500dfae7 Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Sat, 1 May 2021 10:42:05 +0200 Subject: [PATCH] int24_t and scaling --- README.md | 3 ++- sandbox/test_int24/test_int24.ino | 21 +++++++++++++++++++ src/AudioTools.h | 2 +- src/AudioTools/{SoundTypes.h => AudioTypes.h} | 8 +++++-- src/AudioTools/Converter.h | 2 +- src/AudioTools/I2S.h | 2 +- 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 sandbox/test_int24/test_int24.ino rename src/AudioTools/{SoundTypes.h => AudioTypes.h} (89%) diff --git a/README.md b/README.md index 01fd5bb7bb..9a36ff9010 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Some basic C++ classes that can be used for Audio Processing privided as Arduino - NBuffer (Multi buffer for writing and reading of (audio) data) - TimerAlarmRepeating (e.g. for sampling audio data using exact times) [ESP32 only] - A Wav Encoder and Decoder +- AudioOutputWithCallback class to provide callback integration with ESP8266Audio This functionality provides the glue which makes different audio processing components and libraries work together. We also provide plenty of examples that demonstrate how to implement the different scenarios. @@ -62,5 +63,5 @@ This is currently work in progress: | Streams | open | | WAV encoding/deconding | open | | AAC encoding/deconding | open | -| int24_t | open | +| int24_t | tested | diff --git a/sandbox/test_int24/test_int24.ino b/sandbox/test_int24/test_int24.ino new file mode 100644 index 0000000000..639cc0dedf --- /dev/null +++ b/sandbox/test_int24/test_int24.ino @@ -0,0 +1,21 @@ +#include "AudioTools.h" + +using namespace audio_tools; + +void setup(){ + int24_t value; + Serial.begin(115200); + + for (int32_t j=8388607;j>-8388606;j++){ + value = j; + Serial.print(j); + Serial.print(", "); + Serial.print((int32_t)value); + Serial.println((int32_t)value == j ? ", OK" : ", ERROR"); + } + +} + +void loop(){ + +} \ No newline at end of file diff --git a/src/AudioTools.h b/src/AudioTools.h index 72122bd21a..73dec9fc3a 100644 --- a/src/AudioTools.h +++ b/src/AudioTools.h @@ -7,7 +7,7 @@ * @copyright GPLv3 * */ -#include "AudioTools/SoundTypes.h" +#include "AudioTools/AudioTypes.h" #include "AudioTools/Buffers.h" #include "AudioTools/Converter.h" #include "AudioTools/MusicalNotes.h" diff --git a/src/AudioTools/SoundTypes.h b/src/AudioTools/AudioTypes.h similarity index 89% rename from src/AudioTools/SoundTypes.h rename to src/AudioTools/AudioTypes.h index 2a3fd50ab9..33ce50a42e 100644 --- a/src/AudioTools/SoundTypes.h +++ b/src/AudioTools/AudioTypes.h @@ -20,6 +20,10 @@ class int24_t { value[2]=0; } + int24_t(void *ptr){ + int24_t(static_cast(ptr)); + } + int24_t(uint8_t *ptr){ value[0]=ptr[0]; value[1]=ptr[1]; @@ -58,8 +62,8 @@ class int24_t { } /// provides value between -2,147,483,647 and 2,147,483,647 - int16_t scale32() { - return static_cast(*this) * INT32_MAX / INT24_MAX; + int32_t scale32() { + return static_cast(*this) / static_cast(INT24_MAX) * static_cast(INT32_MAX) ; } /// provides value between -1.0 and 1.0 diff --git a/src/AudioTools/Converter.h b/src/AudioTools/Converter.h index 8b16208380..2b71f9cee1 100644 --- a/src/AudioTools/Converter.h +++ b/src/AudioTools/Converter.h @@ -1,5 +1,5 @@ #pragma once -#include "SoundTypes.h" +#include "AudioTypes.h" #include "BluetoothA2DPSource.h" namespace audio_tools { diff --git a/src/AudioTools/I2S.h b/src/AudioTools/I2S.h index 554cac0368..6f3a744c71 100644 --- a/src/AudioTools/I2S.h +++ b/src/AudioTools/I2S.h @@ -5,7 +5,7 @@ #include "esp_a2dp_api.h" #include "driver/i2s.h" #include "freertos/queue.h" -#include "SoundTypes.h" +#include "AudioTypes.h" namespace audio_tools {