ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
file_audio.hpp File Reference

File-based audio input for audio-reactive shaders. More...

#include <string>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  acmx2
namespace  acmx2::audio

Functions

void file_audio_close ()
 Close the file audio decoder and release all resources.
std::string file_audio_current_source_path ()
 Return the source track at the current playback position.
bool file_audio_enable_output (int output_device)
 Configure real-time playback of the decoded file through an output device.
bool file_audio_has_output_clock ()
 Check whether real-time output playback can provide the master clock.
bool file_audio_is_active ()
 Check whether file audio playback is still active.
bool file_audio_open (const std::string &filepath)
 Open and fully decode an audio file to mono float PCM at 44 100 Hz.
double file_audio_playback_time ()
 Return the current output-device playback timestamp in seconds.
void file_audio_process_frame (double video_fps, acmx2::audio::AudioAnalyzer &analyzer)
 Advance playback by one video frame and update the audio analyzer.
void file_audio_set_repeat (bool enabled)
 Enable or disable looping of the currently decoded audio file.
std::vector< std::string > file_audio_source_paths ()
 Return the successfully decoded source tracks in playback order.

Detailed Description

File-based audio input for audio-reactive shaders.

Provides an alternative audio source that reads from a media file (WAV, MP3, AAC, FLAC, OGG, or video containers with an audio track) instead of a live microphone via RtAudio. The decoded audio drives the same AudioAnalyzer and 1-D FFT spectrum texture used by live input.

Typical usage:

if (file_audio_open("music.mp3")) {
// each frame:
file_audio_process_frame(60.0, analyzer);
}
void file_audio_close()
Stop file-audio playback and release decoder/sample resources.
bool file_audio_open(const std::string &filepath)
Open and fully decode an audio file to mono float PCM at 44 100 Hz.
void file_audio_process_frame(double video_fps, acmx2::audio::AudioAnalyzer &analyzer)
Advance playback by one video frame and update the audio analyzer.

Requires FFmpeg libraries (libavformat, libavcodec, libswresample). Compiled only when the CMake option AUDIO=ON is set.

Definition in file ACMX2/file_audio.hpp.

Function Documentation

◆ file_audio_close()

void file_audio_close ( )

Close the file audio decoder and release all resources.

Stop file-audio playback and release decoder/sample resources.

Stops file playback, frees any remaining FFmpeg contexts (safe to call even if already closed), and releases the decoded sample buffer.

Close the file audio decoder and release all resources.

Definition at line 526 of file ACMX2/file_audio.cpp.

References closeDecoderResources(), decodedSamples, file_audio_close(), fileAudioActive, anonymous_namespace{file_audio.cpp}::fileAudioOutput, fileAudioRepeat, fileAudioSourceEndPositions, fileAudioSourcePaths, framePlaybackPos, and playbackPos.

Referenced by file_audio_close(), file_audio_open(), and ACView::~ACView().

◆ file_audio_current_source_path()

std::string file_audio_current_source_path ( )

Return the source track at the current playback position.

Returns
Current file/playlist entry path, or an empty string when inactive.

Definition at line 446 of file ACMX2/file_audio.cpp.

References file_audio_current_source_path(), fileAudioActive, fileAudioSourceEndPositions, fileAudioSourcePaths, and playbackPos.

Referenced by file_audio_current_source_path().

◆ file_audio_enable_output()

bool file_audio_enable_output ( int output_device)

Configure real-time playback of the decoded file through an output device.

The stream is opened immediately and starts when file_audio_process_frame() first advances the file, keeping audible playback aligned with visual analysis.

Parameters
output_deviceRtAudio device ID, or -1 for the default output.
Returns
true when the output stream was configured successfully.

Definition at line 455 of file ACMX2/file_audio.cpp.

References decodedSamples, file_audio_enable_output(), and anonymous_namespace{file_audio.cpp}::fileAudioOutput.

Referenced by file_audio_enable_output().

◆ file_audio_has_output_clock()

bool file_audio_has_output_clock ( )

Check whether real-time output playback can provide the master clock.

This remains true from output configuration until the decoded audio reaches its end. Before the stream starts, its timestamp is zero.

