#pragma once #include #include #include /** * Audio buffer structure for storing audio data. * Data is stored in interleaved format (L, R, L, R, ...) for stereo. */ struct AudioBuffer { std::vector data; // Interleaved samples unsigned int channels; unsigned int sampleRate; size_t samples; // Total samples (frames * channels) }; /** * Audio file I/O utilities. * Supports any common audio format (WAV, MP3, FLAC, OGG, etc.) via FFmpeg/libav. * Automatically resamples to target sample rate if needed. */ class AudioFile { public: /** * Load audio from any common audio file format. * Audio is automatically resampled to 44100 Hz and converted to stereo float32. * @param path Path to the audio file * @param target_sample_rate Target sample rate (default: 44100 Hz) * @return AudioBuffer containing the loaded audio data * @throws std::runtime_error if the file cannot be opened or decoded */ static AudioBuffer Load(const std::string& path, int target_sample_rate = 44100); /** * Save audio to a WAV file (PCM float32). * @param path Path to save the WAV file * @param buffer AudioBuffer containing audio data to save * @throws std::runtime_error if the file cannot be written */ static void Save(const std::string& path, const AudioBuffer& buffer); };