2 #include "audioconfig.h"
3 #include "audiodevice.h"
5 #include "audioesound.h"
8 #include "playbackconfig.h"
9 #include "preferences.h"
10 #include "recordconfig.h"
15 AudioLowLevel::AudioLowLevel(AudioDevice *device)
17 this->device = device;
20 AudioLowLevel::~AudioLowLevel()
29 AudioDevice::AudioDevice()
33 this->out_config = new AudioOutConfig(0, 0, 0);
34 this->in_config = new AudioInConfig;
37 AudioDevice::~AudioDevice()
43 int AudioDevice::initialize()
45 record_before_play = 0;
48 for(int i = 0; i < TOTAL_BUFFERS; i++)
58 rec_dither = play_dither = 0;
59 software_position_info = 0;
63 last_buffer_size = total_samples = position_correction = 0;
65 dc_offset_thread = new DC_Offset;
67 lowlevel_in = lowlevel_out = lowlevel_duplex = 0;
70 total_samples_read = 0;
76 int AudioDevice::create_lowlevel(AudioLowLevel* &lowlevel, int driver)
78 this->driver = driver;
86 case AUDIO_OSS_ENVY24:
87 lowlevel = new AudioOSS(this);
93 lowlevel = new AudioESound(this);
101 lowlevel = new AudioALSA(this);
107 lowlevel = new Audio1394(this);
115 int AudioDevice::open_input(AudioInConfig *config, int rate, int samples)
119 *this->in_config = *config;
120 //printf("AudioDevice::open_input %s\n", this->in_config->oss_in_device[0]);
121 in_samplerate = rate;
122 in_samples = samples;
123 create_lowlevel(lowlevel_in, config->driver);
124 lowlevel_in->open_input();
125 record_timer.update();
129 int AudioDevice::open_output(AudioOutConfig *config, int rate, int samples, int realtime)
133 *this->out_config = *config;
134 out_samplerate = rate;
135 out_samples = samples;
136 out_realtime = realtime;
137 create_lowlevel(lowlevel_out, config->driver);
138 lowlevel_out->open_output();
142 int AudioDevice::open_duplex(AudioOutConfig *out_config, int rate, int samples, int realtime)
145 duplex_init = 1; // notify playback routines to test the duplex lock
146 *this->out_config = *out_config;
147 duplex_samplerate = rate;
148 duplex_samples = samples;
150 duplex_realtime = realtime;
151 for(int i = 0; i < MAXDEVICES; i++)
153 duplex_channels += out_config->oss_out_channels[i];
155 duplex_lock.lock(); // prevent playback until recording starts
156 create_lowlevel(lowlevel_duplex, out_config->driver);
157 lowlevel_duplex->open_duplex();
158 playback_timer.update();
159 record_timer.update();
164 int AudioDevice::interrupt_crash()
166 if(lowlevel_in) return lowlevel_in->interrupt_crash();
171 int AudioDevice::close_all()
173 if(lowlevel_in) lowlevel_in->close_all();
174 if(lowlevel_out) lowlevel_out->close_all();
175 if(lowlevel_duplex) lowlevel_duplex->close_all();
180 delete [] input_buffer;
185 rec_dither = play_dither = 0;
186 software_position_info = position_correction = last_buffer_size = 0;
204 delete lowlevel_duplex;
210 int AudioDevice::set_vdevice(VideoDevice *vdevice)
212 this->vdevice = vdevice;
217 int AudioDevice::get_ichannels()
219 if(r) return in_channels;
220 else if(d) return duplex_channels;
224 int AudioDevice::get_ibits()
226 if(r) return in_bits;
227 else if(d) return duplex_bits;
232 int AudioDevice::get_obits()
234 if(w) return out_bits;
235 else if(d) return duplex_bits;
239 int AudioDevice::get_ochannels()
241 if(w) return out_channels;
242 else if(d) return duplex_channels;
246 AudioLowLevel* AudioDevice::get_lowlevel_out()
248 if(w) return lowlevel_out;
249 else if(d) return lowlevel_duplex;
253 AudioLowLevel* AudioDevice::get_lowlevel_in()
255 if(r) return lowlevel_in;
256 else if(d) return lowlevel_duplex;
260 int AudioDevice::get_irate()
262 if(r) return in_samplerate;
264 if(d) return duplex_samplerate;
267 int AudioDevice::get_orealtime()
269 if(w) return out_realtime;
270 else if(d) return duplex_realtime;
275 int AudioDevice::get_orate()
277 if(w) return out_samplerate;
278 else if(d) return duplex_samplerate;
282 int AudioDevice::get_interrupted()
287 int AudioDevice::get_device_buffer()
289 return device_buffer;