@@ -1379,12 +1379,18 @@ int Audio::read_FLAC_Header(uint8_t *data, size_t len) {
13791379 }
13801380 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13811381 if (m_controlCounter == FLAC_MAGIC) { /* check MAGIC STRING */
1382+ if (specialIndexOf (data, " OggS" , 10 ) == 0 ) { // is ogg
1383+ headerSize = 0 ;
1384+ retvalue = 0 ;
1385+ m_controlCounter = FLAC_OKAY;
1386+ return 0 ;
1387+ }
13821388 if (specialIndexOf (data, " fLaC" , 10 ) != 0 ) {
13831389 log_e (" Magic String 'fLaC' not found in header" );
13841390 stopSong ();
13851391 return -1 ;
13861392 }
1387- m_controlCounter = FLAC_MBH;
1393+ m_controlCounter = FLAC_MBH; // METADATA_BLOCK_HEADER
13881394 headerSize = 4 ;
13891395 retvalue = 4 ;
13901396 return 0 ;
@@ -3836,6 +3842,34 @@ int Audio::findNextSync(uint8_t* data, size_t len){
38363842 return nextSync;
38373843}
38383844// ---------------------------------------------------------------------------------------------------------------------
3845+ void Audio::setDecoderItems (){
3846+ if (m_codec == CODEC_MP3){
3847+ setChannels (MP3GetChannels ());
3848+ setSampleRate (MP3GetSampRate ());
3849+ setBitsPerSample (MP3GetBitsPerSample ());
3850+ setBitrate (MP3GetBitrate ());
3851+ }
3852+ if (m_codec == CODEC_AAC || m_codec == CODEC_M4A){
3853+ setChannels (AACGetChannels ());
3854+ setSampleRate (AACGetSampRate ());
3855+ setBitsPerSample (AACGetBitsPerSample ());
3856+ setBitrate (AACGetBitrate ());
3857+ }
3858+ if (m_codec == CODEC_FLAC){
3859+ setChannels (FLACGetChannels ());
3860+ setSampleRate (FLACGetSampRate ());
3861+ setBitsPerSample (FLACGetBitsPerSample ());
3862+ setBitrate (FLACGetBitRate ());
3863+ }
3864+ if (m_codec == CODEC_OPUS){
3865+ setChannels (OPUSGetChannels ());
3866+ setSampleRate (OPUSGetSampRate ());
3867+ setBitsPerSample (OPUSGetBitsPerSample ());
3868+ setBitrate (OPUSGetBitRate ());
3869+ }
3870+ showCodecParams ();
3871+ }
3872+ // ---------------------------------------------------------------------------------------------------------------------
38393873int Audio::sendBytes (uint8_t * data, size_t len) {
38403874 int bytesLeft;
38413875 static bool f_setDecodeParamsOnce = true ;
@@ -3889,37 +3923,6 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
38893923 return bytesDecoded;
38903924 }
38913925 else { // ret>=0
3892- if (f_setDecodeParamsOnce){
3893- f_setDecodeParamsOnce = false ;
3894- m_PlayingStartTime = millis ();
3895-
3896- if (m_codec == CODEC_MP3){
3897- setChannels (MP3GetChannels ());
3898- setSampleRate (MP3GetSampRate ());
3899- setBitsPerSample (MP3GetBitsPerSample ());
3900- setBitrate (MP3GetBitrate ());
3901- }
3902- if (m_codec == CODEC_AAC || m_codec == CODEC_M4A){
3903- setChannels (AACGetChannels ());
3904- setSampleRate (AACGetSampRate ());
3905- setBitsPerSample (AACGetBitsPerSample ());
3906- setBitrate (AACGetBitrate ());
3907- }
3908- if (m_codec == CODEC_FLAC){
3909- setChannels (FLACGetChannels ());
3910- setSampleRate (FLACGetSampRate ());
3911- setBitsPerSample (FLACGetBitsPerSample ());
3912- setBitrate (FLACGetBitRate ());
3913- }
3914- if (m_codec == CODEC_OPUS){
3915- setChannels (OPUSGetChannels ());
3916- setSampleRate (OPUSGetSampRate ());
3917- setBitsPerSample (OPUSGetBitsPerSample ());
3918- setBitrate (OPUSGetBitRate ());
3919- }
3920-
3921- showCodecParams ();
3922- }
39233926 if (m_codec == CODEC_MP3){
39243927 m_validSamples = MP3GetOutputSamps () / getChannels ();
39253928 }
@@ -3946,6 +3949,11 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
39463949 if (audio_showstreamtitle) audio_showstreamtitle (st);
39473950 }
39483951 }
3952+ if (f_setDecodeParamsOnce){
3953+ f_setDecodeParamsOnce = false ;
3954+ setDecoderItems ();
3955+ m_PlayingStartTime = millis ();
3956+ }
39493957 }
39503958 compute_audioCurrentTime (bytesDecoded);
39513959
@@ -4156,6 +4164,7 @@ uint32_t Audio::getAudioCurrentTime() { // return current time in seconds
41564164}
41574165// ---------------------------------------------------------------------------------------------------------------------
41584166bool Audio::setAudioPlayPosition (uint16_t sec){
4167+ if (m_codec == CODEC_OPUS) return false ; // not impl. yet
41594168 // Jump to an absolute position in time within an audio file
41604169 // e.g. setAudioPlayPosition(300) sets the pointer at pos 5 min
41614170 if (sec > getAudioFileDuration ()) sec = getAudioFileDuration ();
@@ -4185,6 +4194,7 @@ uint32_t Audio::getTotalPlayingTime() {
41854194}
41864195// ---------------------------------------------------------------------------------------------------------------------
41874196bool Audio::setTimeOffset (int sec){
4197+ if (m_codec == CODEC_OPUS) return false ; // not impl. yet
41884198 // fast forward or rewind the current position in seconds
41894199 // audiosource must be a mp3, aac or wav file
41904200
@@ -4207,6 +4217,7 @@ bool Audio::setTimeOffset(int sec){
42074217}
42084218// ---------------------------------------------------------------------------------------------------------------------
42094219bool Audio::setFilePos (uint32_t pos) {
4220+ if (m_codec == CODEC_OPUS) return false ; // not impl. yet
42104221 xSemaphoreTakeRecursive (mutex_audio, portMAX_DELAY);
42114222 if (!audiofile) return false ;
42124223 if (pos < m_audioDataStart) pos = m_audioDataStart; // issue #96
0 commit comments