27 #define MAX_RTV_FORMATS 5
37 static int Rtv_recording_format;
38 static int Rtv_playback_format;
40 #define RTV_BUFFER_TIME 8 // length of buffer in seconds
42 static int Rtv_recording_inited=0;
43 static int Rtv_playback_inited=0;
45 static int Rtv_recording=0;
47 #define MAX_RTV_OUT_BUFFERS 1
48 #define RTV_OUT_FLAG_USED (1<<0)
60 static int Rtv_record_timer_id;
62 static SDL_TimerID Rtv_record_timer_id;
64 static int Rtv_callback_time;
69 static unsigned char *Rtv_capture_raw_buffer;
70 static unsigned char *Rtv_capture_compressed_buffer;
72 static int Rtv_capture_raw_buffer_size;
75 static unsigned char *Rtv_playback_uncompressed_buffer;
76 static int Rtv_playback_uncompressed_buffer_size;
83 void CALLBACK TimeProc(
unsigned int id,
unsigned int msg,
unsigned long userdata,
unsigned long dw1,
unsigned long dw2)
89 nprintf((
"Alan",
"In callback\n"));
96 SDL_RemoveTimer(Rtv_record_timer_id);
97 Rtv_record_timer_id = NULL;
105 if (Rtv_callback_time) {
108 SDL_RemoveTimer(Rtv_record_timer_id);
109 Rtv_record_timer_id = NULL;
127 Rtv_recording_format=
i;
132 if ( i == MAX_RTV_FORMATS ) {
152 if ( !Rtv_recording_inited ) {
157 Rtv_capture_raw_buffer_size = Rtv_formats[Rtv_recording_format].
frequency * (
RTV_BUFFER_TIME) *
fl2i(Rtv_formats[Rtv_recording_format].bits_per_sample/8.0
f);
164 if ( Rtv_capture_raw_buffer ) {
165 vm_free(Rtv_capture_raw_buffer);
166 Rtv_capture_raw_buffer=NULL;
168 Rtv_capture_raw_buffer = (
unsigned char*)
vm_malloc(Rtv_capture_raw_buffer_size);
171 if ( Rtv_capture_compressed_buffer ) {
172 vm_free(Rtv_capture_compressed_buffer);
173 Rtv_capture_compressed_buffer=NULL;
175 Rtv_capture_compressed_buffer_size=Rtv_capture_raw_buffer_size;
176 Rtv_capture_compressed_buffer = (
unsigned char*)
vm_malloc(Rtv_capture_compressed_buffer_size);
178 Rtv_recording_inited=1;
189 if ( !Rtv_recording ) {
195 if ( Rtv_record_timer_id ) {
197 SDL_RemoveTimer(Rtv_record_timer_id);
198 Rtv_record_timer_id = NULL;
200 timeKillEvent(Rtv_record_timer_id);
201 Rtv_record_timer_id = 0;
211 if ( Rtv_recording ) {
215 if ( Rtv_capture_raw_buffer ) {
216 vm_free(Rtv_capture_raw_buffer);
217 Rtv_capture_raw_buffer=NULL;
220 if ( Rtv_capture_compressed_buffer ) {
221 vm_free(Rtv_capture_compressed_buffer);
222 Rtv_capture_compressed_buffer=NULL;
227 Rtv_recording_inited=0;
239 Assert(Rtv_recording_inited);
241 if ( Rtv_recording ) {
249 if ( user_callback ) {
251 Rtv_record_timer_id = SDL_AddTimer(callback_time,
TimeProc, NULL);
253 Rtv_record_timer_id = timeSetEvent(callback_time, callback_time,
TimeProc, 0, TIME_PERIODIC);
255 if ( !Rtv_record_timer_id ) {
260 Rtv_callback_time = callback_time;
263 Rtv_record_timer_id = 0;
292 *outbuf = Rtv_capture_raw_buffer;
300 void rtvoice_uncompress(
unsigned char *data_in,
int size_in,
double gain,
unsigned char *data_out,
int size_out)
302 if ( (data_in == NULL) || (size_in <= 0) ) {
310 if ( Rtv_playback_uncompressed_buffer ) {
311 vm_free(Rtv_playback_uncompressed_buffer);
312 Rtv_playback_uncompressed_buffer=NULL;
315 Rtv_playback_inited=0;
324 Rtv_output_buffers[
i].
flags=0;
336 if ( !Rtv_playback_inited ) {
340 Rtv_playback_format=0;
341 rtvf = &Rtv_formats[Rtv_playback_format];
343 if ( Rtv_playback_uncompressed_buffer ) {
344 vm_free(Rtv_playback_uncompressed_buffer);
345 Rtv_playback_uncompressed_buffer=NULL;
349 Rtv_playback_uncompressed_buffer = (
unsigned char*)
vm_malloc(Rtv_playback_uncompressed_buffer_size);
350 Assert(Rtv_playback_uncompressed_buffer);
352 Rtv_playback_inited=1;
368 if ( i == MAX_RTV_OUT_BUFFERS ) {
383 rtvf = &Rtv_formats[Rtv_playback_format];
392 if ( Rtv_output_buffers[index].ds_handle == -1 ) {
404 if ( Rtv_output_buffers[index].ds_handle != -1 ) {
426 if ( Rtv_output_buffers[index].ds_handle != -1 ) {
int rtvoice_init_recording(int qos)
void rtvoice_free_playback_buffer(int index)
int dscap_max_buffersize()
int rtvoice_init_playback()
int ds_play(int sid, int snd_id, int priority, const EnhancedSoundData *enhanced_sound_data, float volume, float pan, int looping, bool is_voice_msg)
void rtvoice_stop_recording()
void rtvoice_get_data(unsigned char **outbuf, int *size, double *gain)
#define RTV_OUT_FLAG_USED
void rtvoice_set_qos(int qos)
int rtvoice_find_free_output_buffer()
void dscap_release_buffer()
int ds_create_buffer(int frequency, int bits_per_sample, int nchannels, int nseconds)
void rtvoice_close_recording()
int rtvoice_play(int index, unsigned char *data, int size)
int dscap_get_raw_data(unsigned char *outbuf, unsigned int max_size)
int dscap_create_buffer(int freq, int bits_per_sample, int nchannels, int nseconds)
void rtvoice_stop_playback(int index)
void rtvoice_uncompress(unsigned char *data_in, int size_in, double gain, unsigned char *data_out, int size_out)
Uint32 CALLBACK TimeProc(Uint32 interval, void *param)
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
int rtvoice_pick_record_format()
const unsigned int SND_ENHANCED_MAX_LIMIT
void rtvoice_close_playback()
void rtvoice_reset_out_buffers()
GLenum GLsizei GLenum GLenum const GLvoid * data
void ds_stop_easy(int sid)
int rtvoice_create_playback_buffer()
void rtvoice_stop_playback_all()
#define MAX_RTV_OUT_BUFFERS
void ds_unload_buffer(int sid)
int ds_lock_data(int sid, unsigned char *data, int size)
int rtvoice_start_recording(void(*user_callback)(), int callback_time)
struct rtv_format rtv_format
float Master_voice_volume
struct rtv_out_buffer rtv_out_buffer