| 93 | } |
| 94 | |
| 95 | bool _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 |
no test coverage detected