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 // + audio offset from configuration if playback
123 int64_t current_position();
125 int get_interrupted();
126 int get_device_buffer();
127 // Used by video devices to share audio devices
128 AudioLowLevel
* get_lowlevel_out();
129 AudioLowLevel
* get_lowlevel_in();
133 // Create a lowlevel driver out of the driver ID
134 int create_lowlevel(AudioLowLevel
* &lowlevel
, int driver
);
135 int arm_buffer(int buffer
, double **output
, int samples
, int channels
);
144 DC_Offset
*dc_offset_thread
;
145 // Override configured parameters depending on the driver
146 int in_samplerate
, in_bits
, in_channels
, in_samples
;
147 int out_samplerate
, out_bits
, out_channels
, out_samples
;
148 int duplex_samplerate
, duplex_bits
, duplex_channels
, duplex_samples
;
149 int out_realtime
, duplex_realtime
;
153 // Samples per buffer
154 int osamples
, isamples
, dsamples
;
155 // Video device to pass data to if the same device handles video
156 VideoDevice
*vdevice
;
157 // OSS < 3.9 --> playback before recording
158 // OSS >= 3.9 --> doesn't matter
159 // Got better synchronization by starting playback first
160 int record_before_play
;
161 Condition
*duplex_lock
;
162 Condition
*startup_lock
;
163 // notify playback routines to test the duplex lock
165 // bits in output file
171 int buffer_size
[TOTAL_BUFFERS
];
172 int last_buffer
[TOTAL_BUFFERS
]; // not written to device
173 // formatted buffers for output
174 char *buffer
[TOTAL_BUFFERS
], *input_buffer
;
175 Sema
*play_lock
[TOTAL_BUFFERS
];
176 Sema
*arm_lock
[TOTAL_BUFFERS
];
180 // for position information
181 int total_samples
, last_buffer_size
, position_correction
;
183 int last_position
; // prevent the counter from going backwards
184 Timer playback_timer
, record_timer
;
186 int is_playing_back
, is_recording
, global_timer_started
, software_position_info
;
190 // Multiple data paths can be opened simultaneously by RecordEngine
191 AudioLowLevel
*lowlevel_in
, *lowlevel_out
, *lowlevel_duplex
;
193 AudioOutConfig
*out_config
;
194 AudioInConfig
*in_config
;
195 // Extra configuration if shared with video
196 VideoInConfig
*vconfig
;
198 int thread_buffer_num
, thread_result
;
199 int64_t total_samples_read
;