From 2d1357d277fe7172c20eaa17261e932425028588 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Mon, 12 Aug 2019 06:20:38 +0200 Subject: [PATCH] Skip ID3 tags. They can get quite large... --- include/player.h | 1 + src/player.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/player.h b/include/player.h index f4993b9..2d7a612 100644 --- a/include/player.h +++ b/include/player.h @@ -52,6 +52,7 @@ private: void _set_last_track(const char* album, uint8_t track, uint32_t position); std::map _last_tracks; void _play_file(String filename, uint32_t offset); + uint32_t _id3_tag_offset(File f); void _finish_playing(); void _finish_stopping(); void _mute(); diff --git a/src/player.cpp b/src/player.cpp index 13dcad2..107539d 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -334,13 +334,40 @@ void Player::_play_file(String file, uint32_t file_offset) { _write_control_register(SCI_STATUS, _read_control_register(SCI_STATUS) & ~SS_DO_NOT_JUMP); delay(100); + if (file_offset == 0) { + _file.seek(_id3_tag_offset(_file)); + } _refills = 0; - _current_play_position = 0; + _current_play_position = _file.position(); _skip_to = file_offset; if (_skip_to>0) _mute(); INFO("Now playing.\n"); } +uint32_t Player::_id3_tag_offset(File f) { + uint32_t original_position = f.position(); + uint32_t offset = 0; + if (f.read()=='I' && f.read()=='D' && f.read()=='3') { + DEBUG("ID3 tag found\n"); + // Skip ID3 tag version + f.read(); f.read(); + byte tags = f.read(); + bool footer_present = tags & 0x10; + DEBUG("ID3 footer found: %d\n", footer_present); + for (byte i=0; i<4; i++) { + offset <<= 7; + offset |= (0x7F & f.read()); + } + offset += 10; + if (footer_present) offset += 10; + DEBUG("ID3 tag length is %d bytes.\n", offset); + } else { + DEBUG("No ID3 tag found\n"); + } + f.seek(original_position); + return offset; +} + void Player::_flush(uint count, int8_t byte) { SPIMaster::enable(XDCS); SPI.beginTransaction(*_spi_settings);