9#define AUDIOTOOLS_VERSION "1.0.1"
10#define AUDIOTOOLS_MAJOR_VERSION 1
11#define AUDIOTOOLS_MIOR_VERSION 0
14#if defined(IS_MIN_DESKTOP)
16# include "AudioTools/AudioLibs/Desktop/Time.h"
17# include "AudioTools/AudioLibs/Desktop/Main.h"
18# define USE_STREAM_READ_OVERRIDE
23#elif defined(IS_DESKTOP_WITH_TIME_ONLY)
24# include "AudioTools/AudioLibs/Desktop/Time.h"
30#elif defined(IS_DESKTOP)
36# define USE_URL_ARDUINO
37# define USE_STREAM_WRITE_OVERRIDE
38# define USE_STREAM_READ_OVERRIDE
39# define USE_STREAM_READCHAR_OVERRIDE
44typedef WiFiClient WiFiClientSecure;
49#elif defined(ESP32_CMAKE)
51# include "esp_idf_version.h"
56# define USE_STREAM_READ_OVERRIDE
62#include "AudioTools/CoreAudio/AudioRuntime.h"
66#if __has_include("AudioConfigLocal.h")
67#include "AudioConfigLocal.h"
71#ifndef AUDIO_INCLUDE_CORE
72# define AUDIO_INCLUDE_CORE true
76#ifndef PREFER_FIXEDPOINT
77# define PREFER_FIXEDPOINT false
81#ifndef USE_AUDIOTOOLS_NS
82# define USE_AUDIOTOOLS_NS true
93#ifndef USE_AUDIO_LOGGING
94# define USE_AUDIO_LOGGING true
98# define LOG_LEVEL AudioLogger::Warning
102# define LOG_STREAM Serial
105#ifndef LOG_PRINTF_BUFFER_SIZE
106# define LOG_PRINTF_BUFFER_SIZE 303
110# define LOG_METHOD __PRETTY_FUNCTION__
114#ifndef USE_CHECK_MEMORY
115# define USE_CHECK_MEMORY false
121# define USE_OBSOLETE false
128#ifndef DEFAULT_BUFFER_SIZE
129# define DEFAULT_BUFFER_SIZE 1024
132#ifndef DEFAULT_SAMPLE_RATE
133# define DEFAULT_SAMPLE_RATE 44100
136#ifndef DEFAULT_CHANNELS
137# define DEFAULT_CHANNELS 2
140#ifndef DEFAULT_BITS_PER_SAMPLE
141# define DEFAULT_BITS_PER_SAMPLE 16
144#ifndef I2S_DEFAULT_PORT
145# define I2S_DEFAULT_PORT 0
148#ifndef I2S_BUFFER_SIZE
149# define I2S_BUFFER_SIZE 512
152#ifndef I2S_BUFFER_COUNT
153# define I2S_BUFFER_COUNT 6
156#ifndef ANALOG_BUFFER_SIZE
157# define ANALOG_BUFFER_SIZE 512
160#ifndef ANALOG_BUFFER_COUNT
161# define ANALOG_BUFFER_COUNT 6
164#ifndef A2DP_BUFFER_SIZE
165# define A2DP_BUFFER_SIZE 512
168#ifndef A2DP_BUFFER_COUNT
169# define A2DP_BUFFER_COUNT 30
172#ifndef CODEC_DELAY_MS
173# define CODEC_DELAY_MS 10
176#ifndef COPY_DELAY_ON_NODATA
177# define COPY_DELAY_ON_NODATA 10
180#ifndef COPY_RETRY_LIMIT
181# define COPY_RETRY_LIMIT 20
184#ifndef MAX_SINGLE_CHARS
185# define MAX_SINGLE_CHARS 8
190# define HTTP_MAX_LEN 1024
194#ifndef HTTP_CHUNKED_SIZE_MAX_LEN
195# define HTTP_CHUNKED_SIZE_MAX_LEN 80
199#ifndef USE_RESAMPLE_BUFFER
200# define USE_RESAMPLE_BUFFER true
206#ifndef PWM_BUFFER_SIZE
207# define PWM_BUFFER_SIZE 1024
210#ifndef PWM_BUFFER_COUNT
211# define PWM_BUFFER_COUNT 4
214#ifndef PWM_AUDIO_FREQUENCY
215# define PWM_AUDIO_FREQUENCY 30000
228#if defined(ESP32) && defined(CONFIG_IDF_TARGET_ESP32C3)
231# define USE_INT24_FROM_INT
235#if defined(ESP32) && defined(CONFIG_IDF_TARGET_ESP32S2)
239#if defined(ESP32) && defined(CONFIG_IDF_TARGET_ESP32S3)
246#if defined(ESP32) && defined(CONFIG_IDF_TARGET_ESP32C6)
252#if defined(ESP32) && defined(CONFIG_IDF_TARGET_ESP32P4)
264# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
265# define USE_SERVER_ACCEPT true
267# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
268# define USE_CONCURRENCY
270# define USE_PRINT_FLUSH true
272# define USE_PRINT_FLUSH false
274# define USE_SD_SUPPORTS_SPI
276# if !defined(ARDUINO)
277# define USE_IDF_LOGGER
279# if !defined(I2S_USE_APLL)
280# define I2S_USE_APLL false
285#if defined(ESP32) && !defined(ESP32X) && !defined(CONFIG_IDF_TARGET_ESP32H2)
286#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0 , 0)
287# define USE_INT24_FROM_INT
298# define USE_WIFI_CLIENT_SECURE
299# define USE_URL_ARDUINO
300# define USE_AUDIO_SERVER
302# define USE_TOUCH_READ
305#define USE_TYPETRAITS
306#define USE_STREAM_WRITE_OVERRIDE
307#define USE_STREAM_READ_OVERRIDE
308#define USE_EXT_BUTTON_LOGIC
310#define USE_ALLOCATOR true
312#define USE_TASK false
314#define PWM_FREQENCY 30000
315#define PIN_PWM_START 12
316#define PIN_I2S_BCK 14
318#define PIN_I2S_DATA_IN 32
319#define PIN_I2S_DATA_OUT 22
320#define PIN_I2S_MCK -1
322#define PIN_I2S_MUTE -1
323#define SOFT_MUTE_VALUE 0
327#define I2S_AUTO_CLEAR true
330#define URL_STREAM_CORE 0
331#define URL_STREAM_PRIORITY 2
332#define URL_STREAM_BUFFER_COUNT 10
333#define STACK_SIZE 30000
334#define URL_CLIENT_TIMEOUT 60000;
335#define URL_HANDSHAKE_TIMEOUT 120000
343#if ESP_IDF_VERSION_MAJOR < 4 && !defined(I2S_COMM_FORMAT_STAND_I2S)
344# define I2S_COMM_FORMAT_STAND_I2S (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB)
345# define I2S_COMM_FORMAT_STAND_MSB (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB)
346# define I2S_COMM_FORMAT_STAND_PCM_LONG (I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_LONG)
347# define I2S_COMM_FORMAT_STAND_PCM_SHORT (I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_SHORT)
349typedef int eps32_i2s_sample_rate_type;
351typedef uint32_t eps32_i2s_sample_rate_type;
358#if defined(ESP32) && defined(ESP32X)
360# include "esp32-hal-log.h"
362# if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0 , 0)
363# define USE_INT24_FROM_INT
368#define USE_URL_ARDUINO
370#define USE_WIFI_CLIENT_SECURE
372#define USE_AUDIO_SERVER
373#define USE_TYPETRAITS
375#define USE_STREAM_WRITE_OVERRIDE
376#define USE_STREAM_READ_OVERRIDE
378#define USE_ALLOCATOR true
381#define PWM_FREQENCY 30000
382#define PIN_PWM_START 1
383#define PIN_I2S_MCK -1
386#define PIN_I2S_DATA_OUT 8
387#define PIN_I2S_DATA_IN 9
389#define PIN_I2S_MUTE -1
390#define SOFT_MUTE_VALUE 0
394#define I2S_AUTO_CLEAR true
398#define URL_STREAM_CORE 0
399#define URL_STREAM_PRIORITY 2
400#define URL_STREAM_BUFFER_COUNT 10
401#define STACK_SIZE 30000
402#define URL_CLIENT_TIMEOUT 60000;
403#define URL_HANDSHAKE_TIMEOUT 120000
410typedef uint32_t eps32_i2s_sample_rate_type;
416#if defined(ESP32) && defined(CONFIG_IDF_TARGET_ESP32H2)
417#include "esp32-hal-log.h"
418#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0 , 0)
419# define USE_INT24_FROM_INT
428#define USE_TYPETRAITS
430#define USE_STREAM_WRITE_OVERRIDE
431#define USE_STREAM_READ_OVERRIDE
433#define USE_ALLOCATOR true
436#define PWM_FREQENCY 30000
437#define PIN_PWM_START 1
438#define PIN_I2S_MCK -1
441#define PIN_I2S_DATA_OUT 8
442#define PIN_I2S_DATA_IN 9
444#define PIN_I2S_MUTE -1
445#define SOFT_MUTE_VALUE 0
448#define I2S_AUTO_CLEAR true
450typedef uint32_t eps32_i2s_sample_rate_type;
457# include <ESP8266WiFi.h>
460#define USE_TYPETRAITS
463#define USE_AUDIO_SERVER
464#define USE_URL_ARDUINO
466#define PIN_PWM_START 12
467#define PIN_I2S_BCK -1
469#define PIN_I2S_DATA_IN -1
470#define PIN_I2S_DATA_OUT -1
471#define I2S_USE_APLL false
472#define PIN_I2S_MUTE 23
473#define SOFT_MUTE_VALUE 0
475#define USE_SERVER_ACCEPT 1
477#define URL_CLIENT_TIMEOUT 60000;
478#define URL_HANDSHAKE_TIMEOUT 120000
479#define USE_SD_SUPPORTS_SPI
484#if (defined(ARDUINO_SEEED_XIAO_NRF52840_SENSE) || defined(ARDUINO_ARDUINO_NANO33BLE) || defined(ARDUINO_ARCH_MBED_NANO)) && !defined(ARDUINO_ARCH_ZEPHYR)
486#define USE_INT24_FROM_INT
489#define USE_TYPETRAITS
492#define USE_ALT_PIN_SUPPORT
494#define PIN_PWM_START 5
497#define PIN_I2S_DATA_IN 4
498#define PIN_I2S_DATA_OUT 4
500#define PIN_I2S_MUTE -1
501#define SOFT_MUTE_VALUE 0
506#if defined(ARDUINO_ARCH_MBED_RP2040)
511#define USE_ANALOG_ARDUINO
512#define USE_TYPETRAITS
514#define USE_INT24_FROM_INT
516#define PIN_ANALOG_START 26
517#define PIN_PWM_START 6
518#define PIN_I2S_BCK 26
519#define PIN_I2S_WS PIN_I2S_BCK+1
520#define PIN_I2S_DATA_IN 28
521#define PIN_I2S_DATA_OUT 28
523#define PIN_I2S_MUTE -1
524#define SOFT_MUTE_VALUE 0
528#define FIX_SYNC_SYNCHRONIZE
530#ifndef ANALOG_BUFFER_SIZE
531#define ANALOG_BUFFER_SIZE 1024
534#ifndef ANALOG_BUFFERS
535#define ANALOG_BUFFERS 50
541#elif defined(ARDUINO_ARCH_RP2040)
546#define USE_ANALOG_ARDUINO
547#define USE_TYPETRAITS
549#define USE_INT24_FROM_INT
551#define PIN_ANALOG_START 26
552#define PIN_PWM_START 6
553#define PIN_I2S_BCK 26
554#define PIN_I2S_WS PIN_I2S_BCK+1
555#define PIN_I2S_DATA_IN 28
556#define PIN_I2S_DATA_OUT 28
557#define PIN_I2S_MCK -1
559#define PIN_I2S_MUTE -1
560#define SOFT_MUTE_VALUE 0
561#define PIN_CS PIN_SPI0_SS
562#define USE_SERVER_ACCEPT true
568#ifndef ANALOG_BUFFER_SIZE
569#define ANALOG_BUFFER_SIZE 256
572#ifndef ANALOG_BUFFERS
573#define ANALOG_BUFFERS 100
577#define USE_SD_SUPPORTS_SPI
582#define VS1053_DREQ 10
583#define VS1053_CS_SD -1
584#define VS1053_RESET 11
585#define VS1053_DEFINED
589#if (defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_ARCH_RP2040)) && (LWIP_IPV4==1 || LWIP_IPV6==1) &&!defined(NO_WIFI)
592# define USE_WIFI_CLIENT_SECURE
593# define USE_URL_ARDUINO
594# define USE_AUDIO_SERVER
595using WiFiServerSecure = BearSSL::WiFiServerSecure;
604#define NO_INPLACE_INIT_SUPPORT
612#define PIN_PWM_START 6
615#undef PWM_BUFFER_SIZE
616#define PWM_BUFFER_SIZE 125
618#undef DEFAULT_BUFFER_SIZE
619#define DEFAULT_BUFFER_SIZE 125
622#undef USE_AUDIO_LOGGING
623#undef LOG_PRINTF_BUFFER_SIZE
624#define LOG_PRINTF_BUFFER_SIZE 60
630#define PIN_I2S_BCK 13
632#define PIN_I2S_DATA_IN 12
633#define PIN_I2S_DATA_OUT 11
634#define PIN_I2S_MUTE -1
640#if defined(ARDUINO_ARCH_STM32)
649#define USE_ANALOG_ARDUINO
650#define USE_INT24_FROM_INT
652#define PIN_ANALOG_START PA0
653#define PIN_PWM_START PA0
654#define PWM_DEFAULT_TIMER TIM2
655#define PWM_FREQ_TIMER_NO 3
658#define PIN_I2S_BCK -1
660#define PIN_I2S_DATA_IN -1
661#define PIN_I2S_DATA_OUT -1
662#define PIN_I2S_MUTE -1
663#define SOFT_MUTE_VALUE 0
667#define USE_URL_ARDUINO
668#define USE_AUDIO_SERVER
675#ifdef ARDUINO_ARCH_SAMD
676#define NO_INPLACE_INIT_SUPPORT
680#define USE_INT24_FROM_INT
682#define PIN_I2S_WS PIN_I2S_BCK+1
683#define PIN_I2S_DATA_IN 3
684#define PIN_I2S_DATA_OUT 3
685#define PIN_I2S_MUTE -1
686#define SOFT_MUTE_VALUE 0
691#ifdef ARDUINO_SAMD_MKRWIFI1010
693#define USE_URL_ARDUINO
694#define USE_AUDIO_SERVER
699#if defined(ARDUINO_GIGA)
701#include <Arduino_AdvancedAnalog.h>
703#define USE_INT24_FROM_INT
704#define USE_TYPETRAITS
706#define USE_STREAM_WRITE_OVERRIDE
707#define ANALOG_BUFFER_SIZE 1024
708#define ANALOG_BUFFERS 10
709#define USE_URL_ARDUINO
710#define USE_AUDIO_SERVER
712#define PIN_ANALOG_START A7
720#if defined(ARDUINO_ARCH_MBED_PORTENTA)
722#include <Arduino_AdvancedAnalog.h>
724#define USE_INT24_FROM_INT
725#define USE_TYPETRAITS
729#define USE_STREAM_WRITE_OVERRIDE
730#define ANALOG_BUFFER_SIZE 1024
731#define ANALOG_BUFFERS 10
732#define USE_URL_ARDUINO
733#define USE_AUDIO_SERVER
735#define PIN_ANALOG_START A0
736#define PIN_PWM_START D2
743#if defined(ARDUINO_ARCH_RENESAS) || defined(_RENESAS_RA_)
748#define USE_INT24_FROM_INT
750#define USE_TYPETRAITS
753#define PIN_PWM_START D2
754#define PIN_PWM_COUNT 12
756#define USE_ANALOG_ARDUINO
758#define PIN_ANALOG_START A0
759#define ANALOG_BUFFER_SIZE 512
760#define ANALOG_BUFFERS 5
761#define ANALOG_MAX_OUT_CHANNELS 1
762#define ANALOG_MAX_SAMPLE_RATE 16000
767#define VS1053_CS_SD 9
768#define VS1053_RESET 8
769#define VS1053_DEFINED
772#if defined(ARDUINO) && !defined(ARDUINO_MINIMA)
774# define USE_URL_ARDUINO
775# define USE_AUDIO_SERVER
783#ifdef ARDUINO_ARCH_ZEPHYR
785# define NO_INPLACE_INIT_SUPPORT
786# define USE_TYPETRAITS
788# define PIN_I2S_BCK 2
790# define PIN_I2S_DATA_IN 4
791# define PIN_I2S_DATA_OUT 4
793# define PIN_I2S_MUTE -1
794# define SOFT_MUTE_VALUE 0
795# define USE_NANO33BLE
796# define USE_ALT_PIN_SUPPORT
802#ifndef VS1053_DEFINED
804# define VS1053_DCS 16
805# define VS1053_DREQ 4
806# define VS1053_RESET 15
807# define VS1053_CS_SD -1
813#define VS1053_DEFAULT_VOLUME 0.7
820# define USE_STREAM_WRITE_OVERRIDE
823#ifndef ANALOG_MAX_SAMPLE_RATE
824# define ANALOG_MAX_SAMPLE_RATE 44100
827#ifndef PWM_MAX_SAMPLE_RATE
828# define PWM_MAX_SAMPLE_RATE 8000
832#ifndef URL_CLIENT_TIMEOUT
833# define URL_CLIENT_TIMEOUT 60000;
834# define URL_HANDSHAKE_TIMEOUT 120000
838# define USE_TASK false
841#ifndef USE_SERVER_ACCEPT
842# define USE_SERVER_ACCEPT false
846# define USE_ALLOCATOR false
849#ifndef USE_ESP32_LOGGER
850# define USE_ESP32_LOGGER false
854#ifndef USE_PRINT_FLUSH
855# define USE_PRINT_FLUSH true
858#ifndef ESP_IDF_VERSION_VAL
859# define ESP_IDF_VERSION_VAL(a, b , c) 0
863# define CHECK_MEMORY() checkMemory(true)
865# define CHECK_MEMORY()
868#pragma GCC diagnostic ignored "-Wunused-variable"
869#pragma GCC diagnostic ignored "-Wunused-function"
870#pragma GCC diagnostic ignored "-Wvla"
871#pragma GCC diagnostic ignored "-Wsign-compare"
872#pragma GCC diagnostic ignored "-Woverloaded-virtual"
873#pragma GCC diagnostic ignored "-Wdouble-promotion"
875#ifdef USE_NO_MEMACCESS
876#pragma GCC diagnostic ignored "-Wclass-memaccess"
879#ifdef USE_INITIALIZER_LIST
880#pragma GCC diagnostic ignored "-Wnarrowing"
886#include "AudioTools/CoreAudio/AudioBasic/Int24_3bytes_t.h"
887#include "AudioTools/CoreAudio/AudioBasic/Int24_4bytes_t.h"
888#include "AudioTools/CoreAudio/AudioBasic/FloatAudio.h"
891 #ifdef USE_3BYTE_INT24
If you want to use the framework w/o Arduino you need to provide the implementation of a couple of cl...