MCPcopy Create free account
hub / github.com/DamRsn/NeuralNote / _loadMP3File

Function _loadMP3File

Lib/Utils/AudioUtils.cpp:95–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95bool _loadMP3File(const std::string& filename, juce::AudioBuffer<float>& outBuffer, double& outSampleRate)
96{
97 mp3dec_t mp3d;
98 mp3dec_file_info_t info;
99 int loadResult = mp3dec_load(&mp3d, filename.c_str(), &info, nullptr, nullptr);
100
101 if (loadResult) {
102 return false;
103 }
104
105 outBuffer.setSize(info.channels, static_cast<int>(info.samples / info.channels));
106
107 for (size_t i = 0; i < info.samples; ++i) {
108 size_t channel = i % info.channels;
109 outBuffer.setSample((int) channel, static_cast<int>(i / info.channels), (float) info.buffer[i] / 32768.0f);
110 }
111
112 outSampleRate = static_cast<double>(info.hz);
113 free(info.buffer);
114 return true;
115}
116
117} // namespace AudioUtils

Callers 1

loadAudioFileFunction · 0.85

Calls 1

mp3dec_loadFunction · 0.85

Tested by

no test coverage detected