ACMX 2.136.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
ACMX2/file_audio.hpp
Go to the documentation of this file.
1#ifndef __FILE_AUDIO__H_
2#define __FILE_AUDIO__H_
3
4#include <string>
5#include <vector>
6
7namespace acmx2::audio {
8 class AudioAnalyzer;
9}
10
11/**
12 * @file file_audio.hpp
13 * @brief File-based audio input for audio-reactive shaders.
14 *
15 * Provides an alternative audio source that reads from a media file
16 * (WAV, MP3, AAC, FLAC, OGG, or video containers with an audio track)
17 * instead of a live microphone via RtAudio. The decoded audio drives
18 * the same AudioAnalyzer and 1-D FFT spectrum texture used by live input.
19 *
20 * Typical usage:
21 * @code
22 * if (file_audio_open("music.mp3")) {
23 * // each frame:
24 * file_audio_process_frame(60.0, analyzer);
25 * }
26 * file_audio_close();
27 * @endcode
28 *
29 * Requires FFmpeg libraries (libavformat, libavcodec, libswresample).
30 * Compiled only when the CMake option @c AUDIO=ON is set.
31 */
32
33/**
34 * @brief Open and fully decode an audio file to mono float PCM at 44 100 Hz.
35 *
36 * Uses FFmpeg to open @p filepath, locate the first audio stream,
37 * decode it, and resample all samples into an internal buffer.
38 * After this call the FFmpeg decoder contexts are freed; only the
39 * sample buffer remains in memory.
40 *
41 * @param filepath Path to an audio or video file containing an audio track.
42 * @return @c true on success, @c false on any decoder or I/O error.
43 */
44bool file_audio_open(const std::string &filepath);
45
46/**
47 * @brief Return the successfully decoded source tracks in playback order.
48 *
49 * A single audio file returns one path. An M3U source returns each usable
50 * playlist entry with relative paths resolved against the playlist directory.
51 */
52std::vector<std::string> file_audio_source_paths();
53
54/**
55 * @brief Return the source track at the current playback position.
56 * @return Current file/playlist entry path, or an empty string when inactive.
57 */
59
60/**
61 * @brief Enable or disable looping of the currently decoded audio file.
62 * @param enabled When true, playback restarts at the first sample at EOF.
63 */
64void file_audio_set_repeat(bool enabled);
65
66/**
67 * @brief Configure real-time playback of the decoded file through an output device.
68 *
69 * The stream is opened immediately and starts when file_audio_process_frame()
70 * first advances the file, keeping audible playback aligned with visual analysis.
71 *
72 * @param output_device RtAudio device ID, or -1 for the default output.
73 * @return @c true when the output stream was configured successfully.
74 */
75bool file_audio_enable_output(int output_device);
76
77/**
78 * @brief Check whether real-time output playback can provide the master clock.
79 *
80 * This remains true from output configuration until the decoded audio reaches
81 * its end. Before the stream starts, its timestamp is zero.
82 */
84
85/**
86 * @brief Return the current output-device playback timestamp in seconds.
87 *
88 * @return Playback position measured by the RtAudio callback, or 0 when no
89 * output clock is available.
90 */
92
93/**
94 * @brief Advance playback by one video frame and update the audio analyzer.
95 *
96 * Without output playback, advances by exactly one video-frame duration
97 * using a fractional sample accumulator. With output playback, analyzes the
98 * sample window at the output device's current timestamp.
99 *
100 * @param video_fps Video frame rate — determines how many audio samples
101 * are consumed per call.
102 * @param analyzer Shared analyzer that also services live audio input.
103 */
104void file_audio_process_frame(double video_fps, acmx2::audio::AudioAnalyzer &analyzer);
105
106/**
107 * @brief Check whether file audio playback is still active.
108 * @return @c true if a file is open and unplayed samples remain.
109 */
111
112/**
113 * @brief Close the file audio decoder and release all resources.
114 *
115 * Stops file playback, frees any remaining FFmpeg contexts (safe to call
116 * even if already closed), and releases the decoded sample buffer.
117 */
118void file_audio_close();
119
120#endif
double file_audio_playback_time()
Return the current output-device playback timestamp in seconds.
bool file_audio_has_output_clock()
Check whether real-time output playback can provide the master clock.
void file_audio_close()
Stop file-audio playback and release decoder/sample resources.
std::vector< std::string > file_audio_source_paths()
Return the successfully decoded source tracks in playback order.
bool file_audio_open(const std::string &filepath)
Open and fully decode an audio file or M3U playlist to mono float PCM at 44.1 kHz.
void file_audio_set_repeat(bool enabled)
Enable or disable looping of the currently decoded audio file.
bool file_audio_enable_output(int output_device)
Configure real-time playback of the decoded file through an output device.
bool file_audio_is_active()
Return true while decoded file-audio samples remain.
void file_audio_process_frame(double video_fps, acmx2::audio::AudioAnalyzer &analyzer)
Advance one video-frame worth of samples and update audio analysis.
std::string file_audio_current_source_path()
Return the source track at the current playback position.
Owns the audio-reactive analysis state shared by live and file audio.