--- Utility: Decode OGG to flat PCM i16 vector ---
| 75 | |
| 76 | // --- Utility: Decode OGG to flat PCM i16 vector --- |
| 77 | static 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 --- |
| 111 | static fl::vector<fl::i16> mixPcm(fl::span<const fl::i16> a, fl::span<const fl::i16> b, |
no test coverage detected