r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / audiodevice.h
blob46c5e52efd465a48183703284300107a7b2d5795
1 #ifndef AUDIODEVICE_H
2 #define AUDIODEVICE_H
4 #include <fcntl.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/ioctl.h>
8 #include <unistd.h>
10 #include "audioalsa.inc"
11 #include "audioconfig.inc"
12 #include "audiodevice.inc"
13 #include "audio1394.inc"
14 #include "audioesound.inc"
15 #include "audiooss.inc"
16 #include "binary.h"
17 #include "dcoffset.inc"
18 #include "maxchannels.h"
19 #include "mutex.h"
20 #include "preferences.inc"
21 #include "recordgui.inc"
22 #include "thread.h"
23 #include "timer.h"
24 #include "vdevice1394.inc"
25 #include "videodevice.inc"
27 class AudioLowLevel
29 public:
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; };
44 AudioDevice *device;
48 class AudioDevice : public Thread
50 public:
51 AudioDevice();
52 ~AudioDevice();
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);
63 int close_all();
64 int reset_output();
65 int restart();
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,
75 int samples,
76 int channels,
77 int *over,
78 double *max,
79 int input_offset = 0);
80 int set_record_dither(int value);
82 int stop_recording();
83 // If a firewire device crashed
84 int interrupt_crash();
86 // ================================== dc offset
88 // get and set offset
89 int get_dc_offset(int *output, RecordGUIDCOffsetText **dc_offset_text);
90 // set new offset
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);
95 // play back buffers
96 void run();
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();
116 // If interrupted
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();
123 private:
124 int initialize();
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);
128 int get_obits();
129 int get_ochannels();
130 int get_ibits();
131 int get_ichannels();
132 int get_orate();
133 int get_irate();
134 int get_orealtime();
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;
143 // Access mode
144 int r, w, d;
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
155 int duplex_init;
156 // bits in output file
157 int rec_dither;
158 // 1 or 0
159 int play_dither;
160 int sharing;
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];
167 Mutex timer_lock;
168 int arm_buffer_num;
170 // for position information
171 int total_samples, last_buffer_size, position_correction;
172 int device_buffer;
173 int last_position; // prevent the counter from going backwards
174 Timer playback_timer, record_timer;
175 // Current operation
176 int is_playing_back, is_recording, global_timer_started, software_position_info;
177 int interrupt;
178 int driver;
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;
186 private:
187 int thread_buffer_num, thread_result;
188 int64_t total_samples_read;
193 #endif