---------------------------------------------------------------------------
| 78 | |
| 79 | // --------------------------------------------------------------------------- |
| 80 | bool AudioReader::load_audio(const std::string& filename, |
| 81 | audio_data_t& out_audio, |
| 82 | int target_sample_rate, |
| 83 | MonoDownmixMode downmix) |
| 84 | { |
| 85 | init_ffmpeg_once(); |
| 86 | |
| 87 | if (!std::filesystem::exists(filename)) { |
| 88 | std::cerr << "Error: audio file not found: " << filename << std::endl; |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | AVFormatContext* format_ctx = nullptr; |
| 93 | if (avformat_open_input(&format_ctx, filename.c_str(), nullptr, nullptr) < 0) { |
| 94 | std::cerr << "Error: could not open audio file: " << filename << std::endl; |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool ok = decode_audio(format_ctx, out_audio, target_sample_rate, downmix); |
| 99 | avformat_close_input(&format_ctx); |
| 100 | return ok; |
| 101 | } |
| 102 | |
| 103 | // --------------------------------------------------------------------------- |
| 104 | bool AudioReader::load_audio_from_memory(const uint8_t* data, size_t size, |