LiVES 2.4.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
audio.h
Go to the documentation of this file.
1 // audio.h
2 // LiVES (lives-exe)
3 // (c) G. Finch 2005 - 2009
4 // Released under the GPL 3 or later
5 // see file ../COPYING for licensing details
6
7 #ifndef HAS_LIVES_AUDIO_H
8 #define HAS_LIVES_AUDIO_H
9
10 #define SAMPLE_MAX_16BIT_P 32767.0f
11 #define SAMPLE_MAX_16BIT_N 32768.0f
12 #define SAMPLE_MAX_16BITI 32768
13
15 #define SWAP_U_TO_S 1
16 #define SWAP_S_TO_U 2
17
18 #define SWAP_X_TO_L 1
20 #define SWAP_L_TO_X 2
21
22
24 # define DEFAULT_AUDIO_RATE 44100
25 # define DEFAULT_AUDIO_CHANS 2
26 # define DEFAULT_AUDIO_SAMPS 16
27 # define DEFAULT_AUDIO_SIGNED8 (AFORM_UNSIGNED)
28 # define DEFAULT_AUDIO_SIGNED16 (!AFORM_UNSIGNED)
29
31 #define LIVES_ACONNECT_TIMEOUT (10 * U_SEC)
32
34 #define MAX_AUDIO_MEM 8*1024*1024
35
37 #define RENDER_BLOCK_SIZE 1024
38
40 #define SILENCE_BLOCK_SIZE 65536
41
43 #define READ_BLOCK_SIZE 4096
44
46 #define XSAMPLES 128000
47
48
51
52
53 #define ASERVER_CMD_PROCESSED 0
54 #define ASERVER_CMD_FILE_OPEN 1
55 #define ASERVER_CMD_FILE_CLOSE 2
56 #define ASERVER_CMD_FILE_SEEK 3
57
58 /* message passing structure */
59 typedef struct _aserver_message_t {
60 volatile int command;
61 volatile char *data;
62 volatile struct _aserver_message_t *next;
63 } aserver_message_t;
64
65
66
67 typedef enum {
68 LIVES_NOP_OPERATION=0,
69 LIVES_READ_OPERATION,
70 LIVES_WRITE_OPERATION,
71 LIVES_CONVERT_OPERATION
72 } lives_operation_t;
73
74
75
76
77 typedef struct {
78 lives_operation_t operation; // read, write, or convert [readonly by server]
79 volatile boolean is_ready; // [readwrite all]
80 boolean eof;
81 int fileno; // [readonly by server]
82
83 // readonly by server:
84
85 // use one or other
86 off_t seek;
87 weed_timecode_t start_tc;
88
89 double arate;
90
91 ssize_t bytesize; // file in/out length in bytes [write by server in case of eof]
92
93 boolean in_interleaf;
94 boolean out_interleaf;
95
96 int in_achans;
97 int out_achans;
98 int in_asamps; // set to -val for float
99 int out_asamps; // set to -val for float
100 int swap_sign;
101 int swap_endian;
102 double shrink_factor;
103
104 size_t samp_space;
105
106
107 // in or out buffers
108 uint8_t **buffer8;
109 short **buffer16;
110 int32_t **buffer24;
111 int32_t **buffer32;
112 float **bufferf;
113
114 boolean s8_signed;
115 boolean s16_signed;
116 boolean s24_signed;
117 boolean s32_signed;
118
119 // ring buffer
120 size_t samples_filled;
121 size_t start_sample;
122
123
124 // private fields (used by server)
125 uint8_t *_filebuffer;
126 ssize_t _cbytesize;
127 size_t _csamp_space;
128 int _fd;
129 int _cfileno;
130 int _cseek;
131 int _cachans;
132 int _cin_interleaf;
133 int _cout_interleaf;
134 int _casamps;
135
136 volatile boolean die;
137
138 } lives_audio_buf_t;
139
140
142
143 typedef enum lives_audio_loop {
144 AUDIO_LOOP_NONE,
145 AUDIO_LOOP_FORWARD,
146 AUDIO_LOOP_PINGPONG
147 } lives_audio_loop_t;
148
149
150
151 void sample_silence_dS(float *dst, uint64_t nsamples);
152
153 void sample_move_d8_d16(short *dst, uint8_t *src,
154 uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_sign);
155
156 void sample_move_d16_d16(short *dst, short *src,
157 uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_endian, int swap_sign);
158
159 void sample_move_d16_d8(uint8_t *dst, short *src,
160 uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_sign);
161
162 void sample_move_d16_float(float *dst, short *src, uint64_t nsamples, uint64_t src_skip, int is_unsigned, boolean rev_endian, float vol);
163
164 int64_t sample_move_float_int(void *holding_buff, float **float_buffer, int nsamps, float scale, int chans, int asamps, int usigned,
165 boolean swap_endian, boolean float_interleaved, float vol);
166
167 int64_t sample_move_abuf_float(float **obuf, int nchans, int nsamps, int out_arate, float vol);
168
169 int64_t sample_move_abuf_int16(short *obuf, int nchans, int nsamps, int out_arate);
170
171 void sample_move_float_float(float *dst, float *src, uint64_t nsamples, float scale, int dst_skip);
172
173 boolean float_deinterleave(float *fbuffer, int nsamps, int nchans);
174 boolean float_interleave(float *fbuffer, int nsamps, int nchans);
175
176 int64_t render_audio_segment(int nfiles, int *from_files, int to_file, double *avels, double *fromtime, weed_timecode_t tc_start,
177 weed_timecode_t tc_end, double *chvol, double opvol_start, double opvol_end, lives_audio_buf_t *obuf);
178
179 void aud_fade(int fileno, double startt, double endt, double startv, double endv);
180
181 typedef enum {
182 RECA_WINDOW_GRAB,
183 RECA_NEW_CLIP,
184 RECA_EXISTING,
185 RECA_EXTERNAL,
186 RECA_GENERATED
187 } lives_rec_audio_type_t;
188
189 #ifdef ENABLE_JACK
190 void jack_rec_audio_to_clip(int fileno, int oldfileno, lives_rec_audio_type_t rec_type);
191 void jack_rec_audio_end(boolean close_dev, boolean close_fd);
192 #endif
193
194 #ifdef HAVE_PULSE_AUDIO
195 void pulse_rec_audio_to_clip(int fileno, int oldfileno, lives_rec_audio_type_t rec_type);
196 void pulse_rec_audio_end(boolean close_dev, boolean close_fd);
197 #endif
198
199 void fill_abuffer_from(lives_audio_buf_t *abuf, weed_plant_t *event_list, weed_plant_t *st_event, boolean exact);
200
201
202 boolean resync_audio(int frameno);
203
204
205 lives_audio_track_state_t *get_audio_and_effects_state_at(weed_plant_t *event_list, weed_plant_t *st_event, boolean get_audstate,
206 boolean exact);
207
208 boolean get_audio_from_plugin(float *fbuffer, int nchans, int arate, int nsamps);
209 void reinit_audio_gen(void);
210
211 void init_jack_audio_buffers(int achans, int arate, boolean exact);
212 void free_jack_audio_buffers(void);
213
214 void init_pulse_audio_buffers(int achans, int arate, boolean exact);
215 void free_pulse_audio_buffers(void);
216
217 void audio_free_fnames(void);
218
219 lives_audio_buf_t *audio_cache_init(void);
220 void audio_cache_end(void);
221 lives_audio_buf_t *audio_cache_get_buffer(void);
222
223 boolean apply_rte_audio_init(void);
224 void apply_rte_audio_end(boolean del);
225 boolean apply_rte_audio(int nframes);
226
227 void init_audio_frame_buffer(short aplayer);
228 void free_audio_frame_buffer(lives_audio_buf_t *abuf);
229 void append_to_audio_bufferf(lives_audio_buf_t *abuf, float *src, uint64_t nsamples, int channum);
230 void append_to_audio_buffer16(lives_audio_buf_t *abuf, void *src, uint64_t nsamples, int channum);
231 boolean push_audio_to_channel(weed_plant_t *achan, lives_audio_buf_t *abuf);
232
233 boolean start_audio_stream(void);
234 void stop_audio_stream(void);
235 void clear_audio_stream(void);
236 void audio_stream(void *buff, size_t nbytes, int fd);
237
238 #endif
float_deinterleave
boolean float_deinterleave(float *fbuffer, int nsamps, int nchans)
Definition: audio.c:738
RECA_GENERATED
Definition: audio.h:186
start_audio_stream
boolean start_audio_stream(void)
Definition: audio.c:3051
lives_audio_buf_t::buffer32
int32_t ** buffer32
sample data in 32 bit format (or NULL)
Definition: audio.h:111
sample_move_d16_d16
void sample_move_d16_d16(int16_t *dst, int16_t *src, uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_endian, int swap_sign)
Definition: audio.c:254
AUDIO_LOOP_NONE
Definition: audio.h:144
audio_cache_get_buffer
lives_audio_buf_t * audio_cache_get_buffer(void)
Definition: audio.c:2568
LIVES_WRITE_OPERATION
Definition: audio.h:70
aud_fade
LIVES_INLINE void aud_fade(int fileno, double startt, double endt, double startv, double endv)
fade in/fade out
Definition: audio.c:1374
lives_audio_loop_t
lives_audio_loop_t
Definition: audio.h:143
lives_audio_buf_t::_fd
int _fd
file descriptor
Definition: audio.h:128
sample_move_float_int
int64_t sample_move_float_int(void *holding_buff, float **float_buffer, int nsamps, float scale, int chans, int asamps, int usigned, boolean little_endian, boolean interleaved, float vol)
returns frames output
Definition: audio.c:457
LIVES_READ_OPERATION
Definition: audio.h:69
lives_audio_buf_t::bufferf
float ** bufferf
sample data in float format (or NULL)
Definition: audio.h:112
lives_audio_buf_t::_cin_interleaf
int _cin_interleaf
Definition: audio.h:132
lives_audio_buf_t::out_achans
int out_achans
channels for buffer* side
Definition: audio.h:97
lives_audio_buf_t
Definition: audio.h:77
clear_audio_stream
void clear_audio_stream(void)
Definition: audio.c:3182
lives_audio_buf_t::_csamp_space
size_t _csamp_space
current sample buffer size in single channel samples
Definition: audio.h:127
lives_audio_buf_t::swap_sign
int swap_sign
Definition: audio.h:100
lives_audio_buf_t::eof
boolean eof
did we read EOF ? [readonly by client]
Definition: audio.h:80
lives_audio_buf_t::buffer16
short ** buffer16
sample data in 16 bit format (or NULL)
Definition: audio.h:109
lives_audio_buf_t::_cseek
int _cseek
current seek pos
Definition: audio.h:130
sample_move_d8_d16
void sample_move_d8_d16(short *dst, uint8_t *src, uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_sign)
Definition: audio.c:199
lives_audio_buf_t::bytesize
ssize_t bytesize
Definition: audio.h:91
free_pulse_audio_buffers
void free_pulse_audio_buffers(void)
Definition: audio.c:2117
init_pulse_audio_buffers
void init_pulse_audio_buffers(int achans, int arate, boolean exact)
Definition: audio.c:2073
lives_audio_buf_t::arate
double arate
Definition: audio.h:89
lives_audio_buf_t::in_interleaf
boolean in_interleaf
Definition: audio.h:93
lives_operation_t
lives_operation_t
Definition: audio.h:67
sample_silence_dS
LIVES_INLINE void sample_silence_dS(float *dst, uint64_t nsamples)
Definition: audio.c:193
audio_cache_end
void audio_cache_end(void)
Definition: audio.c:2535
append_to_audio_buffer16
void append_to_audio_buffer16(lives_audio_buf_t *abuf, void *src, uint64_t nsamples, int channum)
Definition: audio.c:90
sample_move_abuf_float
int64_t sample_move_abuf_float(float **obuf, int nchans, int nsamps, int out_arate, float vol)
Definition: audio.c:511
lives_audio_buf_t::s8_signed
boolean s8_signed
Definition: audio.h:114
sample_move_d16_float
void sample_move_d16_float(float *dst, short *src, uint64_t nsamples, uint64_t src_skip, int is_unsigned, boolean rev_endian, float vol)
Definition: audio.c:380
free_audio_frame_buffer
void free_audio_frame_buffer(lives_audio_buf_t *abuf)
Definition: audio.c:153
sample_move_abuf_int16
int64_t sample_move_abuf_int16(short *obuf, int nchans, int nsamps, int out_arate)
Definition: audio.c:616
aserver_message_t::data
volatile char * data
Definition: audio.h:61
apply_rte_audio_init
boolean apply_rte_audio_init(void)
Definition: audio.c:2718
RECA_EXTERNAL
Definition: audio.h:185
lives_audio_buf_t::s16_signed
boolean s16_signed
Definition: audio.h:115
get_audio_and_effects_state_at
lives_audio_track_state_t * get_audio_and_effects_state_at(weed_plant_t *event_list, weed_plant_t *st_event, boolean get_audstate, boolean exact)
Definition: audio.c:1785
lives_audio_buf_t::out_interleaf
boolean out_interleaf
Definition: audio.h:94
lives_audio_buf_t::die
volatile boolean die
set to TRUE to shut down thread
Definition: audio.h:136
lives_audio_buf_t::in_asamps
int in_asamps
Definition: audio.h:98
audio_free_fnames
void audio_free_fnames(void)
Definition: audio.c:46
apply_rte_audio
boolean apply_rte_audio(int nframes)
Definition: audio.c:2763
lives_audio_buf_t::_cbytesize
ssize_t _cbytesize
current _filebuffer bytesize; if this changes we need to realloc _filebuffer
Definition: audio.h:126
fill_abuffer_from
void fill_abuffer_from(lives_audio_buf_t *abuf, weed_plant_t *event_list, weed_plant_t *st_event, boolean exact)
Definition: audio.c:1874
lives_audio_buf_t::_cfileno
int _cfileno
current fileno
Definition: audio.h:129
lives_audio_buf_t::s24_signed
boolean s24_signed
Definition: audio.h:116
resync_audio
boolean resync_audio(int frameno)
Definition: audio.c:2140
sample_move_float_float
void sample_move_float_float(float *dst, float *src, uint64_t nsamples, float scale, int dst_skip)
Definition: audio.c:442
aserver_message_t::command
volatile int command
Definition: audio.h:60
stop_audio_stream
void stop_audio_stream(void)
Definition: audio.c:3137
lives_audio_buf_t::start_sample
size_t start_sample
used for reading (readonly server)
Definition: audio.h:121
lives_audio_buf_t::shrink_factor
double shrink_factor
resampling ratio
Definition: audio.h:102
audio_cache_init
lives_audio_buf_t * audio_cache_init(void)
Definition: audio.c:2499
sample_move_d16_d8
void sample_move_d16_d8(uint8_t *dst, short *src, uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_sign)
Definition: audio.c:327
get_audio_from_plugin
boolean get_audio_from_plugin(float *fbuffer, int nchans, int arate, int nsamps)
Definition: audio.c:2577
lives_audio_buf_t::swap_endian
int swap_endian
Definition: audio.h:101
render_audio_segment
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)
Definition: audio.c:896
push_audio_to_channel
boolean push_audio_to_channel(weed_plant_t *achan, lives_audio_buf_t *abuf)
Definition: audio.c:2918
aserver_message_t::next
struct _aserver_message_t * next
Definition: audio.h:62
RECA_NEW_CLIP
Definition: audio.h:183
RECA_WINDOW_GRAB
Definition: audio.h:182
lives_audio_track_state_t
Definition: main.h:311
lives_audio_buf_t::out_asamps
int out_asamps
Definition: audio.h:99
AUDIO_LOOP_FORWARD
Definition: audio.h:145
apply_rte_audio_end
void apply_rte_audio_end(boolean del)
Definition: audio.c:2756
AUDIO_LOOP_PINGPONG
Definition: audio.h:146
lives_audio_buf_t::samp_space
size_t samp_space
buffer space in samples (* by sizeof(type) to get bytesize) [if interleaf, also * by chans] ...
Definition: audio.h:104
lives_audio_buf_t::_casamps
int _casamps
current out_asamps
Definition: audio.h:134
lives_audio_buf_t::_filebuffer
uint8_t * _filebuffer
raw data to/from file - can be cast to int16_t
Definition: audio.h:125
lives_audio_buf_t::samples_filled
size_t samples_filled
number of samples filled (readonly client)
Definition: audio.h:120
init_jack_audio_buffers
void init_jack_audio_buffers(int achans, int arate, boolean exact)
Definition: audio.c:2051
lives_audio_buf_t::in_achans
int in_achans
channels for _filebuffer side
Definition: audio.h:96
lives_rec_audio_type_t
lives_rec_audio_type_t
Definition: audio.h:181
aserver_message_t
Definition: audio.h:59
lives_audio_buf_t::_cachans
int _cachans
current output channels
Definition: audio.h:131
lives_audio_buf_t::s32_signed
boolean s32_signed
Definition: audio.h:117
lives_audio_buf_t::buffer8
uint8_t ** buffer8
sample data in 8 bit format (or NULL)
Definition: audio.h:108
lives_audio_buf_t::_cout_interleaf
int _cout_interleaf
Definition: audio.h:133
lives_audio_buf_t::operation
lives_operation_t operation
Definition: audio.h:78
RECA_EXISTING
Definition: audio.h:184
reinit_audio_gen
void reinit_audio_gen(void)
Definition: audio.c:2694
lives_audio_buf_t::fileno
int fileno
Definition: audio.h:81
lives_audio_buf_t::buffer24
int32_t ** buffer24
sample data in 24 bit format (or NULL)
Definition: audio.h:110
init_audio_frame_buffer
void init_audio_frame_buffer(short aplayer)
Definition: audio.c:118
audio_stream
LIVES_INLINE void audio_stream(void *buff, size_t nbytes, int fd)
Definition: audio.c:3198
lives_audio_buf_t::is_ready
volatile boolean is_ready
Definition: audio.h:79
append_to_audio_bufferf
void append_to_audio_bufferf(lives_audio_buf_t *abuf, float *src, uint64_t nsamples, int channum)
Definition: audio.c:64
float_interleave
boolean float_interleave(float *fbuffer, int nsamps, int nchans)
Definition: audio.c:756
LIVES_NOP_OPERATION
Definition: audio.h:68
LIVES_CONVERT_OPERATION
Definition: audio.h:71
lives_audio_buf_t::start_tc
weed_timecode_t start_tc
Definition: audio.h:87
free_jack_audio_buffers
void free_jack_audio_buffers(void)
Definition: audio.c:2094
lives_audio_buf_t::seek
off_t seek
Definition: audio.h:86