LiVES  3.0.2
audio.h
Go to the documentation of this file.
1 // audio.h
2 // LiVES (lives-exe)
3 // (c) G. Finch 2005 - 2016
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 
30 // keep first N audio_in filesysten handles open - multitrack only
31 #define NSTOREDFDS 16
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 #define AUD_WRITTEN_CHECK 100000000
49 
50 
53 
54 #define ASERVER_CMD_PROCESSED 0
55 #define ASERVER_CMD_FILE_OPEN 1
56 #define ASERVER_CMD_FILE_CLOSE 2
57 #define ASERVER_CMD_FILE_SEEK 3
58 
59 /* message passing structure */
60 typedef struct _aserver_message_t {
61  volatile int command;
62  volatile char *data;
63  volatile struct _aserver_message_t *next;
65 
66 typedef enum {
72 
73 typedef struct {
74  lives_operation_t operation; // read, write, or convert [readonly by server]
75  volatile boolean is_ready; // [readwrite all]
76  boolean eof;
77  int fileno; // [readonly by server]
78 
79  // readonly by server:
80 
81  // use one or other
82  off_t seek;
83  weed_timecode_t start_tc;
84 
85  int arate;
86 
87  ssize_t bytesize; // file in/out length in bytes [write by server in case of eof]
88 
89  boolean in_interleaf;
90  boolean out_interleaf;
91 
92  int in_achans;
93  int out_achans;
94  int in_asamps; // set to -val for float
95  int out_asamps; // set to -val for float
96  int swap_sign;
98  double shrink_factor;
99 
100  size_t samp_space;
101 
102  boolean sequential;
103 
104  // in or out buffers
105  uint8_t **buffer8;
106  union {
107  short **buffer16;
108  uint8_t **buffer16_8;
109  };
110  int32_t **buffer24;
111  int32_t **buffer32;
112  float **bufferf;
113 
114  // input values
115  boolean s8_signed;
116  boolean s16_signed;
117  boolean s24_signed;
118  boolean s32_signed;
119 
120  // ring buffer
121  volatile size_t samples_filled;
122  size_t start_sample;
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;
134  int _casamps;
135 
136  volatile boolean die;
138 
140 
141 typedef enum lives_audio_loop {
146 
147 float get_float_audio_val_at_time(int fnum, int afd, double secs, int chnum, int chans);
148 
149 void sample_silence_dS(float *dst, uint64_t nsamples);
150 
151 void sample_silence_stream(int nchans, int nframes);
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 float 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 {
189 
190 #ifdef ENABLE_JACK
191 void jack_rec_audio_to_clip(int fileno, int oldfileno, lives_rec_audio_type_t rec_type);
192 void jack_rec_audio_end(boolean close_dev, boolean close_fd);
193 #endif
194 
195 #ifdef HAVE_PULSE_AUDIO
196 void pulse_rec_audio_to_clip(int fileno, int oldfileno, lives_rec_audio_type_t rec_type);
197 void pulse_rec_audio_end(boolean close_dev, boolean close_fd);
198 #endif
199 
200 void fill_abuffer_from(lives_audio_buf_t *abuf, weed_plant_t *event_list, weed_plant_t *st_event, boolean exact);
201 
202 boolean resync_audio(int frameno);
203 
204 lives_audio_track_state_t *get_audio_and_effects_state_at(weed_plant_t *event_list, weed_plant_t *st_event, boolean get_audstate,
205  boolean exact);
206 
207 boolean get_audio_from_plugin(float *fbuffer, int nchans, int arate, int nsamps);
208 void reinit_audio_gen(void);
209 
210 void init_jack_audio_buffers(int achans, int arate, boolean exact);
211 void free_jack_audio_buffers(void);
212 
213 void init_pulse_audio_buffers(int achans, int arate, boolean exact);
214 void free_pulse_audio_buffers(void);
215 
216 void audio_free_fnames(void);
217 
218 boolean is_realtime_aplayer(int ptype);
219 
221 void audio_cache_end(void);
223 
224 boolean apply_rte_audio_init(void);
225 void apply_rte_audio_end(boolean del);
226 boolean apply_rte_audio(int nframes);
227 
228 void init_audio_frame_buffers(short aplayer);
230 void append_to_audio_bufferf(float *src, uint64_t nsamples, int channum);
231 void append_to_audio_buffer16(void *src, uint64_t nsamples, int channum);
232 boolean push_audio_to_channel(weed_plant_t *achan, lives_audio_buf_t *abuf);
233 
234 boolean start_audio_stream(void);
235 void stop_audio_stream(void);
236 void clear_audio_stream(void);
237 void audio_stream(void *buff, size_t nbytes, int fd);
238 
239 char *lives_get_audio_file_name(int fnum);
240 
241 char *get_achannel_name(int totchans, int idx) WARN_UNUSED;
242 const char *audio_player_get_display_name(const char *aplayer);
243 
245 #endif
Definition: audio.h:187
Definition: audio.h:182
int32_t ** buffer32
sample data in 32 bit format (or NULL)
Definition: audio.h:111
Definition: audio.h:142
Definition: audio.h:69
lives_audio_loop_t
Definition: audio.h:141
int _fd
file descriptor
Definition: audio.h:128
void fill_abuffer_from(lives_audio_buf_t *abuf, weed_plant_t *event_list, weed_plant_t *st_event, boolean exact)
Definition: audio.c:2014
int arate
Definition: audio.h:85
Definition: audio.h:68
float ** bufferf
sample data in float format (or NULL)
Definition: audio.h:112
int _cin_interleaf
Definition: audio.h:132
int out_achans
channels for buffer* side
Definition: audio.h:93
Definition: audio.h:73
void sample_move_float_float(float *dst, float *src, uint64_t nsamples, float scale, int dst_skip)
Definition: audio.c:597
size_t _csamp_space
current sample buffer size in single channel samples
Definition: audio.h:127
int swap_sign
Definition: audio.h:96
boolean eof
did we read EOF ? [readonly by client]
Definition: audio.h:76
short ** buffer16
sample data in 16 bit format (or NULL)
Definition: audio.h:107
int _cseek
current seek pos
Definition: audio.h:130
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:478
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:1048
boolean push_audio_to_channel(weed_plant_t *achan, lives_audio_buf_t *abuf)
Definition: audio.c:3048
ssize_t bytesize
Definition: audio.h:87
boolean float_deinterleave(float *fbuffer, int nsamps, int nchans)
Definition: audio.c:895
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:1931
volatile struct _aserver_message_t * next
Definition: audio.h:63
boolean in_interleaf
Definition: audio.h:89
lives_operation_t
Definition: audio.h:66
void audio_stream(void *buff, size_t nbytes, int fd)
Definition: audio.c:3326
boolean is_realtime_aplayer(int ptype)
Definition: audio.c:34
lives_audio_buf_t * audio_cache_get_buffer(void)
Definition: audio.c:2681
boolean resync_audio(int frameno)
Definition: audio.c:2269
boolean s8_signed
Definition: audio.h:115
void sample_move_d16_d16(short *dst, short *src, uint64_t nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_endian, int swap_sign)
boolean get_audio_from_plugin(float *fbuffer, int nchans, int arate, int nsamps)
Definition: audio.c:2690
volatile char * data
Definition: audio.h:62
Definition: audio.h:186
const char * audio_player_get_display_name(const char *aplayer)
Definition: audio.c:70
int64_t sample_move_float_int(void *holding_buff, float **float_buffer, int nsamps, float scale, int chans, int asamps, int usigned, boolean swap_endian, boolean float_interleaved, float vol)
returns frames output
Definition: audio.c:616
boolean start_audio_stream(void)
Definition: audio.c:3189
void apply_rte_audio_end(boolean del)
Definition: audio.c:2874
void sample_silence_stream(int nchans, int nframes)
Definition: audio.c:318
boolean s16_signed
Definition: audio.h:116
void reinit_audio_gen(void)
Definition: audio.c:2815
boolean out_interleaf
Definition: audio.h:90
volatile boolean die
set to TRUE to shut down thread
Definition: audio.h:136
int in_asamps
Definition: audio.h:94
boolean sequential
hint that we will read sequentially starting from seek
Definition: audio.h:102
ssize_t _cbytesize
current _filebuffer bytesize; if this changes we need to realloc _filebuffer
Definition: audio.h:126
void audio_cache_end(void)
Definition: audio.c:2647
int _cfileno
current fileno
Definition: audio.h:129
boolean s24_signed
Definition: audio.h:117
uint8_t ** buffer16_8
sample data in 8 bit format (or NULL)
Definition: audio.h:108
volatile int command
Definition: audio.h:61
void clear_audio_stream(void)
Definition: audio.c:3311
int64_t sample_move_abuf_float(float **obuf, int nchans, int nsamps, int out_arate, float vol)
Definition: audio.c:676
size_t start_sample
used for reading (readonly server)
Definition: audio.h:122
double shrink_factor
resampling ratio
Definition: audio.h:98
int64_t sample_move_abuf_int16(short *obuf, int nchans, int nsamps, int out_arate)
Definition: audio.c:778
int swap_endian
Definition: audio.h:97
Definition: audio.h:184
volatile size_t samples_filled
number of samples filled (readonly client)
Definition: audio.h:121
void init_pulse_audio_buffers(int achans, int arate, boolean exact)
Definition: audio.c:2205
char * lives_get_audio_file_name(int fnum)
Definition: audio.c:59
Definition: audio.h:183
Definition: main.h:350
int out_asamps
Definition: audio.h:95
Definition: audio.h:143
Definition: audio.h:144
lives_cancel_t handle_audio_timeout(void)
Definition: audio.c:3333
boolean float_interleave(float *fbuffer, int nsamps, int nchans)
Definition: audio.c:913
size_t samp_space
buffer space in samples (* by sizeof(type) to get bytesize) [if interleaf, also * by chans] ...
Definition: audio.h:100
int _casamps
current out_asamps
Definition: audio.h:134
uint8_t * _filebuffer
raw data to/from file - can be cast to int16_t
Definition: audio.h:125
void aud_fade(int fileno, double startt, double endt, double startv, double endv)
fade in/fade out
Definition: audio.c:1519
char * get_achannel_name(int totchans, int idx) WARN_UNUSED
Definition: audio.c:49
void audio_free_fnames(void)
Definition: audio.c:76
boolean apply_rte_audio(int nframes)
Definition: audio.c:2881
float get_float_audio_val_at_time(int fnum, int afd, double secs, int chnum, int chans)
Definition: audio.c:259
void init_audio_frame_buffers(short aplayer)
Definition: audio.c:164
void free_jack_audio_buffers(void)
Definition: audio.c:2225
void append_to_audio_bufferf(float *src, uint64_t nsamples, int channum)
Definition: audio.c:91
int in_achans
channels for _filebuffer side
Definition: audio.h:92
lives_rec_audio_type_t
Definition: audio.h:181
Definition: audio.h:60
void free_audio_frame_buffer(lives_audio_buf_t *abuf)
Definition: audio.c:219
int _cachans
current output channels
Definition: audio.h:131
boolean s32_signed
Definition: audio.h:118
void sample_silence_dS(float *dst, uint64_t nsamples)
Definition: audio.c:312
uint8_t ** buffer8
sample data in 8 bit format (or NULL)
Definition: audio.h:105
boolean apply_rte_audio_init(void)
Definition: audio.c:2840
int _cout_interleaf
Definition: audio.h:133
lives_cancel_t
cancel reason
Definition: main.h:415
lives_audio_buf_t * audio_cache_init(void)
Definition: audio.c:2613
lives_operation_t operation
Definition: audio.h:74
Definition: audio.h:185
void append_to_audio_buffer16(void *src, uint64_t nsamples, int channum)
Definition: audio.c:127
int fileno
Definition: audio.h:77
int32_t ** buffer24
sample data in 24 bit format (or NULL)
Definition: audio.h:110
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: audio.c:530
volatile boolean is_ready
Definition: audio.h:75
Definition: audio.h:67
Definition: audio.h:70
#define WARN_UNUSED
Definition: main.h:262
weed_timecode_t start_tc
Definition: audio.h:83
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:342
void init_jack_audio_buffers(int achans, int arate, boolean exact)
Definition: audio.c:2183
off_t seek
Definition: audio.h:82
void stop_audio_stream(void)
Definition: audio.c:3268
void free_pulse_audio_buffers(void)
Definition: audio.c:2248