10 #include "audioalsa.inc"
11 #include "audioconfig.inc"
12 #include "audiodvb.inc"
13 #include "audiodevice.inc"
14 #include "audioesound.inc"
15 #include "audiooss.inc"
16 #include "bctimer.inc"
18 #include "condition.inc"
19 #include "dcoffset.inc"
20 #include "device1394output.inc"
21 #include "maxchannels.h"
23 #include "mwindow.inc"
24 #include "preferences.inc"
25 #include "recordgui.inc"
28 #include "videodevice.inc"
30 #include "audio1394.inc"
31 #include "device1394output.inc"
32 #include "vdevice1394.inc"
38 AudioLowLevel(AudioDevice
*device
);
39 virtual ~AudioLowLevel();
41 virtual int open_input() { return 1; };
42 virtual int open_output() { return 1; };
43 virtual int open_duplex() { return 1; };
44 virtual int close_all() { return 1; };
45 virtual int interrupt_crash() { return 0; };
46 virtual int64_t device_position() { return -1; };
47 virtual int write_buffer(char *buffer
, int size
) { return 1; };
48 virtual int read_buffer(char *buffer
, int size
) { return 1; };
49 virtual int flush_device() { return 1; };
50 virtual int interrupt_playback() { return 1; };
56 class AudioDevice
: public Thread
59 // MWindow is required where global input is used, to get the pointer.
60 AudioDevice(MWindow
*mwindow
= 0);
63 friend class AudioALSA
;
64 friend class AudioDVB
;
65 friend class AudioOSS
;
66 friend class AudioESound
;
67 friend class Audio1394
;
68 friend class VDevice1394
;
69 friend class Device1394Output
;
71 int open_input(AudioInConfig
*config
,
72 VideoInConfig
*vconfig
,
77 int open_output(AudioOutConfig
*config
,
86 // Specify a video device to pass data to if the same device handles video
87 int set_vdevice(VideoDevice
*vdevice
);
89 // ================================ recording
91 // read from the record device
92 // Conversion between double and int is done in AudioDevice
93 int read_buffer(double **input
,
97 int input_offset
= 0);
98 int set_record_dither(int value
);
100 void start_recording();
101 int stop_recording();
102 // If a firewire device crashed
103 int interrupt_crash();
105 // ================================== dc offset
107 // writes to whichever buffer is free or blocks until one becomes free
108 int write_buffer(double **output
, int samples
);
110 // background loop for buffering
112 // background loop for playback
114 // background loop for recording
117 // After the last buffer is written call this to terminate.
118 // A separate buffer for termination is required since the audio device can be
119 // finished without writing a single byte
120 int set_last_buffer();
122 int wait_for_startup();
123 // wait for the playback thread to clean up
124 int wait_for_completion();
126 // start the thread processing buffers
127 int start_playback();
131 // interrupt the playback thread
132 int interrupt_playback();
133 int set_play_dither(int status
);
134 // set software positioning on or off
135 int set_software_positioning(int status
= 1);
136 // total samples played
137 // + audio offset from configuration if playback
138 int64_t current_position();
140 int get_interrupted();
141 int get_device_buffer();
142 // Used by video devices to share audio devices
143 AudioLowLevel
* get_lowlevel_out();
144 AudioLowLevel
* get_lowlevel_in();
148 // Create a lowlevel driver out of the driver ID
149 int create_lowlevel(AudioLowLevel
* &lowlevel
, int driver
);
150 int arm_buffer(int buffer
, double **output
, int samples
);
160 // Override configured parameters depending on the driver
161 int in_samplerate
, in_bits
, in_channels
, in_samples
;
163 int out_samplerate
, out_bits
, out_channels
, out_samples
;
164 int duplex_samplerate
, duplex_bits
, duplex_channels
, duplex_samples
;
165 int out_realtime
, duplex_realtime
;
169 // Samples per buffer
170 int osamples
, isamples
, dsamples
;
171 // Video device to pass data to if the same device handles video
172 VideoDevice
*vdevice
;
173 // OSS < 3.9 --> playback before recording
174 // OSS >= 3.9 --> doesn't matter
175 // Got better synchronization by starting playback first
176 int record_before_play
;
177 Condition
*duplex_lock
;
178 Condition
*startup_lock
;
179 // notify playback routines to test the duplex lock
181 // bits in output file
188 int buffer_size
[TOTAL_BUFFERS
];
189 int last_buffer
[TOTAL_BUFFERS
]; // not written to device
190 // formatted buffers for reading and writing the soundcard
191 char *output_buffer
[TOTAL_BUFFERS
];
192 char *input_buffer
[TOTAL_BUFFERS
];
193 Sema
*play_lock
[TOTAL_BUFFERS
];
194 Sema
*arm_lock
[TOTAL_BUFFERS
];
196 // Get buffer_lock to delay before locking to allow read_buffer to lock it.
199 Condition
*polling_lock
;
202 // for position information
205 int last_buffer_size
;
206 int position_correction
;
208 // prevent the counter from going backwards
210 Timer
*playback_timer
;
215 int global_timer_started
;
216 int software_position_info
;
220 // Multiple data paths can be opened simultaneously by RecordEngine
221 AudioLowLevel
*lowlevel_in
, *lowlevel_out
, *lowlevel_duplex
;
223 AudioOutConfig
*out_config
;
224 AudioInConfig
*in_config
;
225 // Extra configuration if shared with video
226 VideoInConfig
*vconfig
;
228 // Buffer being used by the hardware
229 int thread_buffer_num
;
231 int64_t total_samples_read
;