LiVES
3.2.0
|
#include "main.h"
#include "audio.h"
#include "events.h"
#include "callbacks.h"
#include "effects.h"
#include "resample.h"
Go to the source code of this file.
Macros | |
#define | CLIP_DECAY ((double)16535. / (double)16536.) |
Functions | |
LIVES_GLOBAL_INLINE char * | get_achannel_name (int totchans, int idx) |
LIVES_GLOBAL_INLINE char * | get_audio_file_name (int fnum, boolean opening) |
LIVES_GLOBAL_INLINE char * | lives_get_audio_file_name (int fnum) |
LIVES_GLOBAL_INLINE const char * | audio_player_get_display_name (const char *aplayer) |
void | audio_free_fnames (void) |
void | append_to_audio_bufferf (float *src, uint64_t nsamples, int channum) |
void | append_to_audio_buffer16 (void *src, uint64_t nsamples, int channum) |
void | init_audio_frame_buffers (short aplayer) |
void | free_audio_frame_buffer (lives_audio_buf_t *abuf) |
float | audiofile_get_maxvol (int fnum, double start, double end, float thresh) |
boolean | normalise_audio (int fnum, double start, double end, float thresh) |
float | get_float_audio_val_at_time (int fnum, int afd, double secs, int chnum, int chans) |
LIVES_GLOBAL_INLINE void | sample_silence_dS (float *dst, uint64_t nsamples) |
void | sample_silence_stream (int nchans, int64_t nframes) |
void | sample_move_d8_d16 (short *dst, uint8_t *src, uint64_t nsamples, size_t tbytes, double scale, int nDstChannels, int nSrcChannels, int swap_sign) |
void | sample_move_d16_d16 (int16_t *dst, int16_t *src, uint64_t nsamples, size_t tbytes, double scale, int nDstChannels, int nSrcChannels, int swap_endian, int swap_sign) |
convert from any number of source channels to any number of destination channels - both interleaved More... | |
void | sample_move_d16_d8 (uint8_t *dst, short *src, uint64_t nsamples, size_t tbytes, double scale, int nDstChannels, int nSrcChannels, int swap_sign) |
convert from any number of source channels to any number of destination channels - 8 bit output More... | |
float | sample_move_d16_float (float *dst, short *src, uint64_t nsamples, uint64_t src_skip, int is_unsigned, boolean rev_endian, float vol) |
void | sample_move_float_float (float *dst, float *src, uint64_t nsamples, double scale, int dst_skip) |
int64_t | sample_move_float_int (void *holding_buff, float **float_buffer, int nsamps, double scale, int chans, int asamps, int usigned, boolean rev_endian, boolean interleaved, float vol) |
convert float samples back to int interleaved is for the float buffer; output int is always interleaved scale is out_sample_rate / in_sample_rate (so 2.0 would play twice as fast, etc.) nsamps is number of out samples, asamps is out sample bit size (8 or 16) output is in holding_buff which can be cast to uint8_t *, int16_t *, or uint16_t * returns number of frames out More... | |
int64_t | sample_move_abuf_float (float **obuf, int nchans, int nsamps, int out_arate, float vol) |
copy audio data from cache into audio sound buffer More... | |
int64_t | sample_move_abuf_int16 (short *obuf, int nchans, int nsamps, int out_arate) |
copy audio data from cache into audio sound buffer More... | |
boolean | float_deinterleave (float *fbuffer, int nsamps, int nchans) |
boolean | float_interleave (float *fbuffer, int nsamps, int nchans) |
boolean | pad_with_silence (int out_fd, void *buff, off64_t oins_size, int64_t ins_size, int asamps, int aunsigned, boolean big_endian) |
LIVES_LOCAL_INLINE void | audio_process_events_to (weed_timecode_t tc) |
int64_t | render_audio_segment (int nfiles, int *from_files, int to_file, double *avels, double *fromtime, weed_timecode_t tc_start, weed_timecode_t tc_end, double *chvol, double opvol_start, double opvol_end, lives_audio_buf_t *obuf) |
render a chunk of audio, apply effects and mixing it More... | |
void | aud_fade (int fileno, double startt, double endt, double startv, double endv) |
fade in/fade out More... | |
void | preview_audio (void) |
void | preview_aud_vol (void) |
boolean | adjust_clip_volume (int fileno, float newvol, boolean make_backup) |
LIVES_LOCAL_INLINE lives_audio_track_state_t * | aframe_to_atstate (weed_plant_t *event) |
LIVES_GLOBAL_INLINE lives_audio_track_state_t * | audio_frame_to_atstate (weed_event_t *event, int *ntracks) |
lives_audio_track_state_t * | get_audio_and_effects_state_at (weed_plant_t *event_list, weed_plant_t *st_event, weed_timecode_t fill_tc, int what_to_get, boolean exact) |
get audio (and optionally video) state at timecode tc OR before event st_event More... | |
void | fill_abuffer_from (lives_audio_buf_t *abuf, weed_plant_t *event_list, weed_plant_t *st_event, boolean exact) |
void | init_jack_audio_buffers (int achans, int arate, boolean exact) |
void | init_pulse_audio_buffers (int achans, int arate, boolean exact) |
void | free_jack_audio_buffers (void) |
void | free_pulse_audio_buffers (void) |
LIVES_GLOBAL_INLINE void | avsync_force (void) |
boolean | resync_audio (double frameno) |
resync audio playback to the current video frame More... | |
void | wake_audio_thread (void) |
lives_audio_buf_t * | audio_cache_init (void) |
void | audio_cache_end (void) |
LIVES_GLOBAL_INLINE lives_audio_buf_t * | audio_cache_get_buffer (void) |
boolean | get_audio_from_plugin (float **fbuffer, int nchans, int arate, int nsamps, boolean is_audio_thread) |
void | reinit_audio_gen (void) |
boolean | apply_rte_audio_init (void) |
void | apply_rte_audio_end (boolean del) |
boolean | apply_rte_audio (int64_t nframes) |
boolean | push_audio_to_channel (weed_plant_t *filter, weed_plant_t *achan, lives_audio_buf_t *abuf) |
fill the audio channel(s) for effects with mixed audio / video More... | |
boolean | start_audio_stream (void) |
void | stop_audio_stream (void) |
void | clear_audio_stream (void) |
LIVES_GLOBAL_INLINE void | audio_stream (void *buff, size_t nbytes, int fd) |
LIVES_GLOBAL_INLINE lives_cancel_t | handle_audio_timeout (void) |
Variables | |
off64_t | audio_pos |
weed_timecode_t | aud_tc |
lives_pgid_t | astream_pgid = 0 |
LIVES_LOCAL_INLINE lives_audio_track_state_t* aframe_to_atstate | ( | weed_plant_t * | event | ) |
Definition at line 2400 of file audio.c.
Referenced by fill_abuffer_from(), and get_audio_and_effects_state_at().
void append_to_audio_buffer16 | ( | void * | src, |
uint64_t | nsamples, | ||
int | channum | ||
) |
void append_to_audio_bufferf | ( | float * | src, |
uint64_t | nsamples, | ||
int | channum | ||
) |
void aud_fade | ( | int | fileno, |
double | startt, | ||
double | endt, | ||
double | startv, | ||
double | endv | ||
) |
fade in/fade out
Definition at line 1813 of file audio.c.
Referenced by adjust_clip_volume(), and on_fade_audio_activate().
void audio_cache_end | ( | void | ) |
LIVES_GLOBAL_INLINE lives_audio_buf_t* audio_cache_get_buffer | ( | void | ) |
lives_audio_buf_t* audio_cache_init | ( | void | ) |
LIVES_GLOBAL_INLINE lives_audio_track_state_t* audio_frame_to_atstate | ( | weed_event_t * | event, |
int * | ntracks | ||
) |
Definition at line 2405 of file audio.c.
Referenced by pre_analyse().
void audio_free_fnames | ( | void | ) |
Definition at line 71 of file audio.c.
Referenced by on_fade_audio_activate(), render_events(), and render_to_clip().
LIVES_GLOBAL_INLINE const char* audio_player_get_display_name | ( | const char * | aplayer | ) |
Definition at line 65 of file audio.c.
Referenced by handle_audio_timeout().
LIVES_LOCAL_INLINE void audio_process_events_to | ( | weed_timecode_t | tc | ) |
LIVES_GLOBAL_INLINE void audio_stream | ( | void * | buff, |
size_t | nbytes, | ||
int | fd | ||
) |
float audiofile_get_maxvol | ( | int | fnum, |
double | start, | ||
double | end, | ||
float | thresh | ||
) |
LIVES_GLOBAL_INLINE void avsync_force | ( | void | ) |
force realignment of video and audio at current file->frameno / player->seek_pos
Definition at line 2785 of file audio.c.
Referenced by switch_audio_clip().
void fill_abuffer_from | ( | lives_audio_buf_t * | abuf, |
weed_plant_t * | event_list, | ||
weed_plant_t * | st_event, | ||
boolean | exact | ||
) |
boolean float_deinterleave | ( | float * | fbuffer, |
int | nsamps, | ||
int | nchans | ||
) |
boolean float_interleave | ( | float * | fbuffer, |
int | nsamps, | ||
int | nchans | ||
) |
void free_audio_frame_buffer | ( | lives_audio_buf_t * | abuf | ) |
Definition at line 207 of file audio.c.
Referenced by append_to_audio_buffer16(), and append_to_audio_bufferf().
LIVES_GLOBAL_INLINE char* get_achannel_name | ( | int | totchans, |
int | idx | ||
) |
Definition at line 28 of file audio.c.
Referenced by add_audio_track(), and show_playbar_labels().
lives_audio_track_state_t* get_audio_and_effects_state_at | ( | weed_plant_t * | event_list, |
weed_plant_t * | st_event, | ||
weed_timecode_t | fill_tc, | ||
int | what_to_get, | ||
boolean | exact | ||
) |
get audio (and optionally video) state at timecode tc OR before event st_event
if st_event is not NULL, we get the state just prior to it (state being effects and filter maps, audio tracks / positions)
if st_event is NULL, this is a continuation, and we get the audio state only at timecode tc similar to quantise_events(), except we don't produce output frames
TODO: if exact && non-stateless, silently process audio / video until st_event
update audio state
Definition at line 2419 of file audio.c.
Referenced by audio_process_events_to(), and fill_abuffer_from().
LIVES_GLOBAL_INLINE char* get_audio_file_name | ( | int | fnum, |
boolean | opening | ||
) |
Definition at line 38 of file audio.c.
Referenced by lives_get_audio_file_name().
float get_float_audio_val_at_time | ( | int | fnum, |
int | afd, | ||
double | secs, | ||
int | chnum, | ||
int | chans | ||
) |
LIVES_GLOBAL_INLINE lives_cancel_t handle_audio_timeout | ( | void | ) |
Definition at line 3971 of file audio.c.
Referenced by _start_playback(), load_frame_image(), play_sel(), preview_audio(), and switch_audio_clip().
void init_jack_audio_buffers | ( | int | achans, |
int | arate, | ||
boolean | exact | ||
) |
void init_pulse_audio_buffers | ( | int | achans, |
int | arate, | ||
boolean | exact | ||
) |
LIVES_GLOBAL_INLINE char* lives_get_audio_file_name | ( | int | fnum | ) |
Definition at line 55 of file audio.c.
Referenced by aud_fade(), on_recaudclip_ok_clicked(), reget_afilesize_inner(), and wait_for_bg_audio_sync().
boolean normalise_audio | ( | int | fnum, |
double | start, | ||
double | end, | ||
float | thresh | ||
) |
Definition at line 280 of file audio.c.
Referenced by on_normalise_audio_activate().
void preview_audio | ( | void | ) |
Definition at line 1835 of file audio.c.
Referenced by preview_aud_vol().
boolean push_audio_to_channel | ( | weed_plant_t * | filter, |
weed_plant_t * | achan, | ||
lives_audio_buf_t * | abuf | ||
) |
fill the audio channel(s) for effects with mixed audio / video
push audio from abuf into an audio channel audio will be formatted to the channel requested format
when we have audio effects running, the buffer is constantly fiiled from the audio thread (we have two buffers so that we dont hang the player during read). When the first client reads, the buffers are swapped.
if player is jack, we will have non-interleaved float, if player is pulse, we will have interleaved S16 so we have to convert to float and then back again.
(this is currently only used to push audio to generators, since there are currently no filters which allow both video and audio input)
int64_t render_audio_segment | ( | int | nfiles, |
int * | from_files, | ||
int | to_file, | ||
double * | avels, | ||
double * | fromtime, | ||
weed_timecode_t | tc_start, | ||
weed_timecode_t | tc_end, | ||
double * | chvol, | ||
double | opvol_start, | ||
double | opvol_end, | ||
lives_audio_buf_t * | obuf | ||
) |
render a chunk of audio, apply effects and mixing it
called during multitrack rendering to create the actual audio file (or in-memory buffer for preview playback in multitrack)
also used for fade-in/fade-out in the clip editor (opvol_start, opvol_end)
in multitrack, chvol is taken from the audio mixer; opvol is always 1.
what we will do here: calculate our target samples (= period * out_rate)
calculate how many in_samples for each track (= period * in_rate / ABS (vel) )
read in the relevant number of samples for each track and convert to float
write this into our float buffers (1 buffer per channel per track)
we then send small chunks at a time to any audio effects; this is to allow for parameter interpolation
the small chunks are processed and mixed, converted from float back to int, and then written to the outfile
if obuf != NULL we write to obuf instead
< only used if we are writing output to a file
this is not the velocity we will use for reading, but we need to estimate how many bytes we will read in so we can calculate how many buffers to allocate
we don't want to use more than MAX_AUDIO_MEM bytes (numbers will be much larger than examples given)
calculate tbytes for xsamples
tbytes: how many bytes we want to read in. This is xsamples * the track velocity. we add a small random factor here, so half the time we round up, half the time we round down otherwise we would be gradually losing or gaining samples
convert to float
if we are previewing a rendering, we would get double the volume adjustment, once from the rendering and again from the audio player, so in that case we skip the adjustment here
now we convert to holding_buff to float in float_buffer and adjust the track volume
< this is our chunk size
here we work out the "visibility" of each track at tc (i.e we only get audio from the front track + backing audio) any transitions will combine audio from 2 layers (if the pref is set) backing audio tracks are always full visible the array is used to set the values of the "is_volume_master" parameter of the effect (see the Weed Audio spec.)
first track is ascrap_file - flag that no effects should be applied to it, except for the audio mixer since effects were already applied to the saved audio
the audio is now packaged into audio layers, one for each track (file). This makes it easier to remap the audio tracks from effect to effect, as layers are interchangeable with filter channels
apply the audo effects
after processing we get the audio data back from the layers
non-inplace, audio was replaced so wee need to copy to float_buffer and free
output to file: convert back to int; use out_scale of 1., since we did our resampling in sample_move_*_d16
output to memory buffer; for jack we retain the float audio, for pulse we use int16_t
Definition at line 1276 of file audio.c.
Referenced by aud_fade(), fill_abuffer_from(), on_paste_as_new_activate(), and on_recaudclip_ok_clicked().
boolean resync_audio | ( | double | frameno | ) |
resync audio playback to the current video frame
if we are using a realtime audio player, resync to frameno and return TRUE
otherwise return FALSE
this is called internally - for example when the play position jumps, either due to external transport changes, (e.g. jack transport, osc retrigger / goto) or if we are looping a video selection, or it may be triggered from the keyboard
this is only active if "audio follows video rate/fps changes" is set and various other conditions are met.
Definition at line 2822 of file audio.c.
Referenced by aud_lock_callback(), fps_reset_callback(), and load_frame_image().
int64_t sample_move_abuf_float | ( | float ** | obuf, |
int | nchans, | ||
int | nsamps, | ||
int | out_arate, | ||
float | vol | ||
) |
int64_t sample_move_abuf_int16 | ( | short * | obuf, |
int | nchans, | ||
int | nsamps, | ||
int | out_arate | ||
) |
void sample_move_d16_d16 | ( | int16_t * | dst, |
int16_t * | src, | ||
uint64_t | nsamples, | ||
size_t | tbytes, | ||
double | scale, | ||
int | nDstChannels, | ||
int | nSrcChannels, | ||
int | swap_endian, | ||
int | swap_sign | ||
) |
void sample_move_d16_d8 | ( | uint8_t * | dst, |
short * | src, | ||
uint64_t | nsamples, | ||
size_t | tbytes, | ||
double | scale, | ||
int | nDstChannels, | ||
int | nSrcChannels, | ||
int | swap_sign | ||
) |
float sample_move_d16_float | ( | float * | dst, |
short * | src, | ||
uint64_t | nsamples, | ||
uint64_t | src_skip, | ||
int | is_unsigned, | ||
boolean | rev_endian, | ||
float | vol | ||
) |
Definition at line 677 of file audio.c.
Referenced by push_audio_to_channel().
void sample_move_d8_d16 | ( | short * | dst, |
uint8_t * | src, | ||
uint64_t | nsamples, | ||
size_t | tbytes, | ||
double | scale, | ||
int | nDstChannels, | ||
int | nSrcChannels, | ||
int | swap_sign | ||
) |
Definition at line 459 of file audio.c.
Referenced by push_audio_to_channel().
void sample_move_float_float | ( | float * | dst, |
float * | src, | ||
uint64_t | nsamples, | ||
double | scale, | ||
int | dst_skip | ||
) |
Definition at line 745 of file audio.c.
Referenced by push_audio_to_channel().
int64_t sample_move_float_int | ( | void * | holding_buff, |
float ** | float_buffer, | ||
int | nsamps, | ||
double | scale, | ||
int | chans, | ||
int | asamps, | ||
int | usigned, | ||
boolean | rev_endian, | ||
boolean | interleaved, | ||
float | vol | ||
) |
convert float samples back to int interleaved is for the float buffer; output int is always interleaved scale is out_sample_rate / in_sample_rate (so 2.0 would play twice as fast, etc.) nsamps is number of out samples, asamps is out sample bit size (8 or 16) output is in holding_buff which can be cast to uint8_t *, int16_t *, or uint16_t * returns number of frames out
returns frames output
clipping is applied so that -1.0 <= fval <= 1.0 the clipping value is applied linearly to vol (as a divisor), and if not reset it will decay so clip = 1.0 + (clip - 1.0) * CLIP_DECAY each sample --> clip = 1.0 + clip * CLIP_DECAY - CLIP_DECAY --> clip = (clip * CLIP_DECAY) + (1.0 - CLIP_DECAY) --> clip *= CLIP_DECAY; clip += (1.0 - CLIP_DECAY)
LIVES_GLOBAL_INLINE void sample_silence_dS | ( | float * | dst, |
uint64_t | nsamples | ||
) |
boolean start_audio_stream | ( | void | ) |
Definition at line 3827 of file audio.c.
Referenced by on_vppa_ok_clicked().
void stop_audio_stream | ( | void | ) |
Definition at line 3906 of file audio.c.
Referenced by close_vid_playback_plugin(), lives_exit(), on_vppa_ok_clicked(), and vid_playback_plugin_exit().
void wake_audio_thread | ( | void | ) |
Definition at line 3230 of file audio.c.
Referenced by sample_move_abuf_float(), and sample_move_abuf_int16().
lives_pgid_t astream_pgid = 0 |
Definition at line 3825 of file audio.c.
Referenced by start_audio_stream(), and stop_audio_stream().
off64_t audio_pos |
Definition at line 3470 of file audio.c.
Referenced by apply_rte_audio(), and apply_rte_audio_init().