6 #include "audiodevice.h"
8 #include "audioesound.h"
11 #include "condition.h"
14 #include "playbackconfig.h"
15 #include "preferences.h"
16 #include "recordconfig.h"
20 AudioLowLevel::AudioLowLevel(AudioDevice *device)
22 this->device = device;
25 AudioLowLevel::~AudioLowLevel()
34 AudioDevice::AudioDevice(MWindow *mwindow)
38 this->mwindow = mwindow;
39 this->out_config = new AudioOutConfig(0);
40 this->in_config = new AudioInConfig;
41 this->vconfig = new VideoInConfig;
42 startup_lock = new Condition(0, "AudioDevice::startup_lock");
43 duplex_lock = new Condition(0, "AudioDevice::duplex_lock");
44 timer_lock = new Mutex("AudioDevice::timer_lock");
45 buffer_lock = new Mutex("AudioDevice::buffer_lock");
46 polling_lock = new Condition(0, "AudioDevice::polling_lock");
47 playback_timer = new Timer;
48 record_timer = new Timer;
49 for(int i = 0; i < TOTAL_BUFFERS; i++)
51 play_lock[i] = new Sema(0, "AudioDevice::play_lock");
52 arm_lock[i] = new Sema(1, "AudioDevice::arm_lock");
56 AudioDevice::~AudioDevice()
64 for(int i = 0; i < TOTAL_BUFFERS; i++)
69 delete playback_timer;
75 int AudioDevice::initialize()
77 record_before_play = 0;
80 for(int i = 0; i < TOTAL_BUFFERS; i++)
89 rec_dither = play_dither = 0;
90 software_position_info = 0;
96 position_correction = 0;
99 lowlevel_in = lowlevel_out = lowlevel_duplex = 0;
102 total_samples_read = 0;
110 int AudioDevice::create_lowlevel(AudioLowLevel* &lowlevel, int driver)
112 this->driver = driver;
121 case AUDIO_OSS_ENVY24:
122 lowlevel = new AudioOSS(this);
128 lowlevel = new AudioESound(this);
136 lowlevel = new AudioALSA(this);
144 lowlevel = new Audio1394(this);
151 lowlevel = new AudioDVB(this);
157 lowlevel = new AudioCine(this);
164 int AudioDevice::open_input(AudioInConfig *config,
165 VideoInConfig *vconfig,
173 this->in_config->copy_from(config);
174 this->vconfig->copy_from(vconfig);
175 in_samplerate = rate;
176 in_samples = samples;
177 in_realtime = realtime;
178 in_channels = channels;
179 create_lowlevel(lowlevel_in, config->driver);
180 lowlevel_in->open_input();
181 record_timer->update();
185 int AudioDevice::open_output(AudioOutConfig *config,
193 *this->out_config = *config;
194 out_samplerate = rate;
195 out_samples = samples;
196 out_channels = channels;
197 out_realtime = realtime;
198 create_lowlevel(lowlevel_out, config->driver);
199 return lowlevel_out ? lowlevel_out->open_output() : 0;
203 int AudioDevice::interrupt_crash()
205 if(lowlevel_in) return lowlevel_in->interrupt_crash();
210 int AudioDevice::close_all()
220 if(lowlevel_in) lowlevel_in->close_all();
221 if(lowlevel_out) lowlevel_out->close_all();
222 if(lowlevel_duplex) lowlevel_duplex->close_all();
225 for(int i = 0; i < TOTAL_BUFFERS; i++)
227 delete [] input_buffer[i];
232 rec_dither = play_dither = 0;
233 software_position_info = position_correction = last_buffer_size = 0;
253 delete lowlevel_duplex;
260 int AudioDevice::set_vdevice(VideoDevice *vdevice)
262 this->vdevice = vdevice;
267 int AudioDevice::get_ichannels()
269 if(r) return in_channels;
270 else if(d) return duplex_channels;
274 int AudioDevice::get_ibits()
276 if(r) return in_bits;
277 else if(d) return duplex_bits;
282 int AudioDevice::get_obits()
284 if(w) return out_bits;
285 else if(d) return duplex_bits;
289 int AudioDevice::get_ochannels()
291 if(w) return out_channels;
292 else if(d) return duplex_channels;
296 AudioLowLevel* AudioDevice::get_lowlevel_out()
298 if(w) return lowlevel_out;
299 else if(d) return lowlevel_duplex;
303 AudioLowLevel* AudioDevice::get_lowlevel_in()
305 if(r) return lowlevel_in;
306 else if(d) return lowlevel_duplex;
310 int AudioDevice::get_irate()
312 if(r) return in_samplerate;
314 if(d) return duplex_samplerate;
317 int AudioDevice::get_orealtime()
319 if(w) return out_realtime;
321 if(d) return duplex_realtime;
325 int AudioDevice::get_irealtime()
327 if(r) return in_realtime;
329 if(d) return duplex_realtime;
334 int AudioDevice::get_orate()
336 if(w) return out_samplerate;
337 else if(d) return duplex_samplerate;
341 int AudioDevice::get_interrupted()
346 int AudioDevice::get_device_buffer()
348 return device_buffer;
361 void AudioDevice::run()
373 // c-file-style: "linux"