// audio.h - WAV loading (with ffmpeg fallback) and selection playback
#ifndef AUDIO_H
#define AUDIO_H

#include "spectrogram_types.h"

// Load a WAV (or any ffmpeg-decodable file) into `signal`, downmixed to mono.
// Returns false on failure (the existing signal is left untouched).
bool LoadWavFile(const char* filepath, AudioSignal* signal);
void FreeSignal(AudioSignal* signal);

// Play the current time/frequency selection (applies an FFT bandpass filter).
// Opens the audio output device on demand (see EnsureAudioDevice).
void PlaySelectedRegion(void);

// Audio output device lifecycle. The device is opened lazily (only when
// something actually plays) and released while idle, so a backgrounded window
// isn't holding the output device open — keeping it open costs steady CPU in
// miniaudio's mixing thread.
void EnsureAudioDevice(void);   // InitAudioDevice() if not already initialized
void ReleaseAudioDevice(void);  // unload the playback sound + CloseAudioDevice()

// Save the current selection (band-limited, time-cropped — same processing as
// playback) as a mono WAV in dirPath. Reports the result via app.exportMessage.
void ExportSelectionWAV(const char* dirPath);

#endif // AUDIO_H
