|
3 | 3 | * |
4 | 4 | * Created on: Oct 26.2018 |
5 | 5 | * |
6 | | - * Version 2.0.5g |
7 | | - * Updated on: Aug 10.2022 |
| 6 | + * Version 2.0.5h |
| 7 | + * Updated on: Aug 11.2022 |
8 | 8 | * Author: Wolle (schreibfaul1) |
9 | 9 | * |
10 | 10 | */ |
@@ -1111,6 +1111,49 @@ bool Audio::latinToUTF8(char* buff, size_t bufflen){ |
1111 | 1111 | return true; |
1112 | 1112 | } |
1113 | 1113 | //--------------------------------------------------------------------------------------------------------------------- |
| 1114 | +size_t Audio::readAudioHeader(uint32_t bytes){ |
| 1115 | + size_t bytesReaded = 0; |
| 1116 | + if(m_codec == CODEC_WAV){ |
| 1117 | + int res = read_WAV_Header(InBuff.getReadPtr(), bytes); |
| 1118 | + if(res >= 0) bytesReaded = res; |
| 1119 | + else{ // error, skip header |
| 1120 | + m_controlCounter = 100; |
| 1121 | + } |
| 1122 | + } |
| 1123 | + if(m_codec == CODEC_MP3){ |
| 1124 | + int res = read_ID3_Header(InBuff.getReadPtr(), bytes); |
| 1125 | + if(res >= 0) bytesReaded = res; |
| 1126 | + else{ // error, skip header |
| 1127 | + m_controlCounter = 100; |
| 1128 | + } |
| 1129 | + } |
| 1130 | + if(m_codec == CODEC_M4A){ |
| 1131 | + int res = read_M4A_Header(InBuff.getReadPtr(), bytes); |
| 1132 | + if(res >= 0) bytesReaded = res; |
| 1133 | + else{ // error, skip header |
| 1134 | + m_controlCounter = 100; |
| 1135 | + } |
| 1136 | + } |
| 1137 | + if(m_codec == CODEC_AAC){ |
| 1138 | + // stream only, no header |
| 1139 | + m_audioDataSize = getFileSize(); |
| 1140 | + m_controlCounter = 100; |
| 1141 | + } |
| 1142 | + if(m_codec == CODEC_FLAC){ |
| 1143 | + int res = read_FLAC_Header(InBuff.getReadPtr(), bytes); |
| 1144 | + if(res >= 0) bytesReaded = res; |
| 1145 | + else{ // error, skip header |
| 1146 | + stopSong(); |
| 1147 | + m_controlCounter = 100; |
| 1148 | + } |
| 1149 | + } |
| 1150 | + if(!isRunning()){ |
| 1151 | + log_e("Processing stopped due to invalid audio header"); |
| 1152 | + return 0; |
| 1153 | + } |
| 1154 | + return bytesReaded; |
| 1155 | +} |
| 1156 | +//--------------------------------------------------------------------------------------------------------------------- |
1114 | 1157 | int Audio::read_WAV_Header(uint8_t* data, size_t len) { |
1115 | 1158 | static size_t headerSize; |
1116 | 1159 | static uint32_t cs = 0; |
@@ -2805,7 +2848,6 @@ bool Audio::STfromEXTINF(char* str){ |
2805 | 2848 | void Audio::processLocalFile() { |
2806 | 2849 |
|
2807 | 2850 | if(!(audiofile && m_f_running && getDatamode() == AUDIO_LOCALFILE)) return; |
2808 | | - |
2809 | 2851 | int bytesDecoded = 0; |
2810 | 2852 | uint32_t bytesCanBeWritten = 0; |
2811 | 2853 | uint32_t bytesCanBeRead = 0; |
@@ -2853,45 +2895,7 @@ void Audio::processLocalFile() { |
2853 | 2895 | if(bytesCanBeRead == InBuff.getMaxBlockSize()) { // mp3 or aac frame complete? |
2854 | 2896 |
|
2855 | 2897 | if(m_controlCounter != 100){ |
2856 | | - if(m_codec == CODEC_WAV){ |
2857 | | - int res = read_WAV_Header(InBuff.getReadPtr(), bytesCanBeRead); |
2858 | | - if(res >= 0) bytesDecoded = res; |
2859 | | - else{ // error, skip header |
2860 | | - m_controlCounter = 100; |
2861 | | - } |
2862 | | - } |
2863 | | - if(m_codec == CODEC_MP3){ |
2864 | | - int res = read_ID3_Header(InBuff.getReadPtr(), bytesCanBeRead); |
2865 | | - if(res >= 0) bytesDecoded = res; |
2866 | | - else{ // error, skip header |
2867 | | - m_controlCounter = 100; |
2868 | | - } |
2869 | | - } |
2870 | | - if(m_codec == CODEC_M4A){ |
2871 | | - int res = read_M4A_Header(InBuff.getReadPtr(), bytesCanBeRead); |
2872 | | - if(res >= 0) bytesDecoded = res; |
2873 | | - else{ // error, skip header |
2874 | | - m_controlCounter = 100; |
2875 | | - } |
2876 | | - } |
2877 | | - if(m_codec == CODEC_AAC){ |
2878 | | - // stream only, no header |
2879 | | - m_audioDataSize = getFileSize(); |
2880 | | - m_controlCounter = 100; |
2881 | | - } |
2882 | | - |
2883 | | - if(m_codec == CODEC_FLAC){ |
2884 | | - int res = read_FLAC_Header(InBuff.getReadPtr(), bytesCanBeRead); |
2885 | | - if(res >= 0) bytesDecoded = res; |
2886 | | - else{ // error, skip header |
2887 | | - stopSong(); |
2888 | | - m_controlCounter = 100; |
2889 | | - } |
2890 | | - } |
2891 | | - if(!isRunning()){ |
2892 | | - log_e("Processing stopped due to invalid audio header"); |
2893 | | - return; |
2894 | | - } |
| 2898 | + bytesDecoded = readAudioHeader(bytesCanBeRead); |
2895 | 2899 | } |
2896 | 2900 | else { |
2897 | 2901 | bytesDecoded = sendBytes(InBuff.getReadPtr(), bytesCanBeRead); |
@@ -3729,7 +3733,7 @@ bool Audio:: initializeDecoder(){ |
3729 | 3733 | InBuff.changeMaxBlockSize(m_frameSizeWav); |
3730 | 3734 | break; |
3731 | 3735 | case CODEC_OGG: |
3732 | | - m_codec = CODEC_OGG; |
| 3736 | + m_codec = CODEC_OGG; log_e("!"); |
3733 | 3737 | AUDIO_INFO("ogg not supported"); |
3734 | 3738 | goto exit; |
3735 | 3739 | break; |
@@ -4063,13 +4067,12 @@ int Audio::sendBytes(uint8_t* data, size_t len) { |
4063 | 4067 | bytesLeft = len; |
4064 | 4068 | int ret = 0; |
4065 | 4069 | int bytesDecoded = 0; |
4066 | | - if(m_codec == CODEC_WAV){ //copy len data in outbuff and set validsamples and bytesdecoded=len |
4067 | | - memmove(m_outBuff, data , len); |
4068 | | - if(getBitsPerSample() == 16) m_validSamples = len / (2 * getChannels()); |
4069 | | - if(getBitsPerSample() == 8 ) m_validSamples = len / 2; |
4070 | | - bytesLeft = 0; |
4071 | | - } |
| 4070 | + |
4072 | 4071 | switch(m_codec){ |
| 4072 | + case CODEC_WAV: memmove(m_outBuff, data , len); //copy len data in outbuff and set validsamples and bytesdecoded=len |
| 4073 | + if(getBitsPerSample() == 16) m_validSamples = len / (2 * getChannels()); |
| 4074 | + if(getBitsPerSample() == 8 ) m_validSamples = len / 2; |
| 4075 | + bytesLeft = 0; break; |
4073 | 4076 | case CODEC_MP3: ret = MP3Decode(data, &bytesLeft, m_outBuff, 0); break; |
4074 | 4077 | case CODEC_AAC: ret = AACDecode(data, &bytesLeft, m_outBuff); break; |
4075 | 4078 | case CODEC_M4A: ret = AACDecode(data, &bytesLeft, m_outBuff); break; |
|
0 commit comments