MCPcopy Create free account
hub / github.com/FastLED/FastLED / decodeOggToPcm

Function decodeOggToPcm

tests/fl/audio/detector/vocal_real_audio.hpp:77–108  ·  view source on GitHub ↗

--- Utility: Decode OGG to flat PCM i16 vector ---

Source from the content-addressed store, hash-verified

75
76// --- Utility: Decode OGG to flat PCM i16 vector ---
77static fl::vector<fl::i16> decodeOggToPcm(const char* path, fl::u32* outSampleRate = nullptr) {
78 fl::vector<fl::u8> oggData = loadOggFile(path);
79 if (oggData.empty()) {
80 return fl::vector<fl::i16>();
81 }
82
83 // Parse info for sample rate
84 fl::string error;
85 VorbisInfo info = Vorbis::parseVorbisInfo(oggData, &error);
86 if (!info.isValid) {
87 return fl::vector<fl::i16>();
88 }
89 if (outSampleRate) {
90 *outSampleRate = info.sampleRate;
91 }
92
93 // Decode all samples
94 fl::vector<audio::Sample> samples = Vorbis::decodeAll(oggData, &error);
95 if (samples.empty()) {
96 return fl::vector<fl::i16>();
97 }
98
99 // Concatenate all PCM frames
100 fl::vector<fl::i16> pcm;
101 for (const auto& sample : samples) {
102 const auto& data = sample.pcm();
103 for (fl::size i = 0; i < data.size(); ++i) {
104 pcm.push_back(data[i]);
105 }
106 }
107 return pcm;
108}
109
110// --- Utility: Mix two PCM streams ---
111static fl::vector<fl::i16> mixPcm(fl::span<const fl::i16> a, fl::span<const fl::i16> b,

Callers 1

Calls 4

loadOggFileFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected