FastLED 3.10.6
Loading...
Searching...
No Matches

◆ decodeFrame()

int fl::third_party::Mp3Minimp3Decoder::decodeFrame ( const fl::u8 ** inbuf,
fl::size * bytes_left )

Definition at line 197 of file mp3.cpp.hpp.

198 {
199 if (!mDecoder || !mScratch || !mPcmBuffer || !inbuf || !bytes_left ||
200 !*inbuf || *bytes_left == 0) {
201 return -1;
202 }
203
204 const fl::u8* input = *inbuf;
205 const fl::size max_input = 0x7fffffff;
206 const int input_bytes = static_cast<int>(
207 *bytes_left > max_input ? max_input : *bytes_left);
208 mp3dec_frame_info_t info = {};
209 const int samples = mp3dec_decode_frame_r(
210 mDecoder.get(), mScratch.get(), input, input_bytes, mPcmBuffer.get(),
211 &info);
212 if (samples <= 0 || info.frame_bytes <= 0 ||
213 static_cast<fl::size>(info.frame_bytes) > *bytes_left) {
214 return -1;
215 }
216
217 const fl::u8* header = input + info.frame_offset;
218 *inbuf += info.frame_bytes;
219 *bytes_left -= static_cast<fl::size>(info.frame_bytes);
220
221 int frame_bytes = info.frame_bytes - info.frame_offset;
222 if (frame_bytes > 0 && (header[2] & 0x02) != 0) {
223 --frame_bytes;
224 }
225 mFrameInfo.bitrate = info.bitrate_kbps * 1000;
226 if (mFrameInfo.bitrate == 0 && samples > 0 && frame_bytes > 0) {
227 mFrameInfo.bitrate =
228 (frame_bytes * info.hz * 8) / samples;
229 }
230 mFrameInfo.nChans = info.channels;
231 mFrameInfo.samprate = info.hz;
232 mFrameInfo.bitsPerSample = 16;
233 mFrameInfo.outputSamps = samples * info.channels;
234 mFrameInfo.layer = info.layer;
235 mFrameInfo.version = minimp3Version(header);
236 return 0;
237}
fl::unique_ptr< mp3dec_t, Mp3MemoryDeleter< mp3dec_t > > mDecoder
Definition mp3.h:128
fl::unique_ptr< mp3dec_scratch_t, Mp3MemoryDeleter< mp3dec_scratch_t > > mScratch
Definition mp3.h:130
fl::unique_ptr< fl::i16[], Mp3MemoryDeleter< fl::i16 > > mPcmBuffer
Definition mp3.h:124
int mp3dec_decode_frame_r(mp3dec_t *dec, mp3dec_scratch_t *scratch, const uint8_t *mp3, int mp3_bytes, mp3d_sample_t *pcm, mp3dec_frame_info_t *info) FL_NO_EXCEPT
int minimp3Version(const fl::u8 *header) FL_NO_EXCEPT
Definition mp3.cpp.hpp:119
unsigned char u8
Definition stdint.h:131

References mp3dec_frame_info_t::bitrate_kbps, mp3dec_frame_info_t::channels, fl::FL_NO_EXCEPT, mp3dec_frame_info_t::frame_bytes, mp3dec_frame_info_t::frame_offset, mp3dec_frame_info_t::hz, mp3dec_frame_info_t::layer, mDecoder, mFrameInfo, mp3dec_decode_frame_r(), mPcmBuffer, and mScratch.

Referenced by decode(), and fl::Mp3::parseMp3Info().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: