3 #include "audioconfig.h"
4 #include "audiodevice.h"
5 #include "audioesound.h"
10 #include "playbackconfig.h"
11 #include "preferences.h"
12 #include "recordconfig.h"
17 AudioLowLevel::AudioLowLevel(AudioDevice *device)
19 this->device = device;
22 AudioLowLevel::~AudioLowLevel()
31 AudioDevice::AudioDevice()
35 this->out_config = new AudioOutConfig(0);
36 this->in_config = new AudioInConfig;
37 this->vconfig = new VideoInConfig;
38 startup_lock = new Condition(0, "AudioDevice::startup_lock");
39 duplex_lock = new Condition(0, "AudioDevice::duplex_lock");
40 timer_lock = new Mutex("AudioDevice::timer_lock");
41 for(int i = 0; i < TOTAL_BUFFERS; i++)
43 play_lock[i] = new Sema(0, "AudioDevice::play_lock");
44 arm_lock[i] = new Sema(1, "AudioDevice::arm_lock");
46 dc_offset_thread = new DC_Offset;
49 AudioDevice::~AudioDevice()
57 for(int i = 0; i < TOTAL_BUFFERS; i++)
62 delete dc_offset_thread;
65 int AudioDevice::initialize()
67 record_before_play = 0;
70 for(int i = 0; i < TOTAL_BUFFERS; i++)
79 rec_dither = play_dither = 0;
80 software_position_info = 0;
84 last_buffer_size = total_samples = position_correction = 0;
87 lowlevel_in = lowlevel_out = lowlevel_duplex = 0;
90 total_samples_read = 0;
96 int AudioDevice::create_lowlevel(AudioLowLevel* &lowlevel, int driver)
98 this->driver = driver;
107 case AUDIO_OSS_ENVY24:
108 lowlevel = new AudioOSS(this);
114 lowlevel = new AudioESound(this);
122 lowlevel = new AudioALSA(this);
129 lowlevel = new Audio1394(this);
137 int AudioDevice::open_input(AudioInConfig *config,
138 VideoInConfig *vconfig,
144 this->in_config->copy_from(config);
145 this->vconfig->copy_from(vconfig);
146 //printf("AudioDevice::open_input %s\n", this->in_config->oss_in_device[0]);
147 in_samplerate = rate;
148 in_samples = samples;
149 create_lowlevel(lowlevel_in, config->driver);
150 lowlevel_in->open_input();
151 record_timer.update();
155 int AudioDevice::open_output(AudioOutConfig *config, int rate, int samples, int realtime)
159 *this->out_config = *config;
160 out_samplerate = rate;
161 out_samples = samples;
162 out_realtime = realtime;
163 create_lowlevel(lowlevel_out, config->driver);
164 lowlevel_out->open_output();
168 int AudioDevice::open_duplex(AudioOutConfig *out_config, int rate, int samples, int realtime)
171 duplex_init = 1; // notify playback routines to test the duplex lock
172 *this->out_config = *out_config;
173 duplex_samplerate = rate;
174 duplex_samples = samples;
176 duplex_realtime = realtime;
177 for(int i = 0; i < MAXDEVICES; i++)
179 duplex_channels += out_config->oss_out_channels[i];
181 create_lowlevel(lowlevel_duplex, out_config->driver);
182 lowlevel_duplex->open_duplex();
183 playback_timer.update();
184 record_timer.update();
189 int AudioDevice::interrupt_crash()
191 if(lowlevel_in) return lowlevel_in->interrupt_crash();
196 int AudioDevice::close_all()
198 if(lowlevel_in) lowlevel_in->close_all();
199 if(lowlevel_out) lowlevel_out->close_all();
200 if(lowlevel_duplex) lowlevel_duplex->close_all();
205 delete [] input_buffer;
210 rec_dither = play_dither = 0;
211 software_position_info = position_correction = last_buffer_size = 0;
229 delete lowlevel_duplex;
235 int AudioDevice::set_vdevice(VideoDevice *vdevice)
237 this->vdevice = vdevice;
242 int AudioDevice::get_ichannels()
244 if(r) return in_channels;
245 else if(d) return duplex_channels;
249 int AudioDevice::get_ibits()
251 if(r) return in_bits;
252 else if(d) return duplex_bits;
257 int AudioDevice::get_obits()
259 if(w) return out_bits;
260 else if(d) return duplex_bits;
264 int AudioDevice::get_ochannels()
266 if(w) return out_channels;
267 else if(d) return duplex_channels;
271 AudioLowLevel* AudioDevice::get_lowlevel_out()
273 if(w) return lowlevel_out;
274 else if(d) return lowlevel_duplex;
278 AudioLowLevel* AudioDevice::get_lowlevel_in()
280 if(r) return lowlevel_in;
281 else if(d) return lowlevel_duplex;
285 int AudioDevice::get_irate()
287 if(r) return in_samplerate;
289 if(d) return duplex_samplerate;
292 int AudioDevice::get_orealtime()
294 if(w) return out_realtime;
295 else if(d) return duplex_realtime;
300 int AudioDevice::get_orate()
302 if(w) return out_samplerate;
303 else if(d) return duplex_samplerate;
307 int AudioDevice::get_interrupted()
312 int AudioDevice::get_device_buffer()
314 return device_buffer;