Logger: Memory Optimization for AVR

This commit is contained in:
Phil Schatzmann 2022-09-18 13:06:08 +02:00
parent b0f8c635a2
commit b03ccb51bd
84 changed files with 544 additions and 518 deletions

View File

@ -173,7 +173,7 @@ class AnalogAudioStream : public AudioStreamX {
/// updates the sample rate dynamically
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
if (adc_config.sample_rate != info.sample_rate
|| adc_config.channels != info.channels
|| adc_config.bits_per_sample != info.bits_per_sample) {
@ -193,7 +193,7 @@ class AnalogAudioStream : public AudioStreamX {
/// starts the DAC
bool begin(AnalogConfig cfg) {
LOGI(LOG_METHOD);
TRACEI();
cfg.logInfo();
if (!is_driver_installed){
@ -318,7 +318,7 @@ class AnalogAudioStream : public AudioStreamX {
/// writes the data to the I2S interface
virtual size_t write(const uint8_t *src, size_t size_bytes) override {
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
if (size_bytes>0 && src!=nullptr){
@ -339,10 +339,10 @@ class AnalogAudioStream : public AudioStreamX {
}
size_t readBytes(uint8_t *dest, size_t size_bytes) override {
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
if (i2s_read(port_no, dest, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
}
LOGD( "%s - len: %d -> %d", __func__, size_bytes, result);
return result;
@ -371,7 +371,7 @@ class AnalogAudioStream : public AudioStreamX {
// The internal DAC only supports 8 bit values - so we need to convert the data
size_t outputStereo(const void *src, size_t size_bytes) {
LOGD(LOG_METHOD);
TRACED();
size_t output_size = 0;
size_t result;
uint16_t *dst = (uint16_t *)src;
@ -412,7 +412,7 @@ class AnalogAudioStream : public AudioStreamX {
// I2S requires stereo so we convert mono to stereo
size_t outputMono(const void *src, size_t size_bytes) {
LOGD(LOG_METHOD);
TRACED();
size_t output_size = 0;
uint16_t out[2];
size_t resultTotal = 0;

View File

@ -143,7 +143,7 @@ class EncodedAudioStream : public AudioPrint {
public:
/// Constructor for AudioStream with automatic notification of audio changes
EncodedAudioStream(AudioStream *outputStream, AudioDecoder *decoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = outputStream;
decoder_ptr = decoder;
decoder_ptr->setOutputStream(*outputStream);
@ -154,7 +154,7 @@ public:
/// Constructor for AudioPrint with automatic notification of audio changes
EncodedAudioStream(AudioPrint *outputStream, AudioDecoder *decoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = outputStream;
decoder_ptr = decoder;
decoder_ptr->setOutputStream(*outputStream);
@ -171,7 +171,7 @@ public:
* @param decoder
*/
EncodedAudioStream(Print &outputStream, AudioDecoder &decoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = &outputStream;
decoder_ptr = &decoder;
decoder_ptr->setOutputStream(outputStream);
@ -186,7 +186,7 @@ public:
* @param decoder
*/
EncodedAudioStream(Print *outputStream, AudioDecoder *decoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = outputStream;
decoder_ptr = decoder;
decoder_ptr->setOutputStream(*outputStream);
@ -201,7 +201,7 @@ public:
* @param encoder
*/
EncodedAudioStream(Print &outputStream, AudioEncoder &encoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = &outputStream;
encoder_ptr = &encoder;
encoder_ptr->setOutputStream(outputStream);
@ -216,7 +216,7 @@ public:
* @param encoder
*/
EncodedAudioStream(Print *outputStream, AudioEncoder *encoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = outputStream;
encoder_ptr = encoder;
encoder_ptr->setOutputStream(*outputStream);
@ -231,7 +231,7 @@ public:
*
*/
EncodedAudioStream() {
LOGD(LOG_METHOD);
TRACED();
active = false;
}
@ -247,7 +247,7 @@ public:
/// Define object which need to be notified if the basinfo is changing
void setNotifyAudioChange(AudioBaseInfoDependent &bi) override {
LOGI(LOG_METHOD);
TRACEI();
decoder_ptr->setNotifyAudioChange(bi);
}
@ -260,7 +260,7 @@ public:
}
virtual void setAudioInfo(AudioBaseInfo info) override {
LOGD(LOG_METHOD);
TRACED();
AudioPrint::setAudioInfo(info);
decoder_ptr->setAudioInfo(info);
encoder_ptr->setAudioInfo(info);
@ -268,7 +268,7 @@ public:
/// Starts the processing - sets the status to active
void begin(Print *outputStream, AudioEncoder *encoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = outputStream;
encoder_ptr = encoder;
encoder_ptr->setOutputStream(*outputStream);
@ -278,7 +278,7 @@ public:
/// Starts the processing - sets the status to active
void begin(Print *outputStream, AudioDecoder *decoder) {
LOGD(LOG_METHOD);
TRACED();
ptr_out = outputStream;
decoder_ptr = decoder;
decoder_ptr->setOutputStream(*outputStream);
@ -288,7 +288,7 @@ public:
/// Starts the processing - sets the status to active
void begin() {
LOGD(LOG_METHOD);
TRACED();
const CodecNOP *nop = CodecNOP::instance();
if (decoder_ptr != nop || encoder_ptr != nop) {
decoder_ptr->begin();
@ -301,7 +301,7 @@ public:
/// Starts the processing - sets the status to active
void begin(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
const CodecNOP *nop = CodecNOP::instance();
if (decoder_ptr != nop || encoder_ptr != nop) {
// some decoders need this - e.g. opus
@ -316,7 +316,7 @@ public:
}
/// Ends the processing
void end() {
LOGI(LOG_METHOD);
TRACEI();
decoder_ptr->end();
encoder_ptr->end();
active = false;

View File

@ -18,7 +18,7 @@ class Decoder8Bit : public AudioDecoder {
*/
Decoder8Bit(){
LOGD(LOG_METHOD);
TRACED();
}
/**
@ -27,7 +27,7 @@ class Decoder8Bit : public AudioDecoder {
* @param out_stream Output Stream to which we write the decoded result
*/
Decoder8Bit(Print &out_stream, bool active=true){
LOGD(LOG_METHOD);
TRACED();
p_print = &out_stream;
this->active = active;
}
@ -40,7 +40,7 @@ class Decoder8Bit : public AudioDecoder {
*/
Decoder8Bit(Print &out_stream, AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
p_print = &out_stream;
}
@ -58,7 +58,7 @@ class Decoder8Bit : public AudioDecoder {
}
void begin(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
cfg = info;
if (bid!=nullptr){
bid->setAudioInfo(cfg);
@ -67,12 +67,12 @@ class Decoder8Bit : public AudioDecoder {
}
void begin() override {
LOGD(LOG_METHOD);
TRACED();
active = true;
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
active = false;
}

View File

@ -19,12 +19,12 @@ AudioBaseInfoDependent *audioChangeFDK = nullptr;
class AACDecoderFDK : public AudioDecoder {
public:
AACDecoderFDK(){
LOGD(LOG_METHOD);
TRACED();
dec = new aac_fdk::AACDecoderFDK();
}
AACDecoderFDK(Print &out_stream, int output_buffer_size=2048){
LOGD(LOG_METHOD);
TRACED();
dec = new aac_fdk::AACDecoderFDK(out_stream, output_buffer_size);
}
@ -79,7 +79,7 @@ class AACDecoderFDK : public AudioDecoder {
// release the resources
void end(){
LOGD(LOG_METHOD);
TRACED();
dec->end();
}
@ -232,7 +232,7 @@ public:
/// Defines the Audio Info
virtual void setAudioInfo(AudioBaseInfo from) {
LOGD(LOG_METHOD);
TRACED();
aac_fdk::AudioInfo info;
info.channels = from.channels;
info.sample_rate = from.sample_rate;
@ -247,7 +247,7 @@ public:
* @return int
*/
virtual void begin(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
enc->begin(info.channels,info.sample_rate, info.bits_per_sample);
}
@ -260,7 +260,7 @@ public:
* @return int 0 => ok; error with negative number
*/
virtual void begin(int input_channels=2, int input_sample_rate=44100, int input_bits_per_sample=16) {
LOGD(LOG_METHOD);
TRACED();
enc->begin(input_channels,input_sample_rate, input_bits_per_sample);
}
@ -277,7 +277,7 @@ public:
// release resources
void end(){
LOGD(LOG_METHOD);
TRACED();
enc->end();
}

View File

@ -19,7 +19,7 @@ class AACDecoderHelix : public AudioDecoder {
public:
AACDecoderHelix() {
LOGD(LOG_METHOD);
TRACED();
aac = new libhelix::AACDecoderHelix();
if (aac==nullptr){
LOGE("Not enough memory for libhelix");
@ -31,7 +31,7 @@ class AACDecoderHelix : public AudioDecoder {
* @param out_stream
*/
AACDecoderHelix(Print &out_stream){
LOGD(LOG_METHOD);
TRACED();
aac = new libhelix::AACDecoderHelix(out_stream);
if (aac==nullptr){
LOGE("Not enough memory for libhelix");
@ -46,7 +46,7 @@ class AACDecoderHelix : public AudioDecoder {
* @param bi
*/
AACDecoderHelix(Print &out_stream, AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
aac = new libhelix::AACDecoderHelix(out_stream);
if (aac==nullptr){
LOGE("Not enough memory for libhelix");
@ -59,19 +59,19 @@ class AACDecoderHelix : public AudioDecoder {
*
*/
~AACDecoderHelix(){
LOGD(LOG_METHOD);
TRACED();
if (aac!=nullptr) delete aac;
}
/// Defines the output Stream
virtual void setOutputStream(Print &out_stream){
LOGD(LOG_METHOD);
TRACED();
if (aac!=nullptr) aac->setOutput(out_stream);
}
/// Starts the processing
void begin(){
LOGD(LOG_METHOD);
TRACED();
if (aac!=nullptr) {
aac->setDelay(CODEC_DELAY_MS);
aac->begin();
@ -80,7 +80,7 @@ class AACDecoderHelix : public AudioDecoder {
/// Releases the reserved memory
virtual void end(){
LOGD(LOG_METHOD);
TRACED();
if (aac!=nullptr) aac->end();
}
@ -113,7 +113,7 @@ class AACDecoderHelix : public AudioDecoder {
/// Defines the callback object to which the Audio information change is provided
virtual void setNotifyAudioChange(AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
audioChangeAACHelix = &bi;
if (aac!=nullptr) aac->setInfoCallback(infoCallback);
}
@ -121,7 +121,7 @@ class AACDecoderHelix : public AudioDecoder {
/// notifies the subscriber about a change
static void infoCallback(_AACFrameInfo &i){
if (audioChangeAACHelix!=nullptr){
LOGD(LOG_METHOD);
TRACED();
AudioBaseInfo baseInfo;
baseInfo.channels = i.nChans;
baseInfo.sample_rate = i.sampRateOut;

View File

@ -32,7 +32,7 @@ class APTXDecoder : public AudioDecoder {
virtual AudioBaseInfo audioInfo() { return info; }
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
ctx = aptx_init(is_hd);
is_first_write = true;
if (notify != nullptr) {
@ -41,7 +41,7 @@ class APTXDecoder : public AudioDecoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
bool dropped = aptx_decode_sync_finish(ctx);
aptx_finish(ctx);
ctx = nullptr;
@ -208,7 +208,7 @@ class APTXEncoder : public AudioEncoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
input_buffer.resize(4 * 2);
output_buffer.resize(100 * (is_hd ? 6 : 4));
@ -219,7 +219,7 @@ class APTXEncoder : public AudioEncoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
if (ctx != nullptr) {
size_t output_written = 0;
aptx_encode_finish(ctx, output_buffer.data(), output_buffer.size(),

View File

@ -80,7 +80,7 @@ public:
}
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
int mode = getCodec2Mode(bits_per_second);
if (mode==-1){
@ -114,7 +114,7 @@ public:
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
codec2_destroy(p_codec2);
is_active = false;
}
@ -196,7 +196,7 @@ public:
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
int mode = getCodec2Mode(bits_per_second);
if (mode==-1){
@ -226,7 +226,7 @@ public:
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
codec2_destroy(p_codec2);
is_active = false;
}

View File

@ -12,9 +12,9 @@ namespace audio_tools {
*/
class CopyDecoder : public AudioDecoder {
public:
CopyDecoder() { LOGD(LOG_METHOD); }
CopyDecoder() { TRACED(); }
CopyDecoder(Print &out_stream) { LOGD(LOG_METHOD); pt_print=&out_stream; }
CopyDecoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
CopyDecoder(Print &out_stream, AudioBaseInfoDependent &bi) {pt_print=&out_stream;}
@ -48,9 +48,9 @@ protected:
*/
class CopyEncoder : public AudioEncoder {
public:
CopyEncoder() { LOGD(LOG_METHOD); }
CopyEncoder() { TRACED(); }
CopyEncoder(Print &out_stream) { LOGD(LOG_METHOD); pt_print=&out_stream; }
CopyEncoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
CopyEncoder(Print &out_stream, AudioBaseInfoDependent &bi) {pt_print=&out_stream;}

View File

@ -55,7 +55,7 @@ class FLACDecoder : public StreamingDecoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
is_active = true;
if (decoder == nullptr) {
@ -84,7 +84,7 @@ class FLACDecoder : public StreamingDecoder {
}
void end() {
LOGI(LOG_METHOD);
TRACEI();
flush();
FLAC__stream_decoder_delete(decoder);
is_active = false;
@ -306,7 +306,7 @@ class FLACEncoder : public AudioEncoder {
/// starts the processing using the actual AudioInfo
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
is_open = false;
if (p_encoder==nullptr){
p_encoder = FLAC__stream_encoder_new();
@ -347,7 +347,7 @@ class FLACEncoder : public AudioEncoder {
/// stops the processing
void end() override {
LOGD(LOG_METHOD);
TRACED();
FLAC__stream_encoder_delete(p_encoder);
p_encoder = nullptr;
is_open = false;

View File

@ -43,7 +43,7 @@ class G722Decoder : public AudioDecoder {
}
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
input_buffer.resize(10);
result_buffer.resize(40);
@ -60,7 +60,7 @@ class G722Decoder : public AudioDecoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
g722_decoder_destroy(g722_dctx);
is_active = false;
}
@ -141,7 +141,7 @@ class G722Encoder : public AudioEncoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
if (cfg.channels != 1) {
LOGW("1 channel expected, was: %d", cfg.channels);
}
@ -158,7 +158,7 @@ class G722Encoder : public AudioEncoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
g722_encoder_destroy(g722_ectx);
is_active = false;
}

View File

@ -65,7 +65,7 @@ class G7xxDecoder : public AudioDecoder {
}
void begin() override {
LOGI(LOG_METHOD);
TRACEI();
in_buffer = 0;
in_bits = 0;
out_size = sizeof(int16_t);
@ -75,7 +75,7 @@ class G7xxDecoder : public AudioDecoder {
}
void end() override {
LOGI(LOG_METHOD);
TRACEI();
is_active = false;
}
@ -161,7 +161,7 @@ class G7xxEncoder : public AudioEncoder {
}
void begin() override {
LOGI(LOG_METHOD);
TRACEI();
g72x_init_state(&state);
out_buffer = 0;
out_bits = 0;
@ -170,7 +170,7 @@ class G7xxEncoder : public AudioEncoder {
}
void end() override {
LOGI(LOG_METHOD);
TRACEI();
is_active = false;
}

View File

@ -37,7 +37,7 @@ class GSMDecoder : public AudioDecoder {
}
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
// 160 13-bit samples
result_buffer.resize(160 * sizeof(int16_t));
// gsm_frame of 33 bytes
@ -51,7 +51,7 @@ class GSMDecoder : public AudioDecoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
gsm_destroy(v_gsm);
is_active = false;
}
@ -133,7 +133,7 @@ class GSMEncoder : public AudioEncoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
if (cfg.sample_rate != 8000) {
LOGW("Sample rate is supposed to be 8000 - it was %d", cfg.sample_rate);
@ -151,7 +151,7 @@ class GSMEncoder : public AudioEncoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
gsm_destroy(v_gsm);
is_active = false;
}

View File

@ -17,15 +17,15 @@ namespace audio_tools {
class DecoderHelix : public AudioDecoder {
public:
DecoderHelix() { LOGD(LOG_METHOD); }
DecoderHelix() { TRACED(); }
DecoderHelix(Print &out_stream) {
LOGD(LOG_METHOD);
TRACED();
p_out_stream = &out_stream;
}
DecoderHelix(Print &out_stream, AudioBaseInfoDependent &bi) {
LOGD(LOG_METHOD);
TRACED();
p_out_stream = &out_stream;
p_bi = &bi;
}
@ -37,14 +37,14 @@ public:
/// Starts the processing
void begin() {
LOGD(LOG_METHOD);
TRACED();
// reset actual decoder so that we start a new determination
resetDecoder();
}
/// Releases the reserved memory
void end() {
LOGD(LOG_METHOD);
TRACED();
if (p_decoder!=nullptr){
p_decoder->end();
}

View File

@ -38,7 +38,7 @@ class ILBCDecoder : public AudioDecoder {
virtual AudioBaseInfo audioInfo() { return info; }
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
if (p_print==nullptr){
LOGE("Output not defined");
return;
@ -59,7 +59,7 @@ class ILBCDecoder : public AudioDecoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
delete p_ilbc;
p_ilbc = nullptr;
}
@ -133,7 +133,7 @@ class ILBCEncoder : public AudioEncoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
if (p_print==nullptr){
LOGE("Output not defined");
return;
@ -157,7 +157,7 @@ class ILBCEncoder : public AudioEncoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
if (p_ilbc != nullptr) {
delete p_ilbc;
p_ilbc = nullptr;

View File

@ -51,7 +51,7 @@ class LC3Decoder : public AudioDecoder {
}
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
num_frames = lc3_frame_samples(dt_us, info.sample_rate);
dec_size = lc3_decoder_size(dt_us, info.sample_rate);
@ -83,12 +83,12 @@ class LC3Decoder : public AudioDecoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
active = false;
}
virtual void setNotifyAudioChange(AudioBaseInfoDependent &bi) {
LOGI(LOG_METHOD);
TRACEI();
p_notify = &bi;
}
@ -202,7 +202,7 @@ class LC3Encoder : public AudioEncoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
unsigned enc_size = lc3_encoder_size(dt_us, info.sample_rate);
num_frames = lc3_frame_samples(dt_us, info.sample_rate);
@ -231,7 +231,7 @@ class LC3Encoder : public AudioEncoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
active = false;
}

View File

@ -20,7 +20,7 @@ class MP3DecoderHelix : public AudioDecoder {
public:
MP3DecoderHelix() {
LOGD(LOG_METHOD);
TRACED();
mp3 = new libhelix::MP3DecoderHelix();
filter.setDecoder(mp3);
if (mp3==nullptr){
@ -33,7 +33,7 @@ class MP3DecoderHelix : public AudioDecoder {
* @param out_stream
*/
MP3DecoderHelix(Print &out_stream){
LOGD(LOG_METHOD);
TRACED();
mp3 = new libhelix::MP3DecoderHelix();
filter.setDecoder(mp3);
if (mp3==nullptr){
@ -50,7 +50,7 @@ class MP3DecoderHelix : public AudioDecoder {
* @param bi
*/
MP3DecoderHelix(Print &out_stream, AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
mp3 = new libhelix::MP3DecoderHelix();
filter.setDecoder(mp3);
if (mp3==nullptr){
@ -75,7 +75,7 @@ class MP3DecoderHelix : public AudioDecoder {
/// Starts the processing
void begin(){
LOGD(LOG_METHOD);
TRACED();
if (mp3!=nullptr) {
mp3->setDelay(CODEC_DELAY_MS);
mp3->begin();
@ -85,7 +85,7 @@ class MP3DecoderHelix : public AudioDecoder {
/// Releases the reserved memory
void end(){
LOGD(LOG_METHOD);
TRACED();
if (mp3!=nullptr) mp3->end();
}
@ -120,7 +120,7 @@ class MP3DecoderHelix : public AudioDecoder {
/// Defines the callback object to which the Audio information change is provided
void setNotifyAudioChange(AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
audioChangeMP3Helix = &bi;
if (mp3!=nullptr) mp3->setInfoCallback(infoCallback);
}
@ -128,7 +128,7 @@ class MP3DecoderHelix : public AudioDecoder {
/// notifies the subscriber about a change
static void infoCallback(MP3FrameInfo &i){
if (audioChangeMP3Helix!=nullptr){
LOGD(LOG_METHOD);
TRACED();
AudioBaseInfo baseInfo;
baseInfo.channels = i.nChans;
baseInfo.sample_rate = i.samprate;

View File

@ -34,22 +34,22 @@ class MP3EncoderLAME : public AudioEncoder {
public:
MP3EncoderLAME(){
LOGD(LOG_METHOD);
TRACED();
}
MP3EncoderLAME(Print &out_stream){
LOGD(LOG_METHOD);
TRACED();
p_print = &out_stream;
}
~MP3EncoderLAME(){
LOGD(LOG_METHOD);
TRACED();
end();
}
/// Defines the output stream
void setOutputStream(Print &out_stream){
LOGD(LOG_METHOD);
TRACED();
p_print = &out_stream;
if (enc!=nullptr){
enc->setOutput(out_stream);
@ -58,7 +58,7 @@ public:
/// Defines the Audio Info
void setAudioInfo(AudioBaseInfo from) {
LOGD(LOG_METHOD);
TRACED();
info.channels = from.channels;
info.sample_rate = from.sample_rate;
info.bits_per_sample = from.bits_per_sample;
@ -66,7 +66,7 @@ public:
/// Defines the Audio Info
void setAudioInfo(AudioInfoLAME from) {
LOGD(LOG_METHOD);
TRACED();
info = from;
}
@ -83,7 +83,7 @@ public:
* @return int
*/
void begin(AudioInfoLAME info) {
LOGD(LOG_METHOD);
TRACED();
createEnc();
setAudioInfo(info);
enc->begin();
@ -97,7 +97,7 @@ public:
// * @param input_bits_per_sample
// */
// void begin(int input_channels, int input_sample_rate, int input_bits_per_sample) {
// LOGD(LOG_METHOD);
// TRACED();
// createEnc();
// enc->begin(input_channels, input_sample_rate, input_bits_per_sample);
// }
@ -121,7 +121,7 @@ public:
// release resources
void end(){
LOGD(LOG_METHOD);
TRACED();
if (enc!=nullptr){
enc->end();
delete enc;

View File

@ -22,62 +22,62 @@ class MP3DecoderMAD : public AudioDecoder {
public:
MP3DecoderMAD(){
LOGD(LOG_METHOD);
TRACED();
mad = new libmad::MP3DecoderMAD();
}
MP3DecoderMAD(libmad::MP3DataCallback dataCallback, libmad::MP3InfoCallback infoCB=nullptr){
LOGD(LOG_METHOD);
TRACED();
mad = new libmad::MP3DecoderMAD(dataCallback, infoCB);
}
MP3DecoderMAD(Print &mad_output_streamput, libmad::MP3InfoCallback infoCB = nullptr){
LOGD(LOG_METHOD);
TRACED();
mad = new libmad::MP3DecoderMAD(mad_output_streamput, infoCB);
}
~MP3DecoderMAD(){
LOGD(LOG_METHOD);
TRACED();
delete mad;
}
void setOutputStream(Print &out){
LOGD(LOG_METHOD);
TRACED();
mad->setOutput(out);
}
/// Defines the callback which receives the decoded data
void setAudioDataCallback(libmad::MP3DataCallback cb){
LOGD(LOG_METHOD);
TRACED();
mad->setDataCallback(cb);
}
/// Defines the callback which receives the Info changes
void setInfoCallback(libmad::MP3InfoCallback cb){
LOGD(LOG_METHOD);
TRACED();
mad->setInfoCallback(cb);
}
/// Starts the processing
void begin(){
LOGD(LOG_METHOD);
TRACED();
mad->begin();
}
/// Releases the reserved memory
void end(){
LOGD(LOG_METHOD);
TRACED();
mad->end();
}
/// Provides the last valid audio information
libmad::MadAudioInfo audioInfoEx(){
LOGD(LOG_METHOD);
TRACED();
return mad->audioInfo();
}
AudioBaseInfo audioInfo(){
LOGD(LOG_METHOD);
TRACED();
libmad::MadAudioInfo info = audioInfoEx();
AudioBaseInfo base;
base.channels = info.channels;
@ -88,13 +88,13 @@ class MP3DecoderMAD : public AudioDecoder {
/// Makes the mp3 data available for decoding: however we recommend to provide the data via a callback or input stream
size_t write(const void *data, size_t len){
LOGD(LOG_METHOD);
TRACED();
return mad->write(data,len);
}
/// Makes the mp3 data available for decoding: however we recommend to provide the data via a callback or input stream
size_t write(void *data, size_t len){
LOGD(LOG_METHOD);
TRACED();
return mad->write(data,len);
}
@ -109,7 +109,7 @@ class MP3DecoderMAD : public AudioDecoder {
static void audioChangeCallback(libmad::MadAudioInfo &info){
if (audioChangeMAD!=nullptr){
LOGD(LOG_METHOD);
TRACED();
AudioBaseInfo base;
base.channels = info.channels;
base.sample_rate = info.sample_rate;
@ -120,7 +120,7 @@ class MP3DecoderMAD : public AudioDecoder {
}
virtual void setNotifyAudioChange(AudioBaseInfoDependent &bi) {
LOGD(LOG_METHOD);
TRACED();
audioChangeMAD = &bi;
// register audio change handler
mad->setInfoCallback(audioChangeCallback);

View File

@ -42,7 +42,7 @@ class MP3DecoderMini : public AudioDecoder {
/// Starts the processing
void begin() {
LOGD(LOG_METHOD);
TRACED();
//esp_task_wdt_delete(nullptr);
::mp3dec_init(&mp3d);
buffer.resize(buffer_size);
@ -53,7 +53,7 @@ class MP3DecoderMini : public AudioDecoder {
/// Releases the reserved memory
void end() {
LOGD(LOG_METHOD);
TRACED();
flush();
active = false;
}

View File

@ -12,9 +12,9 @@ namespace audio_tools {
*/
class DecoderNOP : public AudioDecoder {
public:
DecoderNOP() { LOGD(LOG_METHOD); }
DecoderNOP() { TRACED(); }
DecoderNOP(Print &out_stream) { LOGD(LOG_METHOD); }
DecoderNOP(Print &out_stream) { TRACED(); }
DecoderNOP(Print &out_stream, AudioBaseInfoDependent &bi) {}

View File

@ -112,7 +112,7 @@ class OpusAudioDecoder : public AudioDecoder {
/**
* @brief Construct a new OpusDecoder object
*/
OpusAudioDecoder() { LOGD(LOG_METHOD); }
OpusAudioDecoder() { TRACED(); }
/**
* @brief Construct a new OpusDecoder object
@ -120,7 +120,7 @@ class OpusAudioDecoder : public AudioDecoder {
* @param out_stream Output Stream to which we write the decoded result
*/
OpusAudioDecoder(Print &out_stream) {
LOGD(LOG_METHOD);
TRACED();
setOutputStream(out_stream);
}
@ -138,7 +138,7 @@ class OpusAudioDecoder : public AudioDecoder {
OpusSettings &defaultConfig() { return cfg; }
void begin(OpusSettings info) {
LOGD(LOG_METHOD);
TRACED();
cfg = info;
if (bid != nullptr) {
bid->setAudioInfo(cfg);
@ -147,7 +147,7 @@ class OpusAudioDecoder : public AudioDecoder {
}
void begin() override {
LOGD(LOG_METHOD);
TRACED();
outbuf.resize(cfg.max_buffer_size);
assert(outbuf.data() != nullptr);
@ -162,7 +162,7 @@ class OpusAudioDecoder : public AudioDecoder {
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
if (dec) {
opus_decoder_destroy(dec);
dec = nullptr;

View File

@ -46,13 +46,13 @@ class OpusOggDecoder : public OggContainerDecoder {
}
void begin() override {
LOGD(LOG_METHOD);
TRACED();
OggContainerDecoder::begin();
dec.begin();
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
OggContainerDecoder::begin();
dec.end();
}
@ -99,13 +99,13 @@ class OpusOggEncoder : public OggContainerEncoder {
}
void begin() override {
LOGD(LOG_METHOD);
TRACED();
OggContainerEncoder::begin();
enc.begin();
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
OggContainerEncoder::begin();
enc.end();
}
@ -145,7 +145,7 @@ class OpusOggEncoder : public OggContainerEncoder {
if (!writePacket(oh1, OGGZ_FLUSH_AFTER)){
result = false;
}
LOGD(LOG_METHOD);
TRACED();
return result;
}
};

View File

@ -20,7 +20,7 @@ class RAWDecoder : public AudioDecoder {
*/
RAWDecoder(){
LOGD(LOG_METHOD);
TRACED();
}
/**
@ -29,7 +29,7 @@ class RAWDecoder : public AudioDecoder {
* @param out_stream Output Stream to which we write the decoded result
*/
RAWDecoder(Print &out_stream, bool active=true){
LOGD(LOG_METHOD);
TRACED();
p_print = &out_stream;
this->active = active;
}
@ -42,7 +42,7 @@ class RAWDecoder : public AudioDecoder {
*/
RAWDecoder(Print &out_stream, AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
p_print = &out_stream;
}
@ -60,7 +60,7 @@ class RAWDecoder : public AudioDecoder {
}
void begin(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
cfg = info;
if (bid!=nullptr){
bid->setAudioInfo(cfg);
@ -69,12 +69,12 @@ class RAWDecoder : public AudioDecoder {
}
void begin() override {
LOGD(LOG_METHOD);
TRACED();
active = true;
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
active = false;
}

View File

@ -36,14 +36,14 @@ class SBCDecoder : public AudioDecoder {
virtual AudioBaseInfo audioInfo() { return info; }
virtual void begin() {
LOGI(LOG_METHOD);
TRACEI();
is_first = true;
is_active = true;
sbc_init(&sbc, 0L);
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
sbc_finish(&sbc);
is_active = false;
}
@ -202,7 +202,7 @@ class SBCEncoder : public AudioEncoder {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
is_first = true;
is_active = setup();
int codesize = sbc_get_codesize(&sbc);
@ -214,7 +214,7 @@ class SBCEncoder : public AudioEncoder {
}
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
sbc_finish(&sbc);
is_active = false;
}

View File

@ -237,7 +237,7 @@ class WAVDecoder : public AudioDecoder {
*/
WAVDecoder(){
LOGD(LOG_METHOD);
TRACED();
this->audioBaseInfoSupport = nullptr;
}
@ -247,7 +247,7 @@ class WAVDecoder : public AudioDecoder {
* @param out_stream Output Stream to which we write the decoded result
*/
WAVDecoder(Print &out_stream, bool active=true){
LOGD(LOG_METHOD);
TRACED();
this->out = &out_stream;
this->audioBaseInfoSupport = nullptr;
this->active = active;
@ -261,7 +261,7 @@ class WAVDecoder : public AudioDecoder {
*/
WAVDecoder(Print &out_stream, AudioBaseInfoDependent &bi){
LOGD(LOG_METHOD);
TRACED();
this->out = &out_stream;
this->audioBaseInfoSupport = &bi;
}
@ -277,13 +277,13 @@ class WAVDecoder : public AudioDecoder {
void begin() {
LOGD(LOG_METHOD);
TRACED();
isFirst = true;
active = true;
}
void end() {
LOGD(LOG_METHOD);
TRACED();
active = false;
}
@ -300,7 +300,7 @@ class WAVDecoder : public AudioDecoder {
}
virtual size_t write(const void *in_ptr, size_t in_size) {
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
if (active) {
if (isFirst){
@ -352,7 +352,7 @@ class WAVDecoder : public AudioDecoder {
/// Alternative API which provides the data from an input stream
int readStream(Stream &in){
LOGD(LOG_METHOD);
TRACED();
uint8_t buffer[READ_BUFFER_SIZE];
int len = in.readBytes(buffer, READ_BUFFER_SIZE);
return write(buffer, len);

View File

@ -24,7 +24,7 @@ class OggContainerDecoder : public AudioDecoder {
* @brief Construct a new OggContainerDecoder object
*/
OggContainerDecoder() { LOGD(LOG_METHOD); }
OggContainerDecoder() { TRACED(); }
OggContainerDecoder(AudioDecoder *decoder) {
p_codec = decoder;
@ -55,7 +55,7 @@ class OggContainerDecoder : public AudioDecoder {
AudioBaseInfo audioInfo() override { return cfg; }
void begin(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
cfg = info;
if (bid != nullptr) {
bid->setAudioInfo(cfg);
@ -64,7 +64,7 @@ class OggContainerDecoder : public AudioDecoder {
}
void begin() override {
LOGD(LOG_METHOD);
TRACED();
if (p_oggz == nullptr) {
p_oggz = oggz_new(OGGZ_READ | OGGZ_AUTO); // OGGZ_NONSTRICT
is_open = true;
@ -87,7 +87,7 @@ class OggContainerDecoder : public AudioDecoder {
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
flush();
if (p_codec!=nullptr) p_codec->end();
is_open = false;
@ -238,7 +238,7 @@ class OggContainerEncoder : public AudioEncoder {
/// starts the processing using the actual AudioInfo
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
is_open = true;
codec_buffer.begin();
if (p_oggz == nullptr) {
@ -262,7 +262,7 @@ class OggContainerEncoder : public AudioEncoder {
/// stops the processing
void end() override {
LOGD(LOG_METHOD);
TRACED();
writeFooter();
@ -342,7 +342,7 @@ class OggContainerEncoder : public AudioEncoder {
}
virtual bool writeHeader() {
LOGD(LOG_METHOD);
TRACED();
oh.packet = (uint8_t *)&cfg;
oh.bytes = sizeof(cfg);
oh.granulepos = 0;
@ -354,7 +354,7 @@ class OggContainerEncoder : public AudioEncoder {
}
virtual bool writeFooter() {
LOGD(LOG_METHOD);
TRACED();
op.packet = (uint8_t *)nullptr;
op.bytes = 0;
op.granulepos = granulepos;

View File

@ -40,7 +40,7 @@ class SimpleContainerEncoder : public AudioEncoder {
void setOutputStream(Print &outStream) { p_codec->setOutputStream(outStream);}
void begin(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
setAudioInfo(info);
p_codec->begin();
}

View File

@ -377,7 +377,7 @@ typedef uint32_t eps32_i2s_sample_rate_type;
#ifndef assert
#define assert(T)
#endif
#define rintf(F) static_cast<int>(F)
#define PIN_PWM_START 6
#define PIN_CS SS
@ -389,10 +389,10 @@ typedef uint32_t eps32_i2s_sample_rate_type;
// logging is using too much memory
#undef LOG_PRINTF_BUFFER_SIZE
#define LOG_PRINTF_BUFFER_SIZE 40
#define LOG_PRINTF_BUFFER_SIZE 80
#undef USE_AUDIO_LOGGING
#define USE_AUDIO_LOGGING false
#define NO_TRACED
#define NO_TRACEI
#endif

View File

@ -30,7 +30,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
/// Copy constructor
AudioEffects(AudioEffects &copy) {
LOGI(LOG_METHOD);
TRACEI();
// create a copy of the source and all effects
p_generator = copy.p_generator;
for (int j=0;j<copy.size();j++){
@ -53,7 +53,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
/// Destructor
virtual ~AudioEffects(){
LOGD(LOG_METHOD);
TRACED();
if (owns_generator && p_generator!=nullptr){
delete p_generator;
}
@ -64,7 +64,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
/// Defines the input source for the raw guitar input
void setInput(GeneratorT &in){
LOGD(LOG_METHOD);
TRACED();
p_generator = &in;
// automatically activate this object
AudioBaseInfo info;
@ -75,13 +75,13 @@ class AudioEffects : public SoundGenerator<effect_t> {
/// Adds an effect object (by reference)
void addEffect(AudioEffect &effect){
LOGD(LOG_METHOD);
TRACED();
effects.push_back(&effect);
}
/// Adds an effect using a pointer
void addEffect(AudioEffect *effect){
LOGD(LOG_METHOD);
TRACED();
effects.push_back(effect);
LOGI("addEffect -> Number of effects: %d", size());
}
@ -101,7 +101,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
/// deletes all defined effects
void clear() {
LOGD(LOG_METHOD);
TRACED();
effects.clear();
}

View File

@ -102,7 +102,7 @@ class ADSR : public AbstractParameter {
}
void keyOff(){
LOGI(LOG_METHOD);
TRACEI();
if (state!=Idle){
state = Release;
target = 0;

View File

@ -32,7 +32,7 @@ class SoundGenerator {
}
virtual bool begin() {
LOGD(LOG_METHOD);
TRACED();
active = true;
activeWarningIssued = false;
LOGI("bits_per_sample: %d", info.bits_per_sample);
@ -163,7 +163,7 @@ class SineWaveGenerator : public SoundGenerator<T>{
}
bool begin() override {
LOGI(LOG_METHOD);
TRACEI();
SoundGenerator<T>::begin();
this->m_deltaTime = 1.0 / SoundGenerator<T>::info.sample_rate;
return true;
@ -410,7 +410,7 @@ class GeneratorFromArray : public SoundGenerator<T> {
template <size_t arrayLen>
GeneratorFromArray(T(&array)[arrayLen], int repeat=0, bool setInactiveAtEnd=true) {
LOGD(LOG_METHOD);
TRACED();
this->max_repeat = repeat;
this->inactive_at_end = setInactiveAtEnd;
setArray(array, arrayLen);
@ -424,7 +424,7 @@ class GeneratorFromArray : public SoundGenerator<T> {
template <int arrayLen>
void setArray(T(&array)[arrayLen]){
LOGD(LOG_METHOD);
TRACED();
setArray(array, arrayLen);
}
@ -440,7 +440,7 @@ class GeneratorFromArray : public SoundGenerator<T> {
/// Starts the generation of samples
bool begin() override {
LOGI(LOG_METHOD);
TRACEI();
SoundGenerator<T>::begin();
sound_index = 0;
repeat_counter = 0;
@ -527,7 +527,7 @@ class GeneratorFixedValue : public SoundGenerator<T> {
/// Starts the generation of samples
bool begin() override {
LOGI(LOG_METHOD);
TRACEI();
SoundGenerator<T>::begin();
is_running = true;
value_return = value_set;

View File

@ -53,14 +53,14 @@ class DefaultSynthesizerChannel : public AbstractSynthesizerChannel {
DefaultSynthesizerChannel(DefaultSynthesizerChannel<EffectsT> &ch) = default;
DefaultSynthesizerChannel<EffectsT> *clone() override {
LOGD(LOG_METHOD);
TRACED();
auto result = new DefaultSynthesizerChannel<EffectsT>(*this);
result->begin(config);
return result;
}
virtual void begin(AudioBaseInfo config) override {
LOGI(LOG_METHOD);
TRACEI();
this->config = config;
config.logInfo();
// find ADSRGain
@ -87,7 +87,7 @@ class DefaultSynthesizerChannel : public AbstractSynthesizerChannel {
}
virtual void keyOff() override{
LOGD(LOG_METHOD);
TRACED();
if (p_adsr!=nullptr){
p_adsr->keyOff();
} else {
@ -135,7 +135,7 @@ class DefaultGuitarChannel : public DefaultSynthesizerChannel<AudioEffects<Gener
/// Creates a copy of the channel
DefaultGuitarChannel *clone() override {
LOGD(LOG_METHOD);
TRACED();
auto result = new DefaultGuitarChannel(*this);
result->begin(config);
return result;
@ -148,7 +148,7 @@ class DefaultGuitarChannel : public DefaultSynthesizerChannel<AudioEffects<Gener
/// Starts the audio generator / audio processing
virtual void begin(AudioBaseInfo config) override {
LOGI(LOG_METHOD);
TRACEI();
this->config = config;
config.logInfo();
audio_effects.generator().begin(config);
@ -212,7 +212,7 @@ class Synthesizer : public SoundGenerator<int16_t> {
}
~Synthesizer(){
LOGD(LOG_METHOD);
TRACED();
for (int j=0;j<channels.size();j++){
delete channels[j];
channels[j] = nullptr;
@ -224,7 +224,7 @@ class Synthesizer : public SoundGenerator<int16_t> {
}
bool begin(AudioBaseInfo config) {
LOGI(LOG_METHOD);
TRACEI();
this->cfg = config;
SoundGenerator<int16_t>::begin(config);
// provide config to defaut
@ -352,7 +352,7 @@ class Synthesizer : public SoundGenerator<int16_t> {
}
static void callbackKeyOn(bool active, int pin, void* ref){
LOGI(LOG_METHOD);
TRACEI();
KeyParameter* par = (KeyParameter*)ref;
if (par !=nullptr && par->p_synthesizer!=nullptr){
par->p_synthesizer->keyOn(par->note);
@ -362,7 +362,7 @@ class Synthesizer : public SoundGenerator<int16_t> {
}
static void callbackKeyOff(bool active, int pin, void* ref){
LOGI(LOG_METHOD);
TRACEI();
KeyParameter* par = (KeyParameter*)ref;
if (par !=nullptr){
if (par->p_synthesizer!=nullptr){

View File

@ -51,7 +51,7 @@ class AudioServer {
* @param contentType Mime Type of result
*/
void begin(Stream &in, const char* contentType) {
LOGD(LOG_METHOD);
TRACED();
this->in = &in;
this->content_type = contentType;
@ -68,7 +68,7 @@ class AudioServer {
* @param contentType Mime Type of result
*/
void begin(AudioServerDataCallback cb, const char* contentType) {
LOGD(LOG_METHOD);
TRACED();
this->in =nullptr;
this->callback = cb;
this->content_type = contentType;
@ -152,7 +152,7 @@ class AudioServer {
BaseConverter<int16_t> *converter_ptr = nullptr;
void connectWiFi() {
LOGD(LOG_METHOD);
TRACED();
if (WiFi.status() != WL_CONNECTED && network!=nullptr && password != nullptr){
WiFi.begin(network, password);
//WiFi.setSleep(false);
@ -167,7 +167,7 @@ class AudioServer {
}
virtual void sendReplyHeader(){
LOGD(LOG_METHOD);
TRACED();
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client_obj.println("HTTP/1.1 200 OK");
@ -180,7 +180,7 @@ class AudioServer {
}
virtual void sendReplyContent() {
LOGD(LOG_METHOD);
TRACED();
if (callback!=nullptr){
// provide data via Callback
LOGI("sendReply - calling callback");
@ -269,7 +269,7 @@ class AudioEncoderServer : public AudioServer {
* @param channels
*/
void begin(Stream &in, int sample_rate, int channels, int bits_per_sample=16, BaseConverter<int16_t> *converter=nullptr) {
LOGD(LOG_METHOD);
TRACED();
this->in = &in;
audio_info.sample_rate = sample_rate;
audio_info.channels = channels;
@ -287,7 +287,7 @@ class AudioEncoderServer : public AudioServer {
* @param converter
*/
void begin(Stream &in, AudioBaseInfo info, BaseConverter<int16_t> *converter=nullptr) {
LOGD(LOG_METHOD);
TRACED();
this->in = &in;
this->audio_info = info;
encoder->setAudioInfo(audio_info);
@ -304,7 +304,7 @@ class AudioEncoderServer : public AudioServer {
* @param channels
*/
void begin(AudioServerDataCallback cb, int sample_rate, int channels, int bits_per_sample=16) {
LOGD(LOG_METHOD);
TRACED();
audio_info.sample_rate = sample_rate;
audio_info.channels = channels;
audio_info.bits_per_sample = bits_per_sample;
@ -328,7 +328,7 @@ class AudioEncoderServer : public AudioServer {
virtual void sendReplyContent() {
LOGD(LOG_METHOD);
TRACED();
if (callback!=nullptr){
encoded_stream.begin(out_ptr(), encoder);
// provide data via Callback to encoded_stream

View File

@ -22,32 +22,32 @@ class ICYStreamDefault : public AbstractURLStream {
public:
ICYStreamDefault(int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGI(LOG_METHOD);
TRACEI();
url = new URLStreamDefault(readBufferSize);
checkUrl();
}
ICYStreamDefault(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGI(LOG_METHOD);
TRACEI();
url = new URLStreamDefault(clientPar, readBufferSize);
checkUrl();
}
/// Default constructor
ICYStreamDefault(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
LOGI(LOG_METHOD);
TRACEI();
url = new URLStreamDefault(network, password, readBufferSize);
checkUrl();
}
~ICYStreamDefault(){
LOGI(LOG_METHOD);
TRACEI();
if (url!=nullptr) delete url;
}
/// Defines the meta data callback function
virtual bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len)) override {
LOGD(LOG_METHOD);
TRACED();
callback = fn;
icy.setCallback(fn);
return true;
@ -55,7 +55,7 @@ class ICYStreamDefault : public AbstractURLStream {
// Icy http get request to the indicated url
virtual bool begin(const char* urlStr, const char* acceptMime=nullptr, MethodID action=GET, const char* reqMime="", const char*reqData="") override {
LOGD(LOG_METHOD);
TRACED();
// accept metadata
url->httpRequest().header().put("Icy-MetaData","1");
bool result = url->begin(urlStr, acceptMime, action, reqMime, reqData);
@ -78,7 +78,7 @@ class ICYStreamDefault : public AbstractURLStream {
/// Ends the processing
virtual void end() override {
LOGD(LOG_METHOD);
TRACED();
url->end();
icy.end();
}
@ -184,16 +184,16 @@ class ICYStream : public ICYStreamDefault {
public:
ICYStream(int readBufferSize=DEFAULT_BUFFER_SIZE)
:ICYStreamDefault(readBufferSize){
LOGI(LOG_METHOD);
TRACEI();
}
ICYStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE)
:ICYStreamDefault(clientPar, readBufferSize){
LOGI(LOG_METHOD);
TRACEI();
}
ICYStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE)
:ICYStreamDefault(network,password,readBufferSize) {
LOGI(LOG_METHOD);
TRACEI();
}
};

View File

@ -21,35 +21,35 @@ class ICYStream : public AbstractURLStream {
public:
ICYStream(int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGI(LOG_METHOD);
TRACEI();
p_urlStream = new ICYStreamDefault(readBufferSize);
taskStream.setInput(*p_urlStream);
}
ICYStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGI(LOG_METHOD);
TRACEI();
p_urlStream = new ICYStreamDefault(clientPar, readBufferSize);
taskStream.setInput(*p_urlStream);
}
ICYStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
LOGI(LOG_METHOD);
TRACEI();
p_urlStream = new ICYStreamDefault(network, password, readBufferSize);
taskStream.setInput(*p_urlStream);
}
~ICYStream(){
LOGI(LOG_METHOD);
TRACEI();
if (p_urlStream!=nullptr) delete p_urlStream;
}
virtual bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len)) override {
LOGD(LOG_METHOD);
TRACED();
return p_urlStream->setMetadataCallback(fn);
}
virtual bool begin(const char* urlStr, const char* acceptMime=nullptr, MethodID action=GET, const char* reqMime="", const char*reqData="") override {
LOGD(LOG_METHOD);
TRACED();
// start real stream
bool result = p_urlStream->begin(urlStr, acceptMime, action, reqMime, reqData);
// start reader task
@ -58,7 +58,7 @@ class ICYStream : public AbstractURLStream {
}
virtual void end() override{
LOGD(LOG_METHOD);
TRACED();
taskStream.end();
p_urlStream->end();
}

View File

@ -39,25 +39,25 @@ class URLStreamDefault : public AbstractURLStream {
public:
URLStreamDefault(int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGI(LOG_METHOD);
TRACEI();
read_buffer = new uint8_t[readBufferSize];
}
URLStreamDefault(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGI(LOG_METHOD);
TRACEI();
read_buffer = new uint8_t[readBufferSize];
client = &clientPar;
}
URLStreamDefault(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
LOGI(LOG_METHOD);
TRACEI();
read_buffer = new uint8_t[readBufferSize];
this->network = (char*)network;
this->password = (char*)password;
}
~URLStreamDefault(){
LOGI(LOG_METHOD);
TRACEI();
if (read_buffer!=nullptr){
delete[] read_buffer;
read_buffer = nullptr;
@ -310,17 +310,17 @@ class URLStream : public URLStreamDefault {
public:
URLStream(int readBufferSize=DEFAULT_BUFFER_SIZE)
:URLStreamDefault(readBufferSize){
LOGI(LOG_METHOD);
TRACEI();
}
URLStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE)
:URLStreamDefault(clientPar, readBufferSize){
LOGI(LOG_METHOD);
TRACEI();
}
URLStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE)
:URLStreamDefault(network,password,readBufferSize) {
LOGI(LOG_METHOD);
TRACEI();
}
};

View File

@ -15,23 +15,23 @@ namespace audio_tools {
class BufferedTaskStream : public AudioStream {
public:
BufferedTaskStream() {
LOGI(LOG_METHOD);
TRACEI();
createMutex();
};
BufferedTaskStream(AudioStream &input){
LOGI(LOG_METHOD);
TRACEI();
createMutex();
setInput(input);
}
~BufferedTaskStream(){
LOGI(LOG_METHOD);
TRACEI();
stop();
}
virtual void begin(bool wait=true) {
LOGD(LOG_METHOD);
TRACED();
active=true;
ready = false;
xTaskCreatePinnedToCore(task, "BufferedTaskStream", STACK_SIZE, this, URL_STREAM_PRIORITY, &xHandle, URL_STREAM_CORE);
@ -39,14 +39,14 @@ class BufferedTaskStream : public AudioStream {
}
virtual void end() {
LOGD(LOG_METHOD);
TRACED();
if (xHandle!=NULL) vTaskDelete( xHandle );
active = false;
ready = false;
}
virtual void setInput(AudioStream &input) {
LOGD(LOG_METHOD);
TRACED();
p_stream = &input;
}
@ -116,7 +116,7 @@ class BufferedTaskStream : public AudioStream {
bool ready = false;
void createMutex() {
LOGD(LOG_METHOD);
TRACED();
if (mutex == NULL){
mutex = xSemaphoreCreateMutex();
if (mutex==NULL){
@ -126,7 +126,7 @@ class BufferedTaskStream : public AudioStream {
}
static void task(void * pvParameters){
LOGD(LOG_METHOD);
TRACED();
static uint8_t buffer[512];
BufferedTaskStream* self = (BufferedTaskStream*) pvParameters;
while(true){
@ -162,30 +162,30 @@ class BufferedTaskStream : public AudioStream {
class URLStream : public AbstractURLStream {
public:
URLStream(int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGD(LOG_METHOD);
TRACED();
p_urlStream = new URLStreamDefault(readBufferSize);
taskStream.setInput(*p_urlStream);
}
URLStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
LOGD(LOG_METHOD);
TRACED();
p_urlStream = new URLStreamDefault(clientPar, readBufferSize);
taskStream.setInput(*p_urlStream);
}
URLStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
LOGD(LOG_METHOD);
TRACED();
p_urlStream = new URLStreamDefault(network, password, readBufferSize);
taskStream.setInput(*p_urlStream);
}
~URLStream(){
LOGD(LOG_METHOD);
TRACED();
if (p_urlStream!=nullptr) delete p_urlStream;
}
bool begin(const char* urlStr, const char* acceptMime=nullptr, MethodID action=GET, const char* reqMime="", const char*reqData="") {
LOGD(LOG_METHOD);
TRACED();
// start real stream
bool result = p_urlStream->begin(urlStr, acceptMime, action,reqMime, reqData );
// start buffer task
@ -225,7 +225,7 @@ class URLStream : public AbstractURLStream {
}
void end(){
LOGD(LOG_METHOD);
TRACED();
taskStream.end();
p_urlStream->end();
}

View File

@ -39,7 +39,7 @@ class I2SBase {
/// starts the DAC
bool begin(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
this->cfg = cfg;
switch(cfg.rx_tx_mode){
case TX_MODE:
@ -65,7 +65,7 @@ class I2SBase {
/// stops the I2C and unistalls the driver
void end(){
LOGD(LOG_METHOD);
TRACED();
i2s_driver_uninstall(i2s_num);
is_started = false;
}
@ -77,12 +77,12 @@ class I2SBase {
/// writes the data to the I2S interface
size_t writeBytes(const void *src, size_t size_bytes){
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
if (cfg.channels==2){
if (i2s_write(i2s_num, src, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
}
LOGD("i2s_write %d -> %d bytes", size_bytes, result);
} else {
@ -95,13 +95,13 @@ class I2SBase {
size_t result = 0;
if (cfg.channels==2){
if (i2s_read(i2s_num, dest, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
}
} else if (cfg.channels==1){
// I2S has always 2 channels. We support to reduce it to 1
uint8_t temp[size_bytes*2];
if (i2s_read(i2s_num, temp, size_bytes*2, &result, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
}
// convert to 1 channel
switch(cfg.bits_per_sample){
@ -135,7 +135,7 @@ class I2SBase {
/// starts the DAC
bool begin(I2SConfig cfg, int txPin, int rxPin) {
LOGD(LOG_METHOD);
TRACED();
cfg.logInfo();
this->cfg = cfg;
this->i2s_num = (i2s_port_t) cfg.port_no;
@ -219,7 +219,7 @@ class I2SBase {
frame[1]=data[j];
size_t result_call = 0;
if (i2s_write(i2s_num, frame, sizeof(int8_t)*2, &result_call, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
} else {
result += result_call;
}
@ -234,7 +234,7 @@ class I2SBase {
frame[1]=data[j];
size_t result_call = 0;
if (i2s_write(i2s_num, frame, sizeof(int16_t)*2, &result_call, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
} else {
result += result_call;
}
@ -249,7 +249,7 @@ class I2SBase {
frame[1]=data[j];
size_t result_call = 0;
if (i2s_write(i2s_num, frame, sizeof(int24_t)*2, &result_call, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
} else {
result += result_call;
}
@ -264,7 +264,7 @@ class I2SBase {
frame[1]=data[j];
size_t result_call = 0;
if (i2s_write(i2s_num, frame, sizeof(int32_t)*2, &result_call, portMAX_DELAY)!=ESP_OK){
LOGE(LOG_METHOD);
TRACEE();
} else {
result += result_call;
}

View File

@ -160,12 +160,12 @@ class I2SBase {
}
void setupIRQ() {
LOGD(LOG_METHOD);
TRACED();
NVIC_EnableIRQ(I2S_IRQn);
}
void setupRxTx(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
if (cfg.rx_tx_mode == TX_MODE) {
// Enable transmission
NRF_I2S->CONFIG.TXEN = (I2S_CONFIG_TXEN_TXEN_Enabled << I2S_CONFIG_TXEN_TXEN_Pos);
@ -176,7 +176,7 @@ class I2SBase {
}
void setupClock(I2SConfig cfg){
LOGD(LOG_METHOD);
TRACED();
// Enable MCK generator if in master mode
if (cfg.is_master){
NRF_I2S->CONFIG.MCKEN = (I2S_CONFIG_MCKEN_MCKEN_Enabled << I2S_CONFIG_MCKEN_MCKEN_Pos);
@ -201,7 +201,7 @@ class I2SBase {
}
void setupBitWidth(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
uint16_t swidth = I2S_CONFIG_SWIDTH_SWIDTH_16Bit;
switch(cfg.bits_per_sample){
case 8:
@ -219,7 +219,7 @@ class I2SBase {
}
void setupMode(I2SConfig cfg){
LOGD(LOG_METHOD);
TRACED();
// setup mode
switch(cfg.i2s_format){
case I2S_STD_FORMAT:
@ -241,7 +241,7 @@ class I2SBase {
// setup pins
void setupPins(I2SConfig cfg){
LOGD(LOG_METHOD);
TRACED();
// MCK routed to pin 0
// if (cfg.is_master){
// NRF_I2S->PSEL.MCK = (0 << I2S_PSEL_MCK_PIN_Pos) | (I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos);
@ -261,7 +261,7 @@ class I2SBase {
// setup initial data pointers
void setupData(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
NRF_I2S->TXD.PTR = (uint32_t) i2s_buffer.readEnd().address(); // last buffer was processed
NRF_I2S->RXD.PTR = (uint32_t) i2s_buffer.writeEnd().address(); // last buffer was processed
NRF_I2S->RXTXD.MAXCNT = i2s_buffer_size;

View File

@ -34,13 +34,13 @@ class I2SBasePIO {
/// starts the DAC with the default config in TX Mode
bool begin(RxTxMode mode = TX_MODE) {
LOGD(LOG_METHOD);
TRACED();
return begin(defaultConfig(mode));
}
/// starts the DAC
bool begin(I2SConfig cfg) {
LOGI(LOG_METHOD);
TRACEI();
this->cfg = cfg;
cfg.logInfo();
if (cfg.rx_tx_mode != TX_MODE ){
@ -89,7 +89,7 @@ class I2SBasePIO {
/// writes the data to the I2S interface
size_t writeBytes(const void *src, size_t size_bytes) {
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
int16_t *p16 = (int16_t *)src;
@ -109,7 +109,7 @@ class I2SBasePIO {
}
size_t readBytes(void *dest, size_t size_bytes) {
LOGE(LOG_METHOD);
TRACEE();
size_t result = 0;
return result;
}

View File

@ -26,7 +26,7 @@ class I2S : public I2SBase {
public:
/// Default Constructor
I2S() {
LOGD(LOG_METHOD);
TRACED();
}
/// Destructor
@ -35,7 +35,7 @@ class I2S : public I2SBase {
}
bool begin(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
// define bits per sampe from data type
cfg.bits_per_sample = sizeof(T) * 8;
return I2SBase::begin(cfg);
@ -43,7 +43,7 @@ class I2S : public I2SBase {
/// writes the data to the I2S interface
size_t write(T (*src)[2], size_t frameCount){
LOGD(LOG_METHOD);
TRACED();
return writeBytes(src, frameCount * sizeof(T) * 2); // 2 bytes * 2 channels
}
@ -70,7 +70,7 @@ class I2SStream : public AudioStream {
public:
I2SStream(int mute_pin=PIN_I2S_MUTE) {
LOGD(LOG_METHOD);
TRACED();
this->mute_pin = mute_pin;
if (mute_pin>0) {
pinMode(mute_pin, OUTPUT);
@ -89,7 +89,7 @@ class I2SStream : public AudioStream {
/// Starts the I2S interface
void begin(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
i2s.begin(cfg);
// unmute
mute(false);
@ -97,14 +97,14 @@ class I2SStream : public AudioStream {
/// Stops the I2S interface
void end() {
LOGD(LOG_METHOD);
TRACED();
mute(true);
i2s.end();
}
/// updates the sample rate dynamically
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
AudioStream::setAudioInfo(info);
I2SConfig cfg = i2s.config();
if (cfg.sample_rate != info.sample_rate
@ -122,7 +122,7 @@ class I2SStream : public AudioStream {
/// Writes the audio data to I2S
virtual size_t write(const uint8_t *buffer, size_t size) {
LOGD(LOG_METHOD);
TRACED();
return i2s.writeBytes(buffer, size);
}

View File

@ -292,14 +292,14 @@ class A2DPStream : public AudioStream {
SemaphoreHandle_t xSemaphore = NULL;
A2DPStream() {
LOGD(LOG_METHOD);
TRACED();
xSemaphore = xSemaphoreCreateMutex();
A2DPStream_self = this;
}
static void a2dpStateCallback(esp_a2d_connection_state_t state, void *caller){
LOGD(LOG_METHOD);
TRACED();
A2DPStream *self = (A2DPStream*)caller;
if (state==ESP_A2D_CONNECTION_STATE_CONNECTED && self->config.startLogic==StartOnConnect){
is_a2dp_active = true;

View File

@ -51,7 +51,7 @@ class FaustStream : public AudioStreamX {
/// Checks the parameters and starts the processing
bool begin(AudioBaseInfo cfg){
LOGD(LOG_METHOD);
TRACED();
bool result = true;
this->cfg = cfg;
this->bytes_per_sample = cfg.bits_per_sample/8;
@ -98,7 +98,7 @@ class FaustStream : public AudioStreamX {
/// Ends the processing
void end() {
LOGD(LOG_METHOD);
TRACED();
is_read = false;
is_write = false;
p_dsp->instanceClear();
@ -113,7 +113,7 @@ class FaustStream : public AudioStreamX {
size_t readBytes(uint8_t *data, size_t len) override {
size_t result = 0;
if (is_read){
LOGD(LOG_METHOD);
TRACED();
result = len;
int samples = len / bytes_per_sample;
allocateFloatBuffer(samples, false);
@ -128,7 +128,7 @@ class FaustStream : public AudioStreamX {
size_t write(const uint8_t *write_data, size_t len) override {
size_t result = 0;
if (is_write){
LOGD(LOG_METHOD);
TRACED();
int samples = len / bytes_per_sample;
allocateFloatBuffer(samples, with_output_buffer);
int16_t *data16 = (int16_t*) write_data;

View File

@ -31,7 +31,7 @@ friend class AudioKitStream;
/// convert to config object needed by HAL
AudioKitConfig toAudioKitConfig() {
LOGD(LOG_METHOD);
TRACED();
AudioKitConfig result;
result.i2s_num = (i2s_port_t)port_no;
result.mclk_gpio = (gpio_num_t)masterclock_pin;
@ -55,7 +55,7 @@ friend class AudioKitStream;
protected:
// convert to audio_hal_iface_samples_t
audio_hal_iface_bits_t toBits() {
LOGD(LOG_METHOD);
TRACED();
const static int ia[] = {16, 24, 32};
const static audio_hal_iface_bits_t oa[] = {AUDIO_HAL_BIT_LENGTH_16BITS,
AUDIO_HAL_BIT_LENGTH_24BITS,
@ -72,7 +72,7 @@ friend class AudioKitStream;
/// Convert to audio_hal_iface_samples_t
audio_hal_iface_samples_t toSampleRate() {
LOGD(LOG_METHOD);
TRACED();
const static int ia[] = {8000, 11025, 16000, 22050,
24000, 32000, 44100, 48000};
const static audio_hal_iface_samples_t oa[] = {
@ -99,7 +99,7 @@ friend class AudioKitStream;
/// Convert to audio_hal_iface_format_t
audio_hal_iface_format_t toFormat() {
LOGD(LOG_METHOD);
TRACED();
const static int ia[] = {I2S_STD_FORMAT,
I2S_LSB_FORMAT,
I2S_MSB_FORMAT,
@ -154,11 +154,11 @@ class AudioKitStreamAdapter : public AudioStreamX {
public:
AudioKitStreamAdapter(AudioKit *kit) { this->kit = kit; }
size_t write(const uint8_t *data, size_t len) override {
// LOGD(LOG_METHOD);
// TRACED();
return kit->write(data, len);
}
size_t readBytes(uint8_t *data, size_t len) override {
// LOGD(LOG_METHOD);
// TRACED();
return kit->read(data, len);
}
@ -178,7 +178,7 @@ class AudioKitStream : public AudioStreamX {
/// Provides the default configuration
AudioKitStreamConfig defaultConfig(RxTxMode mode = RXTX_MODE) {
LOGD(LOG_METHOD);
TRACED();
AudioKitStreamConfig result;
result.rx_tx_mode = mode;
return result;
@ -186,7 +186,7 @@ class AudioKitStream : public AudioStreamX {
/// Starts the processing
void begin(AudioKitStreamConfig config) {
LOGD(LOG_METHOD);
TRACED();
AudioStream::setAudioInfo(config);
cfg = config;
cfg.logInfo();
@ -211,7 +211,7 @@ class AudioKitStream : public AudioStreamX {
/// Stops the processing
void end() {
LOGD(LOG_METHOD);
TRACED();
kit.end();
is_started = false;
}
@ -252,7 +252,7 @@ class AudioKitStream : public AudioStreamX {
/// Update the audio info with new values: e.g. new sample_rate,
/// bits_per_samples or channels.
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
if (cfg.sample_rate != info.sample_rate
&& cfg.bits_per_sample == info.bits_per_sample
@ -322,7 +322,7 @@ class AudioKitStream : public AudioStreamX {
*
*/
void processActions() {
// LOGD(LOG_METHOD);
// TRACED();
actions.processActions();
// delay(1);
yield();
@ -337,7 +337,7 @@ class AudioKitStream : public AudioStreamX {
* @param ref
*/
void addAction(int pin, void (*action)(bool,int,void*), void* ref=nullptr ) {
LOGI(LOG_METHOD);
TRACEI();
// determine logic from config
AudioActions::ActiveLogic activeLogic = getActionLogic(pin);
actions.add(pin, action, activeLogic, ref);
@ -353,7 +353,7 @@ class AudioKitStream : public AudioStreamX {
* @param ref
*/
void addAction(int pin, void (*action)(bool,int,void*), AudioActions::ActiveLogic activeLogic, void* ref=nullptr ) {
LOGI(LOG_METHOD);
TRACEI();
actions.add(pin, action, activeLogic, ref);
}
@ -378,7 +378,7 @@ class AudioKitStream : public AudioStreamX {
*
*/
static void actionVolumeUp(bool, int, void*) {
LOGI(LOG_METHOD);
TRACEI();
pt_AudioKitStream->incrementVolume(+2);
}
@ -387,7 +387,7 @@ class AudioKitStream : public AudioStreamX {
*
*/
static void actionVolumeDown(bool, int, void*) {
LOGI(LOG_METHOD);
TRACEI();
pt_AudioKitStream->incrementVolume(-2);
}
@ -396,7 +396,7 @@ class AudioKitStream : public AudioStreamX {
*
*/
static void actionStartStop(bool, int, void*) {
LOGI(LOG_METHOD);
TRACEI();
pt_AudioKitStream->active = !pt_AudioKitStream->active;
pt_AudioKitStream->setActive(pt_AudioKitStream->active);
}
@ -406,7 +406,7 @@ class AudioKitStream : public AudioStreamX {
*
*/
static void actionStart(bool, int, void*) {
LOGI(LOG_METHOD);
TRACEI();
pt_AudioKitStream->active = true;
pt_AudioKitStream->setActive(pt_AudioKitStream->active);
}
@ -416,7 +416,7 @@ class AudioKitStream : public AudioStreamX {
*
*/
static void actionStop(bool, int, void*) {
LOGI(LOG_METHOD);
TRACEI();
pt_AudioKitStream->active = false;
pt_AudioKitStream->setActive(pt_AudioKitStream->active);
}
@ -587,7 +587,7 @@ class AudioKitStream : public AudioStreamX {
/// Setup the supported default actions
void setupActions() {
LOGI(LOG_METHOD);
TRACEI();
// SPI might have been activated
if (!cfg.sd_active){
LOGW("Deactivating SPI because SD is not active");

View File

@ -54,7 +54,7 @@ class AudioMP34DT05 : public AudioStreamX {
bool begin() { return begin(config); }
bool begin(AudioMP34DT05Config cfg) {
LOGI(LOG_METHOD);
TRACEI();
config = cfg;
cfg.logInfo();
if (p_buffer == nullptr) {
@ -73,7 +73,7 @@ class AudioMP34DT05 : public AudioStreamX {
}
void end() {
LOGI(LOG_METHOD);
TRACEI();
if (p_mic != nullptr) {
p_mic->end();
}

View File

@ -38,7 +38,7 @@ struct MozziConfig : AudioBaseInfo {
class MozziGenerator : public SoundGenerator<int16_t> {
public:
MozziGenerator(){
LOGD(LOG_METHOD);
TRACED();
}
MozziGenerator(MozziConfig config){
@ -147,11 +147,11 @@ class MozziStream : public AudioStream {
public:
MozziStream(){
LOGD(LOG_METHOD);
TRACED();
}
~MozziStream(){
LOGD(LOG_METHOD);
TRACED();
end();
if (input_ptr!=nullptr){
delete input_ptr;
@ -172,7 +172,7 @@ class MozziStream : public AudioStream {
// Start Mozzi - if controlRate > 0 we actiavate the sound generation (=>allow reads); the parameters describe the values if the
// provided input stream or resulting output stream;
void begin(MozziConfig cfg){
LOGD(LOG_METHOD);
TRACED();
config = cfg;
Mozzi.setAudioRate(config.sample_rate);
// in output mode we do not allocate any unnecessary functionality
@ -184,7 +184,7 @@ class MozziStream : public AudioStream {
}
void end(){
LOGD(LOG_METHOD);
TRACED();
Mozzi.stop();
}

View File

@ -49,7 +49,7 @@ class STKGenerator : public SoundGenerator<T> {
/// Starts the processing
bool begin(AudioBaseInfo cfg){
LOGI(LOG_METHOD);
TRACEI();
cfg.logInfo();
SoundGenerator<T>::begin(cfg);
max_value = NumberConverter::maxValue(sizeof(T)*8);

View File

@ -41,7 +41,7 @@ public:
}
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup) {
if (!SD.begin(cs)) {

View File

@ -59,7 +59,7 @@ class AudioSourceSDFAT : public AudioSource {
public:
/// Default constructor
AudioSourceSDFAT(const char* startFilePath = "/", const char* ext = ".mp3", int chipSelect = PIN_CS, int speedMHz = 2, bool setupIndex=true) {
LOGD(LOG_METHOD);
TRACED();
LOGI("SD chipSelect: %d", chipSelect);
LOGI("SD speedMHz: %d", speedMHz);
LOGI("ext: %s", ext);
@ -72,7 +72,7 @@ public:
/// Costructor with SdSpiConfig
AudioSourceSDFAT(const char* startFilePath, const char* ext, SdSpiConfig &config, bool setupIndex=true) {
LOGD(LOG_METHOD);
TRACED();
p_cfg = &config;
owns_cfg = false;
start_path = startFilePath;
@ -82,7 +82,7 @@ public:
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup) {
if (!sd.begin(*p_cfg)) {

View File

@ -40,7 +40,7 @@ public:
}
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup) {
if (!SD_MMC.begin("/sdcard", true)) {

View File

@ -42,7 +42,7 @@ public:
}
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup) {
if (!SD.begin(cs)) {

View File

@ -59,7 +59,7 @@ class AudioSourceSDFAT : public AudioSource {
public:
/// Default constructor
AudioSourceSDFAT(const char* startFilePath = "/", const char* ext = ".mp3", int chipSelect = PIN_CS, int speedMHz = 2, bool setupIndex=true) {
LOGD(LOG_METHOD);
TRACED();
LOGI("SD chipSelect: %d", chipSelect);
LOGI("SD speedMHz: %d", speedMHz);
LOGI("ext: %s", ext);
@ -72,7 +72,7 @@ public:
/// Costructor with SdSpiConfig
AudioSourceSDFAT(const char* startFilePath, const char* ext, SdSpiConfig &config, bool setupIndex=true) {
LOGD(LOG_METHOD);
TRACED();
p_cfg = &config;
owns_cfg = false;
start_path = startFilePath;
@ -82,7 +82,7 @@ public:
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup) {
if (!sd.begin(*p_cfg)) {

View File

@ -40,7 +40,7 @@ public:
}
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup) {
if (!SD_MMC.begin("/sdcard", true)) {

View File

@ -453,7 +453,7 @@ class UDPStream : public WiFiUDP {
* Replys will be sent to the initial remote caller
*/
size_t write(const uint8_t *buffer, size_t size) override {
LOGD(LOG_METHOD);
TRACED();
beginPacket(remoteIP(), remotePort());
size_t result = WiFiUDP::write(buffer, size);
endPacket();
@ -461,7 +461,7 @@ class UDPStream : public WiFiUDP {
}
// Reads bytes using WiFi::readBytes
size_t readBytes(uint8_t *buffer, size_t length) override {
LOGD(LOG_METHOD);
TRACED();
size_t len = available();
size_t bytes_read = 0;
if (len>0){

View File

@ -49,7 +49,7 @@ class AudioSourceSDFAT : public AudioSource {
public:
/// Default constructor
AudioSourceSDFAT(const char* startFilePath = "/", const char* ext = ".mp3", int chipSelect = PIN_CS, int speedMHz = 2) {
LOGD(LOG_METHOD);
TRACED();
LOGI("SD chipSelect: %d", chipSelect);
LOGI("SD speedMHz: %d", speedMHz);
LOGI("ext: %s", ext);
@ -61,7 +61,7 @@ public:
/// Costructor with SdSpiConfig
AudioSourceSDFAT(const char* startFilePath, const char* ext, SdSpiConfig &config) {
LOGD(LOG_METHOD);
TRACED();
p_cfg = &config;
owns_cfg = false;
start_path = startFilePath;
@ -70,14 +70,14 @@ public:
/// Destructor
virtual ~AudioSourceSDFAT(){
LOGD(LOG_METHOD);
TRACED();
if (p_cfg!=nullptr && owns_cfg){
delete p_cfg;
}
}
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
static bool is_sd_setup = false;
if (!is_sd_setup){
while (!sd.begin(*p_cfg)) {

View File

@ -82,7 +82,7 @@ class RTSPSourceAudioStream : public IAudioSource {
* @param info
*/
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
p_audiostream->setAudioInfo(info);
}
@ -107,7 +107,7 @@ class RTSPSourceAudioStream : public IAudioSource {
* Start preparing data in order to provide it for the stream
*/
virtual void start() override {
LOGI(LOG_METHOD);
TRACEI();
p_audiostream->begin();
active = true;
@ -116,7 +116,7 @@ class RTSPSourceAudioStream : public IAudioSource {
* Stop preparing data as the stream has ended
*/
virtual void stop() override {
LOGI(LOG_METHOD);
TRACEI();
active = false;
p_audiostream->end();
};
@ -171,7 +171,7 @@ class RTSPSourceStream : public IAudioSource {
* @param info
*/
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
rtp_info.setAudioInfo(info);
}
@ -194,14 +194,14 @@ class RTSPSourceStream : public IAudioSource {
* Start preparing data in order to provide it for the stream
*/
virtual void start() override {
LOGI(LOG_METHOD);
TRACEI();
active = true;
};
/**
* Stop preparing data as the stream has ended
*/
virtual void stop() override {
LOGI(LOG_METHOD);
TRACEI();
active = false;
};

View File

@ -39,16 +39,16 @@ class PortAudioConfig : public AudioBaseInfo {
class PortAudioStream : public AudioStreamX {
public:
PortAudioStream() {
LOGD(LOG_METHOD);
TRACED();
}
~PortAudioStream(){
LOGD(LOG_METHOD);
TRACED();
Pa_Terminate();
}
PortAudioConfig defaultConfig(RxTxMode mode) {
LOGD(LOG_METHOD);
TRACED();
PortAudioConfig result;
switch(mode){
case RX_MODE:
@ -72,14 +72,14 @@ class PortAudioStream : public AudioStreamX {
}
PortAudioConfig defaultConfig() {
LOGD(LOG_METHOD);
TRACED();
PortAudioConfig default_info;
return default_info;
}
/// notification of audio info change
void setAudioInfo(AudioBaseInfo in) override {
LOGI(LOG_METHOD);
TRACEI();
info.channels = in.channels;
info.sample_rate = in.sample_rate;
info.bits_per_sample = in.bits_per_sample;
@ -94,7 +94,7 @@ class PortAudioStream : public AudioStreamX {
// start with the indicated configuration
bool begin(PortAudioConfig info) {
LOGD(LOG_METHOD);
TRACED();
this->info = info;
if (info.channels>0 && info.sample_rate && info.bits_per_sample>0){
@ -133,7 +133,7 @@ class PortAudioStream : public AudioStreamX {
}
void end() override {
LOGD(LOG_METHOD);
TRACED();
err = Pa_StopStream( stream );
if( err != paNoError ) {
LOGE( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
@ -221,7 +221,7 @@ class PortAudioStream : public AudioStreamX {
/// automatically start the stream when we start to get data
void startStream() {
if (!stream_started) {
LOGD(LOG_METHOD);
TRACED();
err = Pa_StartStream( stream );
if( err == paNoError ) {
stream_started = true;

View File

@ -23,7 +23,7 @@ class SDDirect {
void begin(const char *startDir, const char *extension,
const char *file_name_pattern) {
LOGD(LOG_METHOD);
TRACED();
this->start_dir = startDir;
this->ext = extension;
this->file_name_pattern = file_name_pattern;
@ -114,7 +114,7 @@ class SDDirect {
}
void rewind(FileT f){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
f.rewind();
#else
@ -134,7 +134,7 @@ class SDDirect {
}
FileT openNext(FileT &dir) {
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
FileT result;
if (!result.openNext(&dir, O_READ)){
@ -147,7 +147,7 @@ class SDDirect {
}
void pushPath(const char* name){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
LOGD("pushPath: %s", name);
String nameStr(name);
@ -156,7 +156,7 @@ class SDDirect {
}
void popPath(){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
String str;
file_path_stack.pop_back(str);
@ -224,7 +224,7 @@ class SDDirect {
}
FileT open(const char* name){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
FileT result;
if (!result.open(name)){

View File

@ -22,7 +22,7 @@ class SDIndex {
};
void begin(const char *startDir, const char *extension,
const char *file_name_pattern, bool setupIndex=true) {
LOGD(LOG_METHOD);
TRACED();
this->ext = extension;
this->file_name_pattern = file_name_pattern;
idx_path = String(startDir)+"/idx.txt";
@ -44,7 +44,7 @@ class SDIndex {
void ls(Print &p, const char *startDir, const char *extension,
const char *file_name_pattern="*"){
LOGD(LOG_METHOD);
TRACED();
this->ext = extension;
this->file_name_pattern = file_name_pattern;
listDir(p, startDir);
@ -164,7 +164,7 @@ class SDIndex {
}
FileT openNext(FileT &dir) {
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
FileT result;
if (!result.openNext(&dir, O_READ)){
@ -186,7 +186,7 @@ class SDIndex {
}
void popPath(){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
String str;
file_path_stack.pop_back(str);
@ -196,7 +196,7 @@ class SDIndex {
/// checks if the file is a valid audio file
bool isValidAudioFile(FileT &file) {
LOGD(LOG_METHOD);
TRACED();
const char *file_name = fileName(file);
if (file.isDirectory()) {
LOGD("-> isValidAudioFile: '%s': %d", file_name, false);
@ -230,7 +230,7 @@ class SDIndex {
}
void rewind(FileT f){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
f.rewind();
#else
@ -282,7 +282,7 @@ class SDIndex {
}
FileT open(const char* name){
LOGD(LOG_METHOD);
TRACED();
#ifdef USE_SDFAT
FileT result;
if (!result.open(name)){

View File

@ -224,7 +224,7 @@ class TfLiteMicroSpeechRecognizeCommands : public TfLiteAbstractRecognizeCommand
/// Setup parameters from config
bool begin(TfLiteConfig cfg) override {
LOGD(LOG_METHOD);
TRACED();
this->cfg = cfg;
if (cfg.labels == nullptr) {
LOGE("config.labels not defined");
@ -240,7 +240,7 @@ class TfLiteMicroSpeechRecognizeCommands : public TfLiteAbstractRecognizeCommand
uint8_t* score,
bool* is_new_command) override {
LOGD(LOG_METHOD);
TRACED();
this->current_time_ms = current_time_ms;
this->time_since_last_top = current_time_ms - previous_time_ms;
@ -303,7 +303,7 @@ class TfLiteMicroSpeechRecognizeCommands : public TfLiteAbstractRecognizeCommand
/// Finds the result
TfLiteStatus evaluate(const char** found_command, uint8_t* result_score, bool* is_new_command) {
LOGD(LOG_METHOD);
TRACED();
float totals[categoryCount()]={0};
int count[categoryCount()]={0};
// calculate totals
@ -419,7 +419,7 @@ class TfLiteMicroSpeachWriter : public TfLiteWriter {
/// Call begin before starting the processing
virtual bool begin(TfLiteAudioStreamBase *parent) {
LOGD(LOG_METHOD);
TRACED();
this->parent = parent;
cfg = parent->config();
current_time = 0;
@ -460,7 +460,7 @@ class TfLiteMicroSpeachWriter : public TfLiteWriter {
}
virtual bool write(int16_t sample) {
LOGD(LOG_METHOD);
TRACED();
if (!write1(sample)){
// determine time
current_time += cfg.kFeatureSliceStrideMs;
@ -531,7 +531,7 @@ class TfLiteMicroSpeachWriter : public TfLiteWriter {
// | data@80ms | -- | <empty> |
// +-----------+ +-----------+
virtual int8_t* addSlice() {
LOGD(LOG_METHOD);
TRACED();
// shift p_feature_data by one slice one one
memmove(p_feature_data, p_feature_data + cfg.kFeatureSliceSize,
(cfg.kFeatureSliceCount - 1) * cfg.kFeatureSliceSize);
@ -609,7 +609,7 @@ class TfLiteMicroSpeachWriter : public TfLiteWriter {
}
virtual TfLiteStatus initializeMicroFeatures() {
LOGD(LOG_METHOD);
TRACED();
config.window.size_ms = cfg.kFeatureSliceDurationMs;
config.window.step_size_ms = cfg.kFeatureSliceStrideMs;
config.filterbank.num_channels = cfg.kFeatureSliceSize;
@ -637,7 +637,7 @@ class TfLiteMicroSpeachWriter : public TfLiteWriter {
int input_size, int8_t* output,
int output_size,
size_t* num_samples_read) {
LOGD(LOG_METHOD);
TRACED();
const int16_t* frontend_input = input;
// Apply FFT
@ -699,7 +699,7 @@ class TfLiteMicroSpeachWriter : public TfLiteWriter {
if (cfg.respondToCommand != nullptr) {
cfg.respondToCommand(found_command, score, is_new_command);
} else {
LOGD(LOG_METHOD);
TRACED();
if (is_new_command) {
char buffer[80];
sprintf(buffer, "Result: %s, score: %d, is_new: %s", found_command,
@ -732,7 +732,7 @@ class TfLiteSineReader : public TfLiteReader {
}
virtual int read(int16_t*data, int sampleCount) override {
LOGD(LOG_METHOD);
TRACED();
float two_pi = 2 * PI;
for (int j=0; j<sampleCount; j+=channels){
// Quantize the input from floating-point to integer
@ -793,7 +793,7 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
/// Optionally define your own p_interpreter
void setInterpreter(tflite::MicroInterpreter* p_interpreter) {
LOGD(LOG_METHOD);
TRACED();
this->p_interpreter = p_interpreter;
}
@ -805,7 +805,7 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
/// Start the processing
virtual bool begin(TfLiteConfig config) override {
LOGD(LOG_METHOD);
TRACED();
cfg = config;
// alloatme memory
@ -876,7 +876,7 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
/// process the data in batches of max kMaxAudioSampleSize.
virtual size_t write(const uint8_t* audio, size_t bytes) override {
LOGD(LOG_METHOD);
TRACED();
if (cfg.writer==nullptr){
LOGE("cfg.output is null");
return 0;
@ -894,7 +894,7 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
/// provide audio data with cfg.input
virtual size_t readBytes(uint8_t *data, size_t len) override {
LOGD(LOG_METHOD);
TRACED();
if (cfg.reader!=nullptr){
return cfg.reader->read((int16_t*)data, (int) len/sizeof(int16_t)) * sizeof(int16_t);
}else {
@ -930,7 +930,7 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
int8_t* p_tensor_buffer = nullptr;
virtual bool setModel(const unsigned char* model) {
LOGD(LOG_METHOD);
TRACED();
p_model = tflite::GetModel(model);
if (p_model->version() != TFLITE_SCHEMA_VERSION) {
LOGE(
@ -958,7 +958,7 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
//
virtual bool setupInterpreter() {
if (p_interpreter == nullptr) {
LOGI(LOG_METHOD);
TRACEI();
if (cfg.useAllOpsResolver) {
tflite::AllOpsResolver resolver;
static tflite::MicroInterpreter static_interpreter(

View File

@ -72,7 +72,7 @@ public:
VS1053Stream() = default;
VS1053Config defaultConfig(RxTxMode mode=TX_MODE) {
LOGD(LOG_METHOD);
TRACED();
VS1053Config c;
// recording is rather inefficient so we use a low sample rate as default
if (mode==RX_MODE){
@ -98,7 +98,7 @@ public:
/// Starts with the indicated configuration
bool begin(VS1053Config cfg) {
LOGI(LOG_METHOD);
TRACEI();
bool result = true;
// enfornce encoded data for midi mode
if (cfg.is_midi){
@ -171,7 +171,7 @@ public:
/// Stops the processing and releases the memory
void end(){
LOGI(LOG_METHOD);
TRACEI();
if (p_out!=nullptr){
delete p_out;
p_out = nullptr;
@ -200,7 +200,7 @@ public:
/// provides the volume
float volume() {
LOGD(LOG_METHOD);
TRACED();
if (p_vs1053==nullptr) return -1.0;
return p_vs1053->getVolume()/100.0;;
}
@ -217,7 +217,7 @@ public:
}
/// Get the currenet balance setting (-1.0..1.0)
float balance(){
LOGD(LOG_METHOD);
TRACED();
if (p_vs1053==nullptr) return -1.0;
return static_cast<float>(p_vs1053->getBalance())/100.0;
}
@ -230,13 +230,13 @@ public:
/// returns the VS1053 object
VS1053 &getVS1053() {
LOGD(LOG_METHOD);
TRACED();
return *p_vs1053;
}
/// Defines an alternative encoder that will be used (e.g. MP3Encoder). It must be allocated on the heap!
bool setEncoder(AudioEncoder *enc){
LOGI(LOG_METHOD);
TRACEI();
if (p_out!=nullptr){
logError("setEncoder");
return false;
@ -255,13 +255,13 @@ public:
return result;
}
size_t readBytes(uint8_t* data, size_t len) override {
LOGD(LOG_METHOD);
TRACED();
return getVS1053().readBytes(data, len);
}
/// Provides the treble amplitude value
float treble() {
LOGD(LOG_METHOD);
TRACED();
return static_cast<float>(getVS1053().treble())/100.0;
}
@ -276,7 +276,7 @@ public:
/// Provides the Bass amplitude value
float bass() {
LOGD(LOG_METHOD);
TRACED();
return static_cast<float>(getVS1053().bass())/100.0;
}
@ -302,7 +302,7 @@ public:
/// Sends a midi message to the VS1053
void sendMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2) {
LOGI(LOG_METHOD);
TRACEI();
if (!cfg.is_midi){
LOGE("start with is_midi=true");
return;
@ -325,7 +325,7 @@ protected:
CopyEncoder copy; // used when is_encoded_data == true
bool beginTx() {
LOGI(LOG_METHOD);
TRACEI();
p_out->begin(cfg);
bool result = p_vs1053->begin();
p_vs1053->startSong();
@ -341,7 +341,7 @@ protected:
#if VS1053_EXT
bool beginRx() {
LOGI(LOG_METHOD);
TRACEI();
VS1053Recording rec;
rec.setSampleRate(cfg.sample_rate);
rec.setChannels(cfg.channels);
@ -350,7 +350,7 @@ protected:
}
bool beginMidi(){
LOGI(LOG_METHOD);
TRACEI();
p_out->begin(cfg);
bool result = p_vs1053->beginMidi();
delay(500);

View File

@ -27,13 +27,13 @@ class MetaDataPrint : public AudioPrint {
/// Defines the callback
virtual void setCallback(void (*fn)(MetaDataType info, const char* str, int len)) {
LOGD(LOG_METHOD);
TRACED();
callback = fn;
}
/// Starts the processing - iceMetaint is determined from the HttpRequest
virtual void begin(HttpRequest &http) {
LOGD(LOG_METHOD);
TRACED();
ICYUrlSetup icySetup;
int metaInt = icySetup.setup(http);
icySetup.executeCallback(callback);
@ -57,7 +57,7 @@ class MetaDataPrint : public AudioPrint {
virtual void end() {
if (callback!=nullptr && meta != nullptr) {
LOGD(LOG_METHOD);
TRACED();
meta->end();
}
}

View File

@ -26,13 +26,13 @@ class MetaDataFilter {
/// (Re)starts the processing
void begin() {
LOGD(LOG_METHOD);
TRACED();
start = 0;
}
/// Writes the data to the decoder
size_t write(uint8_t* data, size_t len){
LOGD(LOG_METHOD);
TRACED();
if (p_decoder==nullptr) return 0;
int pos=0; int meta_len=0;
if (findTag(data, len, pos, meta_len)){

View File

@ -183,7 +183,7 @@ class MetaDataICY : public AbstractMetaData {
/// allocates the memory to store the metadata / we support changing sizes
virtual void setupMetaData(int meta_size) {
LOGD(LOG_METHOD);
TRACED();
if (meta_size>0){
if (metaData==nullptr){
metaData = new char[meta_size+1];
@ -204,7 +204,7 @@ class MetaDataICY : public AbstractMetaData {
/// e.g. StreamTitle=' House Bulldogs - But your love (Radio Edit)';StreamUrl='';
virtual void processMetaData( char* metaData, int len) {
//CHECK_MEMORY();
LOGD(LOG_METHOD);
TRACED();
metaData[len]=0;
if (isAscii(metaData, 12)){
LOGI("%s", metaData);
@ -251,7 +251,7 @@ class ICYUrlSetup {
public:
/// Fills the metaint from the Http Request and executes metadata callbacks on http reply parameters
int setup(HttpRequest &http ) {
LOGD(LOG_METHOD);
TRACED();
p_http = &http;
const char* iceMetaintStr = http.reply().get("icy-metaint");
if (iceMetaintStr){
@ -266,7 +266,7 @@ class ICYUrlSetup {
/// Executes the metadata callbacks with data provided from the http request result parameter
void executeCallback(void (*callback)(MetaDataType info, const char* str, int len)) {
LOGI(LOG_METHOD);
TRACEI();
if (callback==nullptr){
LOGW("callback not defined")
}

View File

@ -542,20 +542,20 @@ class MetaDataID3 : public AbstractMetaData {
}
void begin() {
LOGI(LOG_METHOD);
TRACEI();
id3v1.begin();
id3v2.begin();
}
void end() {
LOGI(LOG_METHOD);
TRACEI();
id3v1.end();
id3v2.end();
}
/// Provide tha audio data to the API to parse for Meta Data
virtual size_t write(const uint8_t *data, size_t length){
LOGD(LOG_METHOD);
TRACED();
if (filter & SELECT_ID3V2) id3v2.write(data, length);
if (!id3v2.isProcessed()) {
if (filter & SELECT_ID3V1) id3v1.write(data, length);

View File

@ -33,7 +33,7 @@ class PWMAudioStreamAVR : public PWMAudioStreamBase {
// Ends the output
virtual void end(){
LOGD(LOG_METHOD);
TRACED();
noInterrupts();
// stop timer callback
TCCR1B = 0;
@ -46,7 +46,7 @@ class PWMAudioStreamAVR : public PWMAudioStreamBase {
/// Setup AVR timer with callback
void setupTimer() {
LOGD(LOG_METHOD);
TRACED();
// CPU Frequency 16 MHz
// prescaler 1, 256 or 1024 => no prescaling
uint32_t steps = F_CPU / 8 / audio_config.sample_rate; // e.g. (16000000/8/44100=>45)
@ -71,7 +71,7 @@ class PWMAudioStreamAVR : public PWMAudioStreamBase {
/// Setup LED PWM
void setupPWM(){
LOGD(LOG_METHOD);
TRACED();
if (audio_config.channels>2) {
LOGW("Max 2 channels supported - you requested %d", audio_config.channels);
audio_config.channels = 2;

View File

@ -51,7 +51,7 @@ struct PWMConfig : public AudioBaseInfo {
// define all pins by passing an array and updates the channels by the number of pins
template<size_t N>
void setPins(int (&array)[N]) {
LOGD(LOG_METHOD);
TRACED();
int new_channels = sizeof(array)/sizeof(int);
if (channels!=new_channels) {
LOGI("channels updated to %d", new_channels);
@ -103,7 +103,7 @@ class PWMAudioStreamBase : public AudioPrint {
// /// Starts the PWMAudio using callbacks
bool begin(uint16_t sampleRate, uint8_t channels, PWMCallbackType cb) {
LOGD(LOG_METHOD);
TRACED();
if (channels>maxChannels()){
LOGE("Only max %d channels are supported!",maxChannels());
return false;
@ -122,7 +122,7 @@ class PWMAudioStreamBase : public AudioPrint {
/// updates the sample rate dynamically
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
PWMConfig cfg = audio_config;
if (cfg.sample_rate != info.sample_rate
|| cfg.channels != info.channels
@ -138,7 +138,7 @@ class PWMAudioStreamBase : public AudioPrint {
/// starts the processing using Streams
bool begin(PWMConfig config ){
LOGD(LOG_METHOD);
TRACED();
this->audio_config = config;
if (config.channels>maxChannels()){
LOGE("Only max %d channels are supported!",maxChannels());
@ -166,7 +166,7 @@ class PWMAudioStreamBase : public AudioPrint {
// restart with prior definitions
bool begin(){
LOGD(LOG_METHOD);
TRACED();
// allocate buffer if necessary
if (user_callback==nullptr) {
if (buffer==nullptr) {
@ -197,7 +197,7 @@ class PWMAudioStreamBase : public AudioPrint {
}
virtual void end(){
LOGD(LOG_METHOD);
TRACED();
is_timer_started = false;
}
@ -262,7 +262,7 @@ class PWMAudioStreamBase : public AudioPrint {
/// when we get the first write -> we activate the timer to start with the output of data
virtual void startTimer(){
if (!is_timer_started){
LOGD(LOG_METHOD);
TRACED();
is_timer_started = true;
}
}
@ -280,7 +280,7 @@ class PWMAudioStreamBase : public AudioPrint {
}
void playNextFrameCallback(){
//LOGD(LOG_METHOD);
//TRACED();
uint8_t channels = audio_config.channels;
int16_t data[channels];
if (user_callback(channels, data)){
@ -296,7 +296,7 @@ class PWMAudioStreamBase : public AudioPrint {
/// writes the next frame to the output pins
void playNextFrameStream(){
if (is_timer_started){
//LOGD(LOG_METHOD);
//TRACED();
int required = (audio_config.bits_per_sample / 8) * audio_config.channels;
if (buffer->available() >= required){
for (int j=0;j<audio_config.channels;j++){
@ -311,7 +311,7 @@ class PWMAudioStreamBase : public AudioPrint {
}
void playNextFrame(){
// LOGD(LOG_METHOD);
// TRACED();
if (user_callback!=nullptr){
playNextFrameCallback();
} else {

View File

@ -41,7 +41,7 @@ class PWMAudioStreamESP32 : public PWMAudioStreamBase {
// Ends the output
virtual void end(){
LOGD(LOG_METHOD);
TRACED();
timerAlarmDisable(timer);
for (int j=0;j<audio_config.channels;j++){
ledcDetachPin(pins[j].gpio);
@ -66,7 +66,7 @@ class PWMAudioStreamESP32 : public PWMAudioStreamBase {
/// Setup LED PWM
virtual void setupPWM(){
LOGD(LOG_METHOD);
TRACED();
// frequency is driven by selected resolution
uint32_t freq = frequency(audio_config.resolution)*1000;
audio_config.pwm_frequency = freq;
@ -101,7 +101,7 @@ class PWMAudioStreamESP32 : public PWMAudioStreamBase {
/// Setup ESP32 timer with callback
virtual void setupTimer() {
LOGD(LOG_METHOD);
TRACED();
// Attach timer int at sample rate
int prescale = 2;

View File

@ -27,7 +27,7 @@ class PWMAudioStreamMBED : public PWMAudioStreamBase {
// Ends the output
virtual void end() override {
LOGD(LOG_METHOD);
TRACED();
ticker.end(); // it does not hurt to call this even if it has not been started
is_timer_started = false;
@ -51,7 +51,7 @@ class PWMAudioStreamMBED : public PWMAudioStreamBase {
/// when we get the first write -> we activate the timer to start with the output of data
virtual void startTimer() override {
if (!is_timer_started){
LOGD(LOG_METHOD);
TRACED();
long wait_time = 1000000l / audio_config.sample_rate;
ticker.setCallbackParameter(this);
ticker.begin(defaultPWMAudioOutputCallback, wait_time, US);
@ -61,7 +61,7 @@ class PWMAudioStreamMBED : public PWMAudioStreamBase {
/// Setup PWM Pins
virtual void setupPWM(){
LOGD(LOG_METHOD);
TRACED();
unsigned long period = 1000000l / audio_config.pwm_frequency; // -> 30.517578125 microseconds
pins.resize(audio_config.channels);
for (int j=0;j<audio_config.channels;j++){

View File

@ -45,7 +45,7 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
/// Ends the output -> resets the timer and the pins
void end() override {
LOGD(LOG_METHOD);
TRACED();
ticker.end(); // it does not hurt to call this even if it has not been started
is_timer_started = false;
for(auto pin : pins) {
@ -61,7 +61,7 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
virtual void startTimer() override {
if (!is_timer_started){
LOGD(LOG_METHOD);
TRACED();
long wait_time = 1000000l / audio_config.sample_rate;
ticker.setCallbackParameter(this);
ticker.begin(defaultPWMAudioOutputCallbackPico, wait_time, US);
@ -72,7 +72,7 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
// setup pwm config and all pins
void setupPWM() override {
LOGD(LOG_METHOD);
TRACED();
pwm_config cfg = setupPWMConfig();
// initialize empty pins
@ -99,7 +99,7 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
// defines the pwm_config which will be used to drive the pins
pwm_config setupPWMConfig() {
LOGD(LOG_METHOD);
TRACED();
// setup pwm frequency
pwm_config pico_pwm_config = pwm_get_default_config();
int wrap_value = maxOutputValue(); // amplitude of square wave (pwm values -amplitude to amplitude) for one byte

View File

@ -55,7 +55,7 @@ class TimerAlarmRepeatingAVR : public TimerAlarmRepeatingDef {
// ends the timer and if necessary the task
bool end() override {
LOGD(LOG_METHOD);
TRACED();
noInterrupts();
// end timer callback
TCCR1B = 0;
@ -72,7 +72,7 @@ class TimerAlarmRepeatingAVR : public TimerAlarmRepeatingDef {
repeating_timer_callback_t callback = nullptr;
void setupTimer(uint64_t sample_rate) {
LOGD(LOG_METHOD);
TRACED();
// CPU Frequency 16 MHz
// prescaler 1, 256 or 1024 => no prescaling
uint32_t steps = F_CPU / 8 / sample_rate; // e.g. (16000000/8/44100=>45)

View File

@ -18,7 +18,7 @@ class UserCallback {
public:
void setup(repeating_timer_callback_t my_callback, void *user_data, bool lock ){
LOGD(LOG_METHOD);
TRACED();
this->my_callback = my_callback;
this->user_data = user_data;
this->lock = lock; // false when called from Task
@ -63,13 +63,13 @@ static IRAM_ATTR void userCallback3() {
class TimerCallback {
public:
TimerCallback() {
LOGD(LOG_METHOD);
TRACED();
timerMux = portMUX_INITIALIZER_UNLOCKED;
p_handler_task = nullptr;
}
void setup(TaskHandle_t &handler_task){
LOGD(LOG_METHOD);
TRACED();
p_handler_task = &handler_task;
}
@ -144,7 +144,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
/// Starts the alarm timer
bool begin(repeating_timer_callback_t callback_f, uint32_t time, TimeUnit unit = MS) override {
LOGD(LOG_METHOD);
TRACED();
// we determine the time in microseconds
switch(unit){
@ -182,7 +182,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
/// ends the timer and if necessary the task
bool end() override {
LOGD(LOG_METHOD);
TRACED();
if (started){
timerEnd(adc_timer);
if (handler_task!=nullptr){
@ -212,7 +212,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
/// direct timer callback
void setupDirectTimerCallback(repeating_timer_callback_t callback_f){
LOGD(LOG_METHOD);
TRACED();
// we start the timer which runs the callback in a seprate task
if (timerCallbackArray==nullptr){
timerCallbackArray = new TimerCallback[4];
@ -237,7 +237,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
// timer callback is notifiying task
void setupTimerCallbackInThread(repeating_timer_callback_t callback_f){
LOGD(LOG_METHOD);
TRACED();
// We start the timer which executes the callbacks directly
if (simpleUserCallback==nullptr){
simpleUserCallback = new UserCallback[4];
@ -255,7 +255,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
/// No timer - just a simple task loop
void setupSimpleThreadLoop(repeating_timer_callback_t callback_f){
LOGD(LOG_METHOD);
TRACED();
user_callback.setup(callback_f, object, false);
xTaskCreatePinnedToCore(simpleTaskLoop, "TimerAlarmRepeatingTask", configMINIMAL_STACK_SIZE+10000, this, priority, &handler_task, core);
LOGI("Task created on core %d", core);
@ -264,7 +264,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
/// We can not do any I2C calls in the interrupt handler so we need to do this in a separate task
static void complexTaskHandler(void *param) {
LOGI(LOG_METHOD);
TRACEI();
UserCallback* cb = (UserCallback*) param;
uint32_t thread_notification;
@ -280,7 +280,7 @@ class TimerAlarmRepeatingESP32 : public TimerAlarmRepeatingDef {
/// We can not do any I2C calls in the interrupt handler so we need to do this in a separate task.
static void simpleTaskLoop(void *param) {
LOGI(LOG_METHOD);
TRACEI();
TimerAlarmRepeatingESP32* ta = (TimerAlarmRepeatingESP32*) param;
while (true) {

View File

@ -21,7 +21,7 @@ template <class T>
class StreamCopyT {
public:
StreamCopyT(Print &to, AudioStream &from, int buffer_size=DEFAULT_BUFFER_SIZE){
LOGD(LOG_METHOD);
TRACED();
begin(to, from);
this->buffer_size = buffer_size;
buffer = new uint8_t[buffer_size];
@ -31,7 +31,7 @@ class StreamCopyT {
}
StreamCopyT(Print &to, Stream &from, int buffer_size=DEFAULT_BUFFER_SIZE){
LOGD(LOG_METHOD);
TRACED();
begin(to, from);
this->buffer_size = buffer_size;
buffer = new uint8_t[buffer_size];
@ -41,7 +41,7 @@ class StreamCopyT {
}
StreamCopyT(int buffer_size=DEFAULT_BUFFER_SIZE){
LOGD(LOG_METHOD);
TRACED();
this->buffer_size = buffer_size;
buffer = new uint8_t[buffer_size];
if (buffer==nullptr){
@ -88,7 +88,7 @@ class StreamCopyT {
// copies the data from one channel from the source to 2 channels on the destination - the result is in bytes
inline size_t copy(){
LOGD(LOG_METHOD);
TRACED();
// if not initialized we do nothing
if (from==nullptr || to==nullptr) return 0;
@ -194,7 +194,7 @@ class StreamCopyT {
/// copies all data - returns true if we copied anything
size_t copyAll(int retryCount=5, int retryWaitMs=200){
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
int retry = 0;
@ -228,13 +228,13 @@ class StreamCopyT {
/// Define the callback that will notify about mime changes
void setMimeCallback(void (*callback)(const char*)){
LOGD(LOG_METHOD);
TRACED();
this->notifyMimeCallback = callback;
}
/// Defines a callback that is notified with the wirtten data
void setCallbackOnWrite(void (*onWrite)(void*obj, void*buffer, size_t len), void* obj){
LOGD(LOG_METHOD);
TRACED();
this->onWrite = onWrite;
this->onWriteObj = obj;
}
@ -317,15 +317,15 @@ class StreamCopyT {
class StreamCopy : public StreamCopyT<uint8_t> {
public:
StreamCopy(int buffer_size=DEFAULT_BUFFER_SIZE): StreamCopyT<uint8_t>(buffer_size) {
LOGD(LOG_METHOD);
TRACED();
}
StreamCopy(Print &to, AudioStream &from, int buffer_size=DEFAULT_BUFFER_SIZE) : StreamCopyT<uint8_t>(to, from, buffer_size){
LOGD(LOG_METHOD);
TRACED();
}
StreamCopy(Print &to, Stream &from, int buffer_size=DEFAULT_BUFFER_SIZE) : StreamCopyT<uint8_t>(to, from, buffer_size){
LOGD(LOG_METHOD);
TRACED();
}
/// copies a buffer length of data and applies the converter

View File

@ -123,15 +123,27 @@ class AudioLogger {
}
};
#define LOG_OUT(level, ...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, level).str(),LOG_PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
#define LOGD(...) if (AudioLogger::instance().level()<=AudioLogger::Debug) { LOG_OUT(AudioLogger::Debug, __VA_ARGS__);}
#define LOGI(...) if (AudioLogger::instance().level()<=AudioLogger::Info) { LOG_OUT(AudioLogger::Info, __VA_ARGS__);}
#define LOGW(...) if (AudioLogger::instance().level()<=AudioLogger::Warning) { LOG_OUT(AudioLogger::Warning, __VA_ARGS__);}
#define LOGE(...) if (AudioLogger::instance().level()<=AudioLogger::Error) { LOG_OUT(AudioLogger::Error, __VA_ARGS__);}
}
//#define LOG_OUT(level, fmt, ...) {AudioLogger::instance().prefix(__FILE__,__LINE__, level);cont char PROGMEM *fmt_P=F(fmt); snprintf_P(AudioLogger::instance().str(), LOG_PRINTF_BUFFER_SIZE, fmt, ##__VA_ARGS__); AudioLogger::instance().println();}
#define LOG_OUT_PGMEM(level, fmt, ...) { \
AudioLogger::instance().prefix(__FILE__,__LINE__, level); \
snprintf(AudioLogger::instance().str(), LOG_PRINTF_BUFFER_SIZE, PSTR(fmt), ##__VA_ARGS__); \
AudioLogger::instance().println();\
}
#define LOG_OUT(level, fmt, ...) { \
AudioLogger::instance().prefix(__FILE__,__LINE__, level); \
snprintf(AudioLogger::instance().str(), LOG_PRINTF_BUFFER_SIZE, fmt, ##__VA_ARGS__); \
AudioLogger::instance().println();\
}
// Log statments which store the fmt string in Progmem
#define LOGD(fmt, ...) if (AudioLogger::instance().level()<=AudioLogger::Debug) { LOG_OUT_PGMEM(AudioLogger::Debug, fmt, ##__VA_ARGS__);}
#define LOGI(fmt, ...) if (AudioLogger::instance().level()<=AudioLogger::Info) { LOG_OUT_PGMEM(AudioLogger::Info, fmt, ##__VA_ARGS__);}
#define LOGW(fmt, ...) if (AudioLogger::instance().level()<=AudioLogger::Warning) { LOG_OUT_PGMEM(AudioLogger::Warning, fmt, ##__VA_ARGS__);}
#define LOGE(fmt, ...) if (AudioLogger::instance().level()<=AudioLogger::Error) { LOG_OUT_PGMEM(AudioLogger::Error, fmt, ##__VA_ARGS__);}
#else
@ -141,3 +153,20 @@ class AudioLogger {
#define LOGE(...)
#endif
// Log File and line
#ifdef NO_TRACED
# define TRACED()
#else
# define TRACED() if (AudioLogger::instance().level()<=AudioLogger::Debug) { LOG_OUT(AudioLogger::Debug, LOG_METHOD);}
#endif
#ifdef NO_TRACEI
# define TRACEI()
#else
# define TRACEI() if (AudioLogger::instance().level()<=AudioLogger::Info) { LOG_OUT(AudioLogger::Info, LOG_METHOD);}
#endif
#define TRACEW() if (AudioLogger::instance().level()<=AudioLogger::Warning) { LOG_OUT(AudioLogger::Warning, LOG_METHOD);}
#define TRACEE() if (AudioLogger::instance().level()<=AudioLogger::Error) { LOG_OUT(AudioLogger::Error, LOG_METHOD);}

View File

@ -41,7 +41,7 @@ namespace audio_tools {
* @param decoder
*/
AudioPlayer(AudioSource& source, AudioPrint& output, AudioDecoder& decoder) {
LOGD(LOG_METHOD);
TRACED();
this->p_source = &source;
this->p_decoder = &decoder;
if (decoder.isResultPCM()){
@ -66,7 +66,7 @@ namespace audio_tools {
* @param notify
*/
AudioPlayer(AudioSource& source, Print& output, AudioDecoder& decoder, AudioBaseInfoDependent* notify = nullptr) {
LOGD(LOG_METHOD);
TRACED();
this->p_source = &source;
this->p_decoder = &decoder;
if (decoder.isResultPCM()){
@ -87,7 +87,7 @@ namespace audio_tools {
* @param decoder
*/
AudioPlayer(AudioSource& source, AudioStream& output, AudioDecoder& decoder) {
LOGD(LOG_METHOD);
TRACED();
this->p_source = &source;
if (decoder.isResultPCM()){
this->volume_out.setTarget(output);
@ -110,7 +110,7 @@ namespace audio_tools {
/// (Re)Starts the playing of the music (from the beginning)
virtual bool begin(int index=0, bool isActive = true) {
LOGD(LOG_METHOD);
TRACED();
bool result = false;
// initilaize volume
if (current_volume==-1){
@ -151,7 +151,7 @@ namespace audio_tools {
}
virtual void end() {
LOGD(LOG_METHOD);
TRACED();
active = false;
p_out_decoding->end();
meta_out.end();
@ -186,7 +186,7 @@ namespace audio_tools {
/// Updates the audio info in the related objects
virtual void setAudioInfo(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
LOGI("sample_rate: %d", info.sample_rate);
LOGI("bits_per_sample: %d", info.bits_per_sample);
LOGI("channels: %d", info.channels);
@ -204,19 +204,19 @@ namespace audio_tools {
/// starts / resumes the playing of a matching song
virtual void play() {
LOGD(LOG_METHOD);
TRACED();
active = true;
}
/// halts the playing
virtual void stop() {
LOGD(LOG_METHOD);
TRACED();
active = false;
}
/// moves to next file
virtual bool next(int offset=1) {
LOGD(LOG_METHOD);
TRACED();
previous_stream = false;
active = setStream(p_source->nextStream(offset));
return active;
@ -224,7 +224,7 @@ namespace audio_tools {
/// moves to selected file
virtual bool setIndex(int idx) {
LOGD(LOG_METHOD);
TRACED();
previous_stream = false;
active = setStream(p_source->selectStream(idx));
return active;
@ -232,7 +232,7 @@ namespace audio_tools {
/// moves to selected file
virtual bool setPath(const char* path) {
LOGD(LOG_METHOD);
TRACED();
previous_stream = false;
active = setStream(p_source->selectStream(path));
return active;
@ -240,7 +240,7 @@ namespace audio_tools {
/// moves to previous file
virtual bool previous(int offset=1) {
LOGD(LOG_METHOD);
TRACED();
previous_stream = true;
active = setStream(p_source->previousStream(offset));
return active;
@ -295,7 +295,7 @@ namespace audio_tools {
/// Call this method in the loop.
virtual void copy() {
if (active) {
LOGD(LOG_METHOD);
TRACED();
if (p_final_print!=nullptr && p_final_print->availableForWrite()==0){
// not ready to do anything - so we wait a bit
delay(100);
@ -332,7 +332,7 @@ namespace audio_tools {
/// Defines the medatadata callback
virtual void setMetadataCallback(void (*callback)(MetaDataType type, const char* str, int len), ID3TypeSelection sel=SELECT_ID3) {
LOGI(LOG_METHOD);
TRACEI();
// setup metadata.
if (p_source->setMetadataCallback(callback)){
// metadata is handled by source
@ -371,7 +371,7 @@ namespace audio_tools {
/// Default constructur only allowed in subclasses
AudioPlayer() {
LOGD(LOG_METHOD);
TRACED();
}
/// Callback implementation which writes to metadata

View File

@ -39,7 +39,7 @@ class AudioPrint : public Print, public AudioBaseInfoDependent, public AudioBase
// overwrite to do something useful
virtual void setAudioInfo(AudioBaseInfo info) override {
LOGD(LOG_METHOD);
TRACED();
cfg = info;
info.logInfo();
if (p_notify!=nullptr){
@ -94,7 +94,7 @@ class CsvStream : public AudioPrint {
/// Starts the processing with 2 channels
void begin(){
LOGD(LOG_METHOD);
TRACED();
this->active = true;
}
@ -109,14 +109,14 @@ class CsvStream : public AudioPrint {
/// Starts the processing with the number of channels defined in AudioBaseInfo
void begin(AudioBaseInfo info){
LOGD(LOG_METHOD);
TRACED();
this->active = true;
this->channels = info.channels;
}
/// Starts the processing with the defined number of channels
void begin(int channels, Print &out=Serial){
LOGD(LOG_METHOD);
TRACED();
this->channels = channels;
this->out_ptr = &out;
this->active = true;
@ -124,13 +124,13 @@ class CsvStream : public AudioPrint {
/// Sets the CsvStream as inactive
void end() {
LOGD(LOG_METHOD);
TRACED();
active = false;
}
/// defines the number of channels
virtual void setAudioInfo(AudioBaseInfo info) {
LOGI(LOG_METHOD);
TRACEI();
info.logInfo();
this->channels = info.channels;
};
@ -138,7 +138,7 @@ class CsvStream : public AudioPrint {
/// Writes the data - formatted as CSV - to the output stream
virtual size_t write(const uint8_t* data, size_t len) {
if (!active) return 0;
LOGD(LOG_METHOD);
TRACED();
size_t lenChannels = len / (sizeof(T)*channels);
data_ptr = (T*)data;
for (size_t j=0;j<lenChannels;j++){
@ -185,21 +185,21 @@ class HexDumpStream : public AudioPrint {
}
void begin(AudioBaseInfo info){
LOGD(LOG_METHOD);
TRACED();
info.logInfo();
this->active = true;
pos = 0;
}
void begin(){
LOGD(LOG_METHOD);
TRACED();
this->active = true;
pos = 0;
}
/// Sets the CsvStream as inactive
void end() {
LOGD(LOG_METHOD);
TRACED();
active = false;
}
@ -210,7 +210,7 @@ class HexDumpStream : public AudioPrint {
virtual size_t write(const uint8_t* data, size_t len) {
if (!active) return 0;
LOGD(LOG_METHOD);
TRACED();
for (size_t j=0;j<len;j++){
out_ptr->print(data[j], HEX);
out_ptr->print(" ");

View File

@ -129,7 +129,7 @@ class SPDIFStream : public AudioStreamX {
/// Start with the provided parameters
bool begin(SPDIFConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
// Some validations to make sure that the config is valid
if (!(cfg.channels == 1 || cfg.channels == 2)) {
LOGE("Unsupported number of channels: %d", cfg.channels);
@ -172,14 +172,14 @@ class SPDIFStream : public AudioStreamX {
}
void end() {
LOGD(LOG_METHOD);
TRACED();
i2s.end();
i2sOn = false;
}
/// Change the audio parameters
void setAudioInfo(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
cfg.bits_per_sample = info.bits_per_sample;
cfg.channels = info.channels;
cfg.sample_rate = info.sample_rate;
@ -236,7 +236,7 @@ class SPDIFStream : public AudioStreamX {
// initialize S/PDIF buffer
void spdif_buf_init(void) {
LOGD(LOG_METHOD);
TRACED();
size_t i;
uint32_t bmc_mw = BMC_W;

View File

@ -72,20 +72,20 @@ public:
}
AudioSourceCallback(Stream* (*nextStreamCallback)(), void (*onStartCallback)() = nullptr) {
LOGD(LOG_METHOD);
TRACED();
this->onStartCallback = onStartCallback;
this->nextStreamCallback = nextStreamCallback;
}
/// Reset actual stream and move to root
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
if (onStartCallback != nullptr) onStartCallback();
};
/// Returns next (with positive index) or previous stream (with negative index)
virtual Stream* nextStream(int offset) override {
LOGD(LOG_METHOD);
TRACED();
return nextStreamCallback == nullptr ? nullptr : nextStreamCallback();
}
@ -143,7 +143,7 @@ class AudioSourceURL : public AudioSource {
public:
template<typename T, size_t N>
AudioSourceURL(AbstractURLStream& urlStream, T(&urlArray)[N], const char* mime, int startPos = 0) {
LOGD(LOG_METHOD);
TRACED();
this->actual_stream = &urlStream;
this->mime = mime;
this->urlArray = urlArray;
@ -154,7 +154,7 @@ public:
/// Setup Wifi URL
virtual void begin() override {
LOGD(LOG_METHOD);
TRACED();
this->pos = 0;
}
@ -225,7 +225,7 @@ public:
// only the ICYStream supports this
bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len), ID3TypeSelection sel=SELECT_ICY) {
LOGI(LOG_METHOD);
TRACEI();
return actual_stream->setMetadataCallback(fn);
}

View File

@ -22,8 +22,6 @@
namespace audio_tools {
static const char *UNDERFLOW_MSG = "data underflow";
/**
* @brief Base class for all Audio Streams. It support the boolean operator to
* test if the object is ready with data
@ -40,7 +38,7 @@ class AudioStream : public Stream, public AudioBaseInfoDependent, public AudioBa
// Call from subclass or overwrite to do something useful
virtual void setAudioInfo(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
this->info = info;
info.logInfo();
if (p_notify!=nullptr){
@ -105,7 +103,7 @@ class AudioStreamX : public AudioStream {
class AudioStreamWrapper : public AudioStream {
public:
AudioStreamWrapper(Stream& s) {
LOGD(LOG_METHOD);
TRACED();
p_stream = &s;
p_stream->setTimeout(clientTimeout);
}
@ -166,13 +164,13 @@ class MemoryStream : public AudioStream {
}
~MemoryStream() {
LOGD(LOG_METHOD);
TRACED();
if (memoryCanChange() && buffer!=nullptr) free(buffer);
}
// resets the read pointer
bool begin() override {
LOGD(LOG_METHOD);
TRACED();
write_pos = memoryCanChange() ? 0 : buffer_size;
if (this->buffer==nullptr){
resize(buffer_size);
@ -521,7 +519,7 @@ class GeneratedSoundStream : public AudioStreamX {
GeneratedSoundStream() = default;
GeneratedSoundStream(SoundGenerator<T> &generator) {
LOGD(LOG_METHOD);
TRACED();
setInput(generator);
}
@ -533,7 +531,7 @@ class GeneratedSoundStream : public AudioStreamX {
/// start the processing
bool begin() override {
LOGD(LOG_METHOD);
TRACED();
if (generator_ptr==nullptr){
LOGE("%s",source_not_defined_error);
return false;
@ -547,7 +545,7 @@ class GeneratedSoundStream : public AudioStreamX {
/// start the processing
bool begin(AudioBaseInfo cfg) {
LOGD(LOG_METHOD);
TRACED();
if (generator_ptr==nullptr){
LOGE("%s",source_not_defined_error);
return false;
@ -561,7 +559,7 @@ class GeneratedSoundStream : public AudioStreamX {
/// stop the processing
void end() override {
LOGD(LOG_METHOD);
TRACED();
generator_ptr->end();
active = false;
}
@ -608,12 +606,12 @@ class GeneratedSoundStream : public AudioStreamX {
class BufferedStream : public AudioStream {
public:
BufferedStream(size_t buffer_size) {
LOGD(LOG_METHOD);
TRACED();
buffer = new SingleBuffer<uint8_t>(buffer_size);
}
~BufferedStream() {
LOGD(LOG_METHOD);
TRACED();
if (buffer != nullptr) {
delete buffer;
}
@ -793,7 +791,7 @@ class RingBufferStream : public AudioStream {
*/
class ExternalBufferStream : public AudioStream {
public:
ExternalBufferStream() { LOGD(LOG_METHOD); }
ExternalBufferStream() { TRACED(); }
virtual int available() override { return buffer.available(); }
@ -846,14 +844,14 @@ class CallbackBufferedStream : public AudioStreamX {
/// Activates the output
virtual bool begin() {
LOGI(LOG_METHOD);
TRACEI();
active = true;
return true;
}
/// stops the processing
virtual void end() {
LOGI(LOG_METHOD);
TRACEI();
active = false;
};
@ -1019,7 +1017,7 @@ class VolumeStream : public AudioStreamX {
/// starts the processing
bool begin(VolumeStreamConfig cfg){
LOGD(LOG_METHOD);
TRACED();
info = cfg;
max_value = NumberConverter::maxValue(info.bits_per_sample);
if (info.channels>max_channels){
@ -1051,7 +1049,7 @@ class VolumeStream : public AudioStreamX {
/// Read raw PCM audio data, which will be the input for the volume control
virtual size_t readBytes(uint8_t *buffer, size_t length) override {
LOGD(LOG_METHOD);
TRACED();
if (buffer==nullptr || p_in==nullptr){
LOGE("NPE");
return 0;
@ -1063,7 +1061,7 @@ class VolumeStream : public AudioStreamX {
/// Writes raw PCM audio data, which will be the input for the volume control
virtual size_t write(const uint8_t *buffer, size_t size) override {
LOGD(LOG_METHOD);
TRACED();
if (buffer==nullptr || p_out==nullptr){
LOGE("NPE");
return 0;
@ -1084,7 +1082,7 @@ class VolumeStream : public AudioStreamX {
/// Detines the Audio info - The bits_per_sample are critical to work properly!
void setAudioInfo(AudioBaseInfo cfg) override {
LOGD(LOG_METHOD);
TRACED();
begin(cfg);
}
@ -1503,10 +1501,10 @@ class TimerCallbackAudioStream : public BufferedStream {
friend void IRAM_ATTR timerCallback(void *obj);
public:
TimerCallbackAudioStream() : BufferedStream(80) { LOGD(LOG_METHOD); }
TimerCallbackAudioStream() : BufferedStream(80) { TRACED(); }
~TimerCallbackAudioStream() {
LOGD(LOG_METHOD);
TRACED();
if (timer != nullptr) delete timer;
if (buffer != nullptr) delete buffer;
if (frame != nullptr) delete[] frame;
@ -1520,7 +1518,7 @@ class TimerCallbackAudioStream : public BufferedStream {
/// updates the audio information
virtual void setAudioInfo(AudioBaseInfo info) {
LOGD(LOG_METHOD);
TRACED();
if (cfg.sample_rate != info.sample_rate || cfg.channels != info.channels ||
cfg.bits_per_sample != info.bits_per_sample) {
bool do_restart = active;
@ -1561,7 +1559,7 @@ class TimerCallbackAudioStream : public BufferedStream {
/// Restart the processing
bool begin() {
LOGD(LOG_METHOD);
TRACED();
if (this->frameCallback != nullptr) {
if (cfg.use_timer) {
timer->begin(timerCallback, time, TimeUnit::US);
@ -1573,7 +1571,7 @@ class TimerCallbackAudioStream : public BufferedStream {
/// Stops the processing
void end() {
LOGD(LOG_METHOD);
TRACED();
if (cfg.use_timer) {
timer->end();
}
@ -1601,7 +1599,7 @@ class TimerCallbackAudioStream : public BufferedStream {
// used for audio sink
virtual size_t writeExt(const uint8_t *data, size_t len) override {
if (!active) return 0;
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
if (!cfg.use_timer) {
result = frameCallback((uint8_t *)data, len);
@ -1615,7 +1613,7 @@ class TimerCallbackAudioStream : public BufferedStream {
// used for audio source
virtual size_t readExt(uint8_t *data, size_t len) override {
if (!active) return 0;
LOGD(LOG_METHOD);
TRACED();
size_t result = 0;
if (!cfg.use_timer) {
@ -1683,7 +1681,6 @@ void TimerCallbackAudioStream::timerCallback(void *obj) {
}
if (src->buffer->writeArray(src->frame, available_bytes) !=
available_bytes) {
// LOGE(UNDERFLOW_MSG);
assert(false);
}
} else {
@ -1694,7 +1691,7 @@ void TimerCallbackAudioStream::timerCallback(void *obj) {
src->buffer->readArray(src->frame, src->frameSize);
if (available_bytes !=
src->frameCallback(src->frame, available_bytes)) {
LOGE(UNDERFLOW_MSG);
LOGE("data underflow");
}
}
}

View File

@ -427,7 +427,7 @@ class NBuffer : public BaseBuffer<T> {
// resets all buffers
void reset() {
LOGD(LOG_METHOD);
TRACED();
while (actual_read_buffer != nullptr) {
actual_read_buffer->reset();
addAvailableBuffer(actual_read_buffer);

View File

@ -410,7 +410,7 @@ class ResampleParameterEstimator {
int limit_max = limits[precision];
for (int j=0;j<limit_max;j++){
int tmp_div = div_array[j];
int tmp_fact = rintf(static_cast<float>(to_rate) * tmp_div / from_rate);
int tmp_fact = static_cast<float>(to_rate) * tmp_div / from_rate;
float tmp_diff = static_cast<float>(to_rate) - (static_cast<float>(from_rate) * tmp_fact / tmp_div);
LOGD("div: %d, fact %d -> diff: %f", tmp_div,tmp_fact,tmp_diff);
if (abs(tmp_diff)<abs(diff)){

View File

@ -96,7 +96,7 @@ class OversamplingDAC : public AudioPrint {
/// starts the Delta Sigma DAC
virtual bool begin(DACInfo cfg){
LOGD(LOG_METHOD);
TRACED();
// reset if already running
if (active){
@ -131,7 +131,7 @@ class OversamplingDAC : public AudioPrint {
/// Stops the output
virtual void end() {
LOGD(LOG_METHOD);
TRACED();
active = false;
reset();
timer_object.end();
@ -155,7 +155,7 @@ class OversamplingDAC : public AudioPrint {
/// Writes the audio data to the output buffer
virtual size_t write(const uint8_t *data, size_t size){
LOGD(LOG_METHOD);
TRACED();
if (size==0) return 0;
int16_t *ptr = (int16_t *)data;
@ -258,7 +258,7 @@ class SimpleDAC : public OversamplingDAC {
}
bool begin(DACInfo cfg) override {
LOGD(LOG_METHOD);
TRACED();
cfg.logInfo(true);
// default processing
return OversamplingDAC::begin(cfg);
@ -273,7 +273,7 @@ class SimpleDAC : public OversamplingDAC {
virtual void startTimer() {
LOGD(LOG_METHOD);
TRACED();
// start (optional) timer
if (outputRate()>0){
uint32_t timeUs = AudioUtils::toTimeUs(outputRate());
@ -349,7 +349,7 @@ class OversamplingDAC32 : public OversamplingDAC {
}
bool begin(DACInfo cfg) override {
LOGD(LOG_METHOD);
TRACED();
cfg.logInfo(true);
// default processing
return OversamplingDAC::begin(cfg);
@ -360,7 +360,7 @@ class OversamplingDAC32 : public OversamplingDAC {
}
virtual void startTimer() {
LOGD(LOG_METHOD);
TRACED();
// start (optional) timer
if (outputRate()>0){
uint32_t timeUs = AudioUtils::toTimeUs(outputRate());
@ -453,7 +453,7 @@ class SerialDAC : public OversamplingDAC32 {
}
bool begin(DACInfo info) override {
LOGD(LOG_METHOD);
TRACED();
info.logInfo(false);
this->cfg = &info;
// setup baud rate in the uart
@ -470,7 +470,7 @@ class SerialDAC : public OversamplingDAC32 {
/// just write the data to the UART w/o buffering
virtual size_t write(const uint8_t *data, size_t size) override {
LOGD(LOG_METHOD);
TRACED();
return serial->write(data, size);
}
@ -529,7 +529,7 @@ class DeltaSigmaDAC : public OversamplingDAC32 {
}
bool begin(DACInfo cfg) override {
LOGD(LOG_METHOD);
TRACED();
cfg.logInfo(true);
// default processing
return OversamplingDAC::begin(cfg);
@ -594,7 +594,7 @@ class PWMDAC : public OversamplingDAC {
}
virtual bool begin(DACInfo cfg) override {
LOGD(LOG_METHOD);
TRACED();
cfg.logInfo(true);
// default processing
bool result = OversamplingDAC::begin(cfg);
@ -628,7 +628,7 @@ class PWMDAC : public OversamplingDAC {
}
void setupPins() {
LOGD(LOG_METHOD);
TRACED();
LOGI("pmw_frequency: %u", pmw_frequency)
LOGI("max_pwm_value: %u", max_pwm_value)
for (int ch=0;ch<info.channels;ch++){
@ -648,7 +648,7 @@ class PWMDAC : public OversamplingDAC {
}
virtual void startTimer() override {
LOGD(LOG_METHOD);
TRACED();
// start (optional) timer
if (outputRate()>0){
uint32_t timeUs = AudioUtils::toTimeUs(outputRate());

View File

@ -44,7 +44,7 @@ class BitBangI2SBase {
*
*/
void end() {
LOGD(LOG_METHOD);
TRACED();
active = false;
}
@ -192,7 +192,7 @@ class BitBangI2SToCore : public BitBangI2SBase {
* @param cfg
*/
virtual bool begin(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
this->cfg = cfg;
cfg.logInfo();
if (i2sHandler==nullptr){
@ -255,7 +255,7 @@ class BitBangI2SToCore : public BitBangI2SBase {
/// Process output in endless loop
void runLoop() {
LOGD(LOG_METHOD);
TRACED();
while(active) {
int64_t end1 = micros()+bitTimeUs;
int64_t end2 = end1+bitTimeUs;
@ -288,7 +288,7 @@ class BitBangI2SWithInterrupts : public BitBangI2SBase {
}
bool begin(I2SConfig cfg) {
LOGD(LOG_METHOD);
TRACED();
cfg.logInfo();
if (i2sHandler==nullptr){
LOGE("The i2sHandler is null");

View File

@ -81,7 +81,7 @@ class RPDriver : public I2SDriver {
}
bool startCore(void(*runLoop)()) override {
LOGD(LOG_METHOD);
TRACED();
multicore_launch_core1(runLoop);
return true;
}
@ -141,7 +141,7 @@ class RP2040BitBangI2SWithInterrupts : public BitBangI2SWithInterrupts {
};
virtual bool begin(I2SConfig cfg) override {
LOGI(LOG_METHOD);
TRACEI();
// setup the reader
LOGI("The sample rate is %d hz", cfg.sample_rate);
// call begin in parent class
@ -149,7 +149,7 @@ class RP2040BitBangI2SWithInterrupts : public BitBangI2SWithInterrupts {
}
void end() {
LOGI(LOG_METHOD);
TRACEI();
BitBangI2SWithInterrupts::end();
pwm_set_enabled(slice_num, false);
gpio_set_irq_enabled_with_callback(cfg.pin_bck, GPIO_IRQ_EDGE_RISE, false, &gpio_callback);
@ -162,7 +162,7 @@ class RP2040BitBangI2SWithInterrupts : public BitBangI2SWithInterrupts {
// We use a 50% pwm signal to generate the output for the pin_bck
virtual void startClockOutSignal(unsigned long frequency) override {
LOGI(LOG_METHOD);
TRACEI();
slice_num = pwm_gpio_to_slice_num(cfg.pin_bck);
uint channel_num = pwm_gpio_to_channel(cfg.pin_bck);
int max_counter = 10;
@ -182,7 +182,7 @@ class RP2040BitBangI2SWithInterrupts : public BitBangI2SWithInterrupts {
}
virtual void startPinInterrupt() override {
LOGI(LOG_METHOD);
TRACEI();
if (cfg.is_master){
pwm_clear_irq(slice_num);
pwm_set_irq_enabled(slice_num, true);