FastLED 3.9.15
Loading...
Searching...
No Matches

◆ audioDecodeCallback()

void fl::third_party::SoftwareMpeg1Decoder::audioDecodeCallback ( fl::third_party::plm_t * plm,
fl::third_party::plm_samples_t * samples,
void * user )
static

Definition at line 112 of file software_decoder.cpp.hpp.

112 {
113 FL_UNUSED(plm_ptr);
114 auto* decoder = static_cast<SoftwareMpeg1Decoder*>(user);
115
116 if (!decoder || !samples || !decoder->config_.audioCallback) {
117 return;
118 }
119
120 // Convert float samples to i16 PCM
121 // pl_mpeg provides interleaved stereo samples as floats in range [-1.0, 1.0]
122 fl::vector<fl::i16> pcm;
123 pcm.reserve(samples->count * 2); // stereo
124
125 for (unsigned i = 0; i < samples->count * 2; i++) {
126 float sample = samples->interleaved[i];
127 // Clamp and convert to i16 range
128 sample = sample < -1.0f ? -1.0f : (sample > 1.0f ? 1.0f : sample);
129 pcm.push_back(static_cast<fl::i16>(sample * 32767.0f));
130 }
131
132 // Create audio::Sample with timestamp in milliseconds
133 fl::u32 timestampMs = static_cast<fl::u32>(samples->time * 1000.0);
134 audio::Sample audioSample(fl::span<const fl::i16>(pcm.data(), pcm.size()), timestampMs);
135
136 // Call the user's audio callback
137 decoder->config_.audioCallback(audioSample);
138}
SoftwareMpeg1Decoder(const Mpeg1Config &config) FL_NOEXCEPT
fl::size size() const FL_NOEXCEPT
T * data() FL_NOEXCEPT
Definition vector.h:619
void reserve(fl::size n) FL_NOEXCEPT
Definition vector.h:591
void push_back(const T &value) FL_NOEXCEPT
Definition vector.h:624
float interleaved[PLM_AUDIO_SAMPLES_PER_FRAME *2]
Definition pl_mpeg.h:232
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.
Definition sample.cpp.hpp:9
#define FL_UNUSED(x)

References SoftwareMpeg1Decoder(), fl::vector< T >::data(), FL_NOEXCEPT, FL_UNUSED, fl::vector< T >::push_back(), fl::vector< T >::reserve(), fl::sample(), and fl::vector_basic::size().

Referenced by initializeDecoder(), and setAudioCallback().

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