Definition at line 469 of file ACMX2/file_audio.cpp.

References file_audio_has_output_clock(), fileAudioActive, and anonymous_namespace{file_audio.cpp}::fileAudioOutput.

Referenced by ACView::draw(), file_audio_has_output_clock(), and file_audio_playback_time().

◆ file_audio_is_active()

bool file_audio_is_active ( )

Check whether file audio playback is still active.

Return true while decoded file-audio samples remain.

Returns
true if a file is open and unplayed samples remain.

Check whether file audio playback is still active.

Definition at line 523 of file ACMX2/file_audio.cpp.

References file_audio_is_active(), and fileAudioActive.

Referenced by file_audio_is_active().

◆ file_audio_open()

bool file_audio_open ( const std::string & filepath)

Open and fully decode an audio file to mono float PCM at 44 100 Hz.

Open and fully decode an audio file or M3U playlist to mono float PCM at 44.1 kHz.

Uses FFmpeg to open filepath, locate the first audio stream, decode it, and resample all samples into an internal buffer. After this call the FFmpeg decoder contexts are freed; only the sample buffer remains in memory.

Parameters
filepathPath to an audio or video file containing an audio track.
Returns
true on success, false on any decoder or I/O error.

Open and fully decode an audio file to mono float PCM at 44 100 Hz.

Definition at line 407 of file ACMX2/file_audio.cpp.

References decodeAudioFile(), decodedSamples, file_audio_close(), file_audio_open(), fileAudioActive, fileAudioSourceEndPositions, fileAudioSourcePaths, framePlaybackPos, isM3uPath(), playbackPos, and readM3uPlaylist().

Referenced by file_audio_open().

◆ file_audio_playback_time()

double file_audio_playback_time ( )

Return the current output-device playback timestamp in seconds.

Returns
Playback position measured by the RtAudio callback, or 0 when no output clock is available.

Definition at line 471 of file ACMX2/file_audio.cpp.

References file_audio_has_output_clock(), file_audio_playback_time(), anonymous_namespace{file_audio.cpp}::FILE_AUDIO_SAMPLE_RATE, and anonymous_namespace{file_audio.cpp}::fileAudioOutput.

Referenced by ACView::draw(), and file_audio_playback_time().

◆ file_audio_process_frame()

void file_audio_process_frame ( double video_fps,
acmx2::audio::AudioAnalyzer & analyzer )

Advance playback by one video frame and update the audio analyzer.

Advance one video-frame worth of samples and update audio analysis.

Without output playback, advances by exactly one video-frame duration using a fractional sample accumulator. With output playback, analyzes the sample window at the output device's current timestamp.

Parameters
video_fpsVideo frame rate — determines how many audio samples are consumed per call.
analyzerShared analyzer that also services live audio input.

Advance playback by one video frame and update the audio analyzer.

Definition at line 478 of file ACMX2/file_audio.cpp.

References decodedSamples, file_audio_process_frame(), anonymous_namespace{file_audio.cpp}::FILE_AUDIO_SAMPLE_RATE, fileAudioActive, anonymous_namespace{file_audio.cpp}::fileAudioOutput, fileAudioRepeat, framePlaybackPos, playbackPos, and acmx2::audio::AudioAnalyzer::process_samples().

Referenced by file_audio_process_frame().

◆ file_audio_set_repeat()

void file_audio_set_repeat ( bool enabled)

Enable or disable looping of the currently decoded audio file.

Parameters
enabledWhen true, playback restarts at the first sample at EOF.

Definition at line 467 of file ACMX2/file_audio.cpp.

References file_audio_set_repeat(), and fileAudioRepeat.

Referenced by file_audio_set_repeat().

◆ file_audio_source_paths()

std::vector< std::string > file_audio_source_paths ( )

Return the successfully decoded source tracks in playback order.

A single audio file returns one path. An M3U source returns each usable playlist entry with relative paths resolved against the playlist directory.

Definition at line 444 of file ACMX2/file_audio.cpp.

References file_audio_source_paths(), and fileAudioSourcePaths.

Referenced by file_audio_source_paths(), and ACView::runFileAudioMuxSync().