LiVES 1.4.9
|
00001 // audio.h 00002 // LiVES (lives-exe) 00003 // (c) G. Finch 2005 - 2009 00004 // Released under the GPL 3 or later 00005 // see file ../COPYING for licensing details 00006 00007 #ifndef _HAS_LIVES_AUDIO_H 00008 #define _HAS_LIVES_AUDIO_H 00009 00010 #define SAMPLE_MAX_16BIT_P 32767.0f 00011 #define SAMPLE_MAX_16BIT_N 32768.0f 00012 #define SAMPLE_MAX_16BITI 32768 00013 00015 #define SWAP_U_TO_S 1 ///< unsigned to signed 00016 #define SWAP_S_TO_U 2 ///< signed to unsigned 00017 00019 #define SWAP_X_TO_L 1 ///< other to local 00020 #define SWAP_L_TO_X 2 ///< local to other 00021 00022 00024 # define DEFAULT_AUDIO_RATE 44100 00025 # define DEFAULT_AUDIO_CHANS 2 00026 # define DEFAULT_AUDIO_SAMPS 16 00027 # define DEFAULT_AUDIO_SIGNED8 (AFORM_UNSIGNED) 00028 # define DEFAULT_AUDIO_SIGNED16 !(AFORM_UNSIGNED) 00029 00030 00032 #define MAX_AUDIO_MEM 8*1024*1024 00033 00035 #define RENDER_BLOCK_SIZE 1024 00036 00038 #define SILENCE_BLOCK_SIZE 65536 00039 00041 #define READ_BLOCK_SIZE 4096 00042 00044 #define XSAMPLES 128000 00045 00046 00049 00050 00051 #define ASERVER_CMD_PROCESSED 0 00052 #define ASERVER_CMD_FILE_OPEN 1 00053 #define ASERVER_CMD_FILE_CLOSE 2 00054 #define ASERVER_CMD_FILE_SEEK 3 00055 00056 /* message passing structure */ 00057 typedef struct _aserver_message_t { 00058 gint command; 00059 gchar *data; 00060 volatile struct _aserver_message_t *next; 00061 } aserver_message_t; 00062 00063 00064 00065 typedef enum { 00066 LIVES_NOP_OPERATION=0, 00067 LIVES_READ_OPERATION, 00068 LIVES_WRITE_OPERATION, 00069 LIVES_CONVERT_OPERATION 00070 } lives_operation_t; 00071 00072 00073 00074 00075 typedef struct { 00076 lives_operation_t operation; // read, write, or convert [readonly by server] 00077 volatile gboolean is_ready; // [readwrite all] 00078 gboolean eof; 00079 int fileno; // [readonly by server] 00080 00081 // readonly by server: 00082 00083 // use one or other 00084 off_t seek; 00085 weed_timecode_t start_tc; 00086 00087 double arate; 00088 00089 size_t bytesize; // file in/out length in bytes [write by server in case of eof] 00090 00091 gboolean in_interleaf; 00092 gboolean out_interleaf; 00093 00094 int in_achans; 00095 int out_achans; 00096 int in_asamps; // set to -val for float 00097 int out_asamps; // set to -val for float 00098 int swap_sign; 00099 int swap_endian; 00100 double shrink_factor; 00101 00102 size_t samp_space; 00103 00104 00105 // in or out buffers 00106 uint8_t **buffer8; 00107 short **buffer16; 00108 int32_t **buffer24; 00109 int32_t **buffer32; 00110 float **bufferf; 00111 00112 00113 // ring buffer 00114 size_t samples_filled; 00115 size_t start_sample; 00116 00117 00118 // private fields (used by server) 00119 uint8_t *_filebuffer; 00120 size_t _cbytesize; 00121 size_t _csamp_space; 00122 int _fd; 00123 int _cfileno; 00124 int _cseek; 00125 int _cachans; 00126 int _cin_interleaf; 00127 int _cout_interleaf; 00128 int _casamps; 00129 00130 volatile gboolean die; 00131 00132 } lives_audio_buf_t; 00133 00134 00136 00137 typedef enum lives_audio_loop { 00138 AUDIO_LOOP_NONE, 00139 AUDIO_LOOP_FORWARD, 00140 AUDIO_LOOP_PINGPONG 00141 } lives_audio_loop_t; 00142 00143 00144 00145 void sample_silence_dS (float *dst, unsigned long nsamples); 00146 00147 void sample_move_d8_d16(short *dst, guchar *src, 00148 unsigned long nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_sign); 00149 00150 void sample_move_d16_d16(short *dst, short *src, 00151 unsigned long nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_endian, int swap_sign); 00152 00153 void sample_move_d16_d8(uint8_t *dst, short *src, 00154 unsigned long nsamples, size_t tbytes, float scale, int nDstChannels, int nSrcChannels, int swap_sign); 00155 00156 void sample_move_d16_float (float *dst, short *src, unsigned long nsamples, unsigned long src_skip, int is_unsigned, float vol); 00157 00158 long sample_move_float_int(void *holding_buff, float **float_buffer, int nsamps, float scale, int chans, int asamps, int usigned, gboolean swap_endian, float vol); 00159 00160 long sample_move_abuf_float (float **obuf, int nchans, int nsamps, int out_arate, float vol); 00161 00162 long sample_move_abuf_int16 (short *obuf, int nchans, int nsamps, int out_arate); 00163 00164 long render_audio_segment(gint nfiles, gint *from_files, gint to_file, gdouble *avels, gdouble *fromtime, weed_timecode_t tc_start, weed_timecode_t tc_end, gdouble *chvol, gdouble opvol_start, gdouble opvol_end, lives_audio_buf_t *obuf); 00165 00166 void aud_fade(gint fileno, gdouble startt, gdouble endt, gdouble startv, gdouble endv); 00167 00168 00169 #define RECA_WINDOW_GRAB 1 00170 #define RECA_NEW_CLIP 2 00171 #define RECA_EXISTING 3 00172 00173 00174 #ifdef ENABLE_JACK 00175 void jack_rec_audio_to_clip(gint fileno, gint oldfileno, gshort rec_type); 00176 void jack_rec_audio_end(void); 00177 #endif 00178 00179 #ifdef HAVE_PULSE_AUDIO 00180 void pulse_rec_audio_to_clip(gint fileno, gint oldfileno, gshort rec_type); 00181 void pulse_rec_audio_end(void); 00182 #endif 00183 00184 void fill_abuffer_from(lives_audio_buf_t *abuf, weed_plant_t *event_list, weed_plant_t *st_event, gboolean exact); 00185 00186 00187 gboolean resync_audio(gint frameno); 00188 00189 00190 lives_audio_track_state_t *get_audio_and_effects_state_at(weed_plant_t *event_list, weed_plant_t *st_event, gboolean get_audstate, gboolean exact); 00191 00192 00193 void init_jack_audio_buffers (gint achans, gint arate, gboolean exact); 00194 void free_jack_audio_buffers(void); 00195 00196 void init_pulse_audio_buffers (gint achans, gint arate, gboolean exact); 00197 void free_pulse_audio_buffers(void); 00198 00199 void audio_free_fnames(void); 00200 00201 lives_audio_buf_t *audio_cache_init (void); 00202 void audio_cache_end (void); 00203 lives_audio_buf_t *audio_cache_get_buffer(void); 00204 00205 gboolean start_audio_stream(void); 00206 void stop_audio_stream(void); 00207 void clear_audio_stream(void); 00208 LIVES_INLINE void audio_stream(void *buff, size_t nbytes, int fd); 00209 00210 #endif