10 #include "audioalsa.inc"
11 #include "audioconfig.inc"
12 #include "audiodevice.inc"
13 #include "audio1394.inc"
14 #include "audioesound.inc"
15 #include "audiooss.inc"
17 #include "dcoffset.inc"
18 #include "maxchannels.h"
20 #include "preferences.inc"
21 #include "recordgui.inc"
24 #include "vdevice1394.inc"
25 #include "videodevice.inc"
30 AudioLowLevel(AudioDevice
*device
);
31 virtual ~AudioLowLevel();
33 virtual int open_input() { return 1; };
34 virtual int open_output() { return 1; };
35 virtual int open_duplex() { return 1; };
36 virtual int close_all() { return 1; };
37 virtual int interrupt_crash() { return 0; };
38 virtual int64_t device_position() { return -1; };
39 virtual int write_buffer(char *buffer
, int size
) { return 1; };
40 virtual int read_buffer(char *buffer
, int size
) { return 1; };
41 virtual int flush_device() { return 1; };
42 virtual int interrupt_playback() { return 1; };
48 class AudioDevice
: public Thread
54 friend class AudioALSA
;
55 friend class AudioOSS
;
56 friend class AudioESound
;
57 friend class Audio1394
;
58 friend class VDevice1394
;
60 int open_input(AudioInConfig
*config
, int rate
, int samples
);
61 int open_output(AudioOutConfig
*config
, int rate
, int samples
, int realtime
);
62 int open_duplex(AudioOutConfig
*config
, int rate
, int samples
, int realtime
);
67 // Specify a video device to pass data to if the same device handles video
68 int set_vdevice(VideoDevice
*vdevice
);
70 // ================================ recording
72 // read from the record device
73 // Conversion between double and int is done in AudioDevice
74 int read_buffer(double **input
,
79 int input_offset
= 0);
80 int set_record_dither(int value
);
83 // If a firewire device crashed
84 int interrupt_crash();
86 // ================================== dc offset
89 int get_dc_offset(int *output
, RecordGUIDCOffsetText
**dc_offset_text
);
91 int set_dc_offset(int dc_offset
, int channel
);
92 // writes to whichever buffer is free or blocks until one becomes free
93 int write_buffer(double **output
, int samples
, int channels
= -1);
98 // After the last buffer is written call this to terminate.
99 // A separate buffer for termination is required since the audio device can be
100 // finished without writing a single byte
101 int set_last_buffer();
103 int wait_for_startup();
104 // wait for the playback thread to clean up
105 int wait_for_completion();
107 // start the thread processing buffers
108 int start_playback();
109 // interrupt the playback thread
110 int interrupt_playback();
111 int set_play_dither(int status
);
112 // set software positioning on or off
113 int set_software_positioning(int status
= 1);
114 // total samples played
115 int64_t current_position();
117 int get_interrupted();
118 int get_device_buffer();
119 // Used by video devices to share audio devices
120 AudioLowLevel
* get_lowlevel_out();
121 AudioLowLevel
* get_lowlevel_in();
125 // Create a lowlevel driver out of the driver ID
126 int create_lowlevel(AudioLowLevel
* &lowlevel
, int driver
);
127 int arm_buffer(int buffer
, double **output
, int samples
, int channels
);
136 DC_Offset
*dc_offset_thread
;
137 // Override configured parameters depending on the driver
138 int in_samplerate
, in_bits
, in_channels
, in_samples
;
139 int out_samplerate
, out_bits
, out_channels
, out_samples
;
140 int duplex_samplerate
, duplex_bits
, duplex_channels
, duplex_samples
;
141 int out_realtime
, duplex_realtime
;
145 // Samples per buffer
146 int osamples
, isamples
, dsamples
;
147 // Video device to pass data to if the same device handles video
148 VideoDevice
*vdevice
;
149 // OSS < 3.9 --> playback before recording
150 // OSS >= 3.9 --> doesn't matter
151 // Got better synchronization by starting playback first
152 int record_before_play
;
153 Mutex duplex_lock
, startup_lock
;
154 // notify playback routines to test the duplex lock
156 // bits in output file
162 int buffer_size
[TOTAL_BUFFERS
];
163 int last_buffer
[TOTAL_BUFFERS
]; // not written to device
164 // formatted buffers for output
165 char *buffer
[TOTAL_BUFFERS
], *input_buffer
;
166 Mutex play_mutex
[TOTAL_BUFFERS
], arm_mutex
[TOTAL_BUFFERS
];
170 // for position information
171 int total_samples
, last_buffer_size
, position_correction
;
173 int last_position
; // prevent the counter from going backwards
174 Timer playback_timer
, record_timer
;
176 int is_playing_back
, is_recording
, global_timer_started
, software_position_info
;
180 // Multiple data paths can be opened simultaneously by RecordEngine
181 AudioLowLevel
*lowlevel_in
, *lowlevel_out
, *lowlevel_duplex
;
183 AudioOutConfig
*out_config
;
184 AudioInConfig
*in_config
;
187 int thread_buffer_num
, thread_result
;
188 int64_t total_samples_read
;