Skip to content

Commit 13a869d

Browse files
committed
Metadata Selection
1 parent dc790de commit 13a869d

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

src/AudioDevices/ESP32AudioKit/AudioKit.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class AudioKitStream : public AudioStream {
383383
* @return true
384384
* @return false
385385
*/
386-
virtual bool begin() { begin(defaultConfig()); }
386+
virtual bool begin() { return begin(defaultConfig()); }
387387

388388
/**
389389
* @brief Starts the processing
@@ -394,6 +394,7 @@ class AudioKitStream : public AudioStream {
394394
*/
395395
virtual bool begin(ConfigES8388 cfg) {
396396
LOGI(LOG_METHOD);
397+
bool result = true;
397398
this->cfg = cfg;
398399
bool isDac = cfg.rx_tx_mode == TX_MODE;
399400
bool isAdc = cfg.rx_tx_mode == RX_MODE;
@@ -411,23 +412,29 @@ class AudioKitStream : public AudioStream {
411412
}
412413

413414
if (!initES8388(!cfg.is_master, isDac, isAdc)) {
415+
result = false;
414416
LOGE("Error: initES8388 failed");
415417
}
416418
if (!configClock(cfg.clock_config)) {
419+
result = false;
417420
LOGE("Error: configClock failed");
418421
}
419422
if (!setBitsPerSample(module_value, cfg.bits_per_sample)) {
423+
result = false;
420424
LOGE("Error: setBitsPerSample failed");
421425
}
422426
if (!setFormat(module_value, cfg.i2s_format)) {
427+
result = false;
423428
LOGE("Error: setFormat failed");
424429
}
425430
if (cfg.rx_tx_mode == RX_MODE) {
426431
if (!configAdcInput(cfg.input_device)) {
432+
result = false;
427433
LOGE("Error: configAdcInput failed");
428434
}
429435
} else {
430436
if (!configDacOutput(cfg.output_device)) {
437+
result = false;
431438
LOGE("Error: configDacOutput failed");
432439
}
433440
}
@@ -438,6 +445,7 @@ class AudioKitStream : public AudioStream {
438445
// set initial volume
439446
actionVolume = cfg.default_volume;
440447
if (!setVoiceVolume(actionVolume)) {
448+
result = false;
441449
LOGE("setVoiceVolume failed");
442450
}
443451

@@ -451,7 +459,9 @@ class AudioKitStream : public AudioStream {
451459
// start module
452460
if (!start(module_value)) {
453461
LOGE("start failed");
462+
result = false;
454463
}
464+
return result;
455465
}
456466

457467
/**
@@ -616,7 +626,7 @@ class AudioKitStream : public AudioStream {
616626
* @return true
617627
* @return false
618628
*/
619-
bool incrementVoiceVolume(int inc) {
629+
void incrementVoiceVolume(int inc) {
620630
actionVolume += inc;
621631
setVoiceVolume(actionVolume);
622632
}
@@ -1131,6 +1141,7 @@ class AudioKitStream : public AudioStream {
11311141
case I2S_PCM_SHORT:
11321142
return setFormat(module, ES_I2S_DSP);
11331143
}
1144+
return false;
11341145
}
11351146
/**
11361147
* @brief Configure ES8388 I2S format

src/AudioMetaData/AbstractMetaData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace audio_tools {
66

7+
enum ID3TypeSelection { SELECT_ID3V1=0b001, SELECT_ID3V2=0b010, SELECT_ID3=0b011, SELECT_ICY=0b100, SELECT_ANY=0b111 };
8+
79
/// Type of meta info
810
enum MetaDataType { Title, Artist, Album, Genre, Name, Description };
911

src/AudioMetaData/MetaDataID3.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ class MetaDataID3V2 : public MetaDataID3Base {
365365
return frame_header;
366366
}
367367

368+
/// returns true if the tag has been provided
369+
bool isProcessed() {
370+
return tag_processed;
371+
}
372+
368373
protected:
369374
ID3v2 tagv2;
370375
bool tag_active = false;
@@ -511,7 +516,6 @@ class MetaDataID3V2 : public MetaDataID3Base {
511516

512517
};
513518

514-
515519
/**
516520
* @brief Simple ID3 Meta Data Parser which supports ID3 V1 and V2 and implements the Stream interface. You just need to set the callback(s) to receive the result
517521
* and copy the audio data to this stream.
@@ -533,6 +537,10 @@ class MetaDataID3 : public AbstractMetaData {
533537
id3v2.setCallback(fn);
534538
}
535539

540+
void setFilter(ID3TypeSelection sel) {
541+
this->filter = sel;
542+
}
543+
536544
void begin() {
537545
LOGI(LOG_METHOD);
538546
id3v1.begin();
@@ -548,15 +556,17 @@ class MetaDataID3 : public AbstractMetaData {
548556
/// Provide tha audio data to the API to parse for Meta Data
549557
virtual size_t write(const uint8_t *data, size_t length){
550558
LOGD(LOG_METHOD);
551-
id3v1.write(data, length);
552-
id3v2.write(data, length);
559+
if (filter & SELECT_ID3V2) id3v2.write(data, length);
560+
if (!id3v2.isProcessed()) {
561+
if (filter & SELECT_ID3V1) id3v1.write(data, length);
562+
}
553563
return length;
554564
}
555565

556-
557566
protected:
558567
MetaDataID3V1 id3v1;
559568
MetaDataID3V2 id3v2;
569+
int filter = SELECT_ID3;
560570
};
561571

562572
} // namespace

src/AudioTools/AudioPlayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace audio_tools {
8181
virtual bool isAutoNext();
8282

8383
// only the ICYStream supports this
84-
virtual bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len)) {
84+
virtual bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len), ID3TypeSelection sel=SELECT_ICY) {
8585
return false;
8686
}
8787

@@ -464,7 +464,7 @@ namespace audio_tools {
464464
};
465465

466466
// only the ICYStream supports this
467-
bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len)) {
467+
bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len), ID3TypeSelection sel=SELECT_ICY) {
468468
LOGI(LOG_METHOD);
469469
return actual_stream->setMetadataCallback(fn);
470470
}
@@ -773,7 +773,7 @@ namespace audio_tools {
773773
}
774774

775775
/// Defines the medatadata callback
776-
virtual void setMetadataCallback(void (*callback)(MetaDataType type, const char* str, int len)) {
776+
virtual void setMetadataCallback(void (*callback)(MetaDataType type, const char* str, int len), ID3TypeSelection sel=SELECT_ID3) {
777777
LOGI(LOG_METHOD);
778778
// setup metadata.
779779
if (p_source->setMetadataCallback(callback)){
@@ -783,6 +783,7 @@ namespace audio_tools {
783783
} else {
784784
// metadata is handled here
785785
meta_out.setCallback(callback);
786+
meta_out.setFilter(sel);
786787
meta_active = true;
787788
}
788789
}

0 commit comments

Comments
 (0)