10 #include "audio1394.inc"
11 #include "audioalsa.inc"
12 #include "audioconfig.inc"
13 #include "audiodevice.inc"
14 #include "audioesound.inc"
15 #include "audiooss.inc"
18 #include "condition.inc"
19 #include "dcoffset.inc"
20 #include "device1394output.inc"
21 #include "maxchannels.h"
23 #include "preferences.inc"
24 #include "recordgui.inc"
27 #include "vdevice1394.inc"
28 #include "videodevice.inc"
33 AudioLowLevel(AudioDevice
*device
);
34 virtual ~AudioLowLevel();
36 virtual int open_input() { return 1; };
37 virtual int open_output() { return 1; };
38 virtual int open_duplex() { return 1; };
39 virtual int close_all() { return 1; };
40 virtual int interrupt_crash() { return 0; };
41 virtual int64_t device_position() { return -1; };
42 virtual int write_buffer(char *buffer
, int size
) { return 1; };
43 virtual int read_buffer(char *buffer
, int size
) { return 1; };
44 virtual int flush_device() { return 1; };
45 virtual int interrupt_playback() { return 1; };
51 class AudioDevice
: public Thread
57 friend class AudioALSA
;
58 friend class AudioOSS
;
59 friend class AudioESound
;
60 friend class Audio1394
;
61 friend class VDevice1394
;
62 friend class Device1394Output
;
64 int open_input(AudioInConfig
*config
,
65 VideoInConfig
*vconfig
,
68 int open_output(AudioOutConfig
*config
, int rate
, int samples
, int realtime
);
69 int open_duplex(AudioOutConfig
*config
, int rate
, int samples
, int realtime
);
74 // Specify a video device to pass data to if the same device handles video
75 int set_vdevice(VideoDevice
*vdevice
);
77 // ================================ recording
79 // read from the record device
80 // Conversion between double and int is done in AudioDevice
81 int read_buffer(double **input
,
86 int input_offset
= 0);
87 int set_record_dither(int value
);
90 // If a firewire device crashed
91 int interrupt_crash();
93 // ================================== dc offset
96 int get_dc_offset(int *output
, RecordGUIDCOffsetText
**dc_offset_text
);
98 int set_dc_offset(int dc_offset
, int channel
);
99 // writes to whichever buffer is free or blocks until one becomes free
100 int write_buffer(double **output
, int samples
, int channels
= -1);
105 // After the last buffer is written call this to terminate.
106 // A separate buffer for termination is required since the audio device can be
107 // finished without writing a single byte
108 int set_last_buffer();
110 int wait_for_startup();
111 // wait for the playback thread to clean up
112 int wait_for_completion();
114 // start the thread processing buffers
115 int start_playback();
116 // interrupt the playback thread
117 int interrupt_playback();
118 int set_play_dither(int status
);
119 // set software positioning on or off
120 int set_software_positioning(int status
= 1);
121 // total samples played
122 int64_t current_position();
124 int get_interrupted();
125 int get_device_buffer();
126 // Used by video devices to share audio devices
127 AudioLowLevel
* get_lowlevel_out();
128 AudioLowLevel
* get_lowlevel_in();
132 // Create a lowlevel driver out of the driver ID
133 int create_lowlevel(AudioLowLevel
* &lowlevel
, int driver
);
134 int arm_buffer(int buffer
, double **output
, int samples
, int channels
);
143 DC_Offset
*dc_offset_thread
;
144 // Override configured parameters depending on the driver
145 int in_samplerate
, in_bits
, in_channels
, in_samples
;
146 int out_samplerate
, out_bits
, out_channels
, out_samples
;
147 int duplex_samplerate
, duplex_bits
, duplex_channels
, duplex_samples
;
148 int out_realtime
, duplex_realtime
;
152 // Samples per buffer
153 int osamples
, isamples
, dsamples
;
154 // Video device to pass data to if the same device handles video
155 VideoDevice
*vdevice
;
156 // OSS < 3.9 --> playback before recording
157 // OSS >= 3.9 --> doesn't matter
158 // Got better synchronization by starting playback first
159 int record_before_play
;
160 Condition
*duplex_lock
;
161 Condition
*startup_lock
;
162 // notify playback routines to test the duplex lock
164 // bits in output file
170 int buffer_size
[TOTAL_BUFFERS
];
171 int last_buffer
[TOTAL_BUFFERS
]; // not written to device
172 // formatted buffers for output
173 char *buffer
[TOTAL_BUFFERS
], *input_buffer
;
174 Sema
*play_lock
[TOTAL_BUFFERS
];
175 Sema
*arm_lock
[TOTAL_BUFFERS
];
179 // for position information
180 int total_samples
, last_buffer_size
, position_correction
;
182 int last_position
; // prevent the counter from going backwards
183 Timer playback_timer
, record_timer
;
185 int is_playing_back
, is_recording
, global_timer_started
, software_position_info
;
189 // Multiple data paths can be opened simultaneously by RecordEngine
190 AudioLowLevel
*lowlevel_in
, *lowlevel_out
, *lowlevel_duplex
;
192 AudioOutConfig
*out_config
;
193 AudioInConfig
*in_config
;
194 // Extra configuration if shared with video
195 VideoInConfig
*vconfig
;
198 int thread_buffer_num
, thread_result
;
199 int64_t total_samples_read
;