105 for (
int i = 0; i < frame.
samples; i++) {
106 fl::i32 left = frame.
pcm[i * 2];
107 fl::i32 right = frame.
pcm[i * 2 + 1];
108 fl::i32 avg = (left + right) / 2;
109 mono_pcm.
push_back(
static_cast<fl::i16
>(avg));
179 mErrorMsg =
"Failed to initialize MP3 decoder";
229 for (fl::size i = 0; i < remaining; i++) {
244 return bytesRead > 0;
259 if (bytes_left == 0) {
276 const fl::u8* decode_ptr = inptr;
277 fl::size decode_bytes = bytes_left;
282 fl::size consumed = (decode_ptr - inptr);
304 mInfo.isValid =
true;
313 for (
int i = 0; i < frame.
samples; i++) {
314 fl::i32 left = frame.
pcm[i * 2];
315 fl::i32 right = frame.
pcm[i * 2 + 1];
316 fl::i32 avg = (left + right) / 2;
317 mono_pcm.
push_back(
static_cast<fl::i16
>(avg));
368 return mImpl->begin(stream);
376 return mImpl->isReady();
380 return mImpl->hasError(msg);
384 return mImpl->decodeNextFrame(out_sample);
388 return mImpl->getPosition();
396 return mImpl->getInfo();
416 *error_message =
"Empty MP3 data";
422 if (data.
size() < 128) {
424 *error_message =
"MP3 data too small";
430 bool foundSync =
false;
431 fl::size syncOffset = 0;
433 for (fl::size i = 0; i <= data.
size() - 4; i++) {
434 if (data[i] == 0xFF && (data[i + 1] & 0xE0) == 0xE0) {
443 *error_message =
"Invalid MP3 stream - no sync word found";
450 if (!decoder.
init()) {
452 *error_message =
"Failed to initialize MP3 decoder";
457 const fl::u8* inptr = data.
data() + syncOffset;
458 fl::size bytes_left = data.
size() - syncOffset;
475 }
else if (error_message) {
476 *error_message =
"Failed to decode MP3 frame header";
478 }
else if (error_message) {
479 *error_message =
"Failed to find MP3 sync word";
static Mp3Info parseMp3Info(fl::span< const fl::u8 > data, fl::string *error_message=nullptr)
static bool isSupported()
static Mp3DecoderPtr createDecoder(fl::string *error_message=nullptr)
bool begin(fl::filebuf_ptr stream)
bool hasError(fl::string *msg=nullptr) const
~Mp3Decoder() FL_NOEXCEPT
bool decodeNextFrame(audio::Sample *out_sample)
fl::size getPosition() const
fl::unique_ptr< fl::third_party::Mp3StreamDecoderImpl > mImpl
constexpr bool empty() const FL_NOEXCEPT
const T * data() const FL_NOEXCEPT
constexpr fl::size size() const FL_NOEXCEPT
int decodeFrame(const fl::u8 **inbuf, fl::size *bytes_left)
int findSyncWord(const fl::u8 *buf, fl::size len)
Mp3HelixDecoder() FL_NOEXCEPT
~Mp3HelixDecoder() FL_NOEXCEPT
fl::unique_ptr< fl::i16[]> mPcmBuffer
int decode(const fl::u8 *data, fl::size len, Fn on_frame)
fl::vector< audio::Sample > decodeToAudioSamples(const fl::u8 *data, fl::size len)
bool begin(fl::filebuf_ptr stream)
bool findAndDecodeFrame(audio::Sample *out_sample)
Mp3StreamDecoderImpl() FL_NOEXCEPT
bool mHasDecodedFirstFrame
static constexpr fl::size BUFFER_SIZE
fl::size getPosition() const
fl::unique_ptr< Mp3HelixDecoder > mDecoder
fl::vector< fl::u8 > mBuffer
~Mp3StreamDecoderImpl() FL_NOEXCEPT
bool hasError(fl::string *msg=nullptr) const
bool decodeNextFrame(audio::Sample *out_sample)
void reserve(fl::size n) FL_NOEXCEPT
void push_back(const T &value) FL_NOEXCEPT
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
struct _MP3FrameInfo MP3FrameInfo
int MP3FindSyncWord(const unsigned char *buf, int nBytes) FL_NOEXCEPT
void MP3FreeDecoder(HMP3Decoder hMP3Decoder) FL_NOEXCEPT
HMP3Decoder MP3InitDecoder(void) FL_NOEXCEPT
int MP3Decode(HMP3Decoder hMP3Decoder, const unsigned char **inbuf, size_t *bytesLeft, short *outbuf, int useSize) FL_NOEXCEPT
void MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo) FL_NOEXCEPT
constexpr fl::size MAX_PCM_SAMPLES
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NOEXCEPT
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode)
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
fl::shared_ptr< filebuf > filebuf_ptr
fl::shared_ptr< Mp3Decoder > Mp3DecoderPtr
To bit_cast(const From &from) FL_NOEXCEPT
Base definition for an LED controller.