2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on the
14 static int OAL_capture_recording = 0;
16 struct capture_buffer {
17 uint samples_per_second;
26 static capture_buffer Capture;
28 static ALCdevice *al_capture_device = NULL;
31 void oal_capture_release_buffer()
33 if (al_capture_device != NULL) {
34 alcCaptureCloseDevice(al_capture_device);
35 al_capture_device = NULL;
39 // create a capture buffer with the specified format
40 // exit: 0 -> buffer created successfully
41 // !0 -> error creating the buffer
42 int oal_capture_create_buffer(int freq, int bits_per_sample, int nchannels, int nseconds)
44 ALenum al_format = AL_FORMAT_MONO8;
45 ALsizei buf_size = freq * nseconds;
47 SDL_assert( (nchannels == 1) || (nchannels == 2) );
48 SDL_assert( (bits_per_sample == 8) || (bits_per_sample == 16) );
50 if ( !oal_is_initted() ) {
55 if (bits_per_sample == 8) {
56 al_format = AL_FORMAT_MONO8;
57 } else if (bits_per_sample == 16) {
58 al_format = AL_FORMAT_MONO16;
60 } else if (nchannels == 2) {
61 if (bits_per_sample == 8) {
62 al_format = AL_FORMAT_STEREO8;
63 } else if (bits_per_sample == 16) {
64 al_format = AL_FORMAT_STEREO16;
68 al_capture_device = alcCaptureOpenDevice(NULL, freq, al_format, buf_size);
70 if (al_capture_device == NULL) {
74 if ( alcGetError(al_capture_device) != ALC_NO_ERROR ) {
78 Capture.format = al_format;
79 Capture.bits_per_sample = bits_per_sample;
80 Capture.n_channels = nchannels;
81 Capture.samples_per_second = freq;
82 Capture.block_align = (nchannels * bits_per_sample) / 8;
87 int oal_capture_supported()
89 return oal_is_initted();
92 // start recording into the buffer
93 int oal_capture_start_record()
95 if ( !oal_is_initted() ) {
99 if (OAL_capture_recording) {
103 alcCaptureStart(al_capture_device);
105 OAL_capture_recording = 1;
107 // nprintf(("Alan","RTVOICE => start record\n"));
112 // stop recording into the buffer
113 int oal_capture_stop_record()
115 if ( !oal_is_initted() ) {
119 if ( !OAL_capture_recording ) {
123 alcCaptureStop(al_capture_device);
125 OAL_capture_recording = 0;
127 // nprintf(("Alan","RTVOICE => stop record\n"));
132 void oal_capture_close()
134 oal_capture_stop_record();
136 if (al_capture_device != NULL) {
137 alcCaptureCloseDevice(al_capture_device);
138 al_capture_device = NULL;
142 // return the max buffer size
143 int oal_capture_max_buffersize()
145 if ( !oal_is_initted() ) {
149 ALCsizei num_samples = 0;
151 alcGetIntegerv(al_capture_device, ALC_CAPTURE_SAMPLES, sizeof(ALCsizei), &num_samples);
153 if (alcGetError(al_capture_device) != ALC_NO_ERROR) {
157 return (num_samples * Capture.block_align);
160 // retrieve the recorded voice data
161 int oal_capture_get_raw_data(ubyte *outbuf, uint max_size)
163 if ( !oal_is_initted() ) {
167 if (outbuf == NULL) {
171 ALCsizei num_samples = 0;
173 alcGetIntegerv(al_capture_device, ALC_CAPTURE_SAMPLES, sizeof(ALCsizei), &num_samples);
175 if (num_samples <= 0) {
179 ALCsizei max_buf_size = min(num_samples, ALsizei(max_size / Capture.block_align));
181 alcCaptureSamples(al_capture_device, outbuf, max_buf_size);
183 if (alcGetError(al_capture_device) != ALC_NO_ERROR) {
187 return (int)max_buf_size * Capture.block_align;