Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

audiodevice.h

Go to the documentation of this file.
00001 #ifndef AUDIODEVICE_H
00002 #define AUDIODEVICE_H
00003 
00004 #include <fcntl.h>
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <sys/ioctl.h>
00008 #include <unistd.h>
00009 
00010 #include "audio1394.inc"
00011 #include "audioalsa.inc"
00012 #include "audioconfig.inc"
00013 #include "audiodevice.inc"
00014 #include "audioesound.inc"
00015 #include "audiooss.inc"
00016 #include "bctimer.h"
00017 #include "binary.h"
00018 #include "condition.inc"
00019 #include "dcoffset.inc"
00020 #include "device1394output.inc"
00021 #include "maxchannels.h"
00022 #include "mutex.inc"
00023 #include "preferences.inc"
00024 #include "recordgui.inc"
00025 #include "sema.inc"
00026 #include "thread.h"
00027 #include "vdevice1394.inc"
00028 #include "videodevice.inc"
00029 
00030 class AudioLowLevel
00031 {
00032 public:
00033         AudioLowLevel(AudioDevice *device);
00034         virtual ~AudioLowLevel();
00035 
00036         virtual int open_input() { return 1; };
00037         virtual int open_output() { return 1; };
00038         virtual int open_duplex() { return 1; };
00039         virtual int close_all() { return 1; };
00040         virtual int interrupt_crash() { return 0; };
00041         virtual int64_t device_position() { return -1; };
00042         virtual int write_buffer(char *buffer, int size) { return 1; };
00043         virtual int read_buffer(char *buffer, int size) { return 1; };
00044         virtual int flush_device() { return 1; };
00045         virtual int interrupt_playback() { return 1; };
00046         
00047         AudioDevice *device;
00048 };
00049 
00050 
00051 class AudioDevice : public Thread
00052 {
00053 public:
00054         AudioDevice();
00055         ~AudioDevice();
00056 
00057         friend class AudioALSA;
00058         friend class AudioOSS;
00059         friend class AudioESound;
00060         friend class Audio1394;
00061         friend class VDevice1394;
00062         friend class Device1394Output;
00063 
00064         int open_input(AudioInConfig *config, 
00065                 VideoInConfig *vconfig,
00066                 int rate, 
00067                 int samples);
00068         int open_output(AudioOutConfig *config, int rate, int samples, int realtime);
00069         int open_duplex(AudioOutConfig *config, int rate, int samples, int realtime);
00070         int close_all();
00071         int reset_output();
00072         int restart();
00073 
00074 // Specify a video device to pass data to if the same device handles video
00075         int set_vdevice(VideoDevice *vdevice);
00076 
00077 // ================================ recording
00078 
00079 // read from the record device
00080 // Conversion between double and int is done in AudioDevice
00081         int read_buffer(double **input, 
00082                 int samples, 
00083                 int channels, 
00084                 int *over, 
00085                 double *max, 
00086                 int input_offset = 0);  
00087         int set_record_dither(int value);
00088 
00089         int stop_recording();
00090 // If a firewire device crashed
00091         int interrupt_crash();
00092 
00093 // ================================== dc offset
00094 
00095 // get and set offset
00096         int get_dc_offset(int *output, RecordGUIDCOffsetText **dc_offset_text);
00097 // set new offset
00098         int set_dc_offset(int dc_offset, int channel);
00099 // writes to whichever buffer is free or blocks until one becomes free
00100         int write_buffer(double **output, int samples, int channels = -1); 
00101 
00102 // play back buffers
00103         void run();           
00104 
00105 // After the last buffer is written call this to terminate.
00106 // A separate buffer for termination is required since the audio device can be
00107 // finished without writing a single byte
00108         int set_last_buffer();         
00109 
00110         int wait_for_startup();
00111 // wait for the playback thread to clean up
00112         int wait_for_completion();
00113 
00114 // start the thread processing buffers
00115         int start_playback();
00116 // interrupt the playback thread
00117         int interrupt_playback();
00118         int set_play_dither(int status);
00119 // set software positioning on or off
00120         int set_software_positioning(int status = 1);
00121 // total samples played
00122 //  + audio offset from configuration if playback
00123         int64_t current_position();
00124 // If interrupted
00125         int get_interrupted();
00126         int get_device_buffer();
00127 // Used by video devices to share audio devices
00128         AudioLowLevel* get_lowlevel_out();
00129         AudioLowLevel* get_lowlevel_in();
00130 
00131 private:
00132         int initialize();
00133 // Create a lowlevel driver out of the driver ID
00134         int create_lowlevel(AudioLowLevel* &lowlevel, int driver);
00135         int arm_buffer(int buffer, double **output, int samples, int channels);
00136         int get_obits();
00137         int get_ochannels();
00138         int get_ibits();
00139         int get_ichannels();
00140         int get_orate();
00141         int get_irate();
00142         int get_orealtime();
00143 
00144         DC_Offset *dc_offset_thread;
00145 // Override configured parameters depending on the driver
00146         int in_samplerate, in_bits, in_channels, in_samples;
00147         int out_samplerate, out_bits, out_channels, out_samples;
00148         int duplex_samplerate, duplex_bits, duplex_channels, duplex_samples;
00149         int out_realtime, duplex_realtime;
00150 
00151 // Access mode
00152         int r, w, d;
00153 // Samples per buffer
00154         int osamples, isamples, dsamples;
00155 // Video device to pass data to if the same device handles video
00156         VideoDevice *vdevice;
00157 // OSS < 3.9   --> playback before recording
00158 // OSS >= 3.9  --> doesn't matter
00159 // Got better synchronization by starting playback first
00160         int record_before_play;
00161         Condition *duplex_lock;
00162         Condition *startup_lock;
00163 // notify playback routines to test the duplex lock
00164         int duplex_init;        
00165 // bits in output file
00166         int rec_dither;         
00167 // 1 or 0
00168         int play_dither;        
00169         int sharing;
00170 
00171         int buffer_size[TOTAL_BUFFERS];
00172         int last_buffer[TOTAL_BUFFERS];    // not written to device
00173 // formatted buffers for output
00174         char *buffer[TOTAL_BUFFERS], *input_buffer;
00175         Sema *play_lock[TOTAL_BUFFERS];
00176         Sema *arm_lock[TOTAL_BUFFERS];
00177         Mutex *timer_lock;
00178         int arm_buffer_num;
00179 
00180 // for position information
00181         int total_samples, last_buffer_size, position_correction;
00182         int device_buffer;
00183         int last_position;  // prevent the counter from going backwards
00184         Timer playback_timer, record_timer;
00185 // Current operation
00186         int is_playing_back, is_recording, global_timer_started, software_position_info;
00187         int interrupt;
00188         int driver;
00189 
00190 // Multiple data paths can be opened simultaneously by RecordEngine
00191         AudioLowLevel *lowlevel_in, *lowlevel_out, *lowlevel_duplex;
00192 
00193         AudioOutConfig *out_config;
00194         AudioInConfig *in_config;
00195 // Extra configuration if shared with video
00196         VideoInConfig *vconfig;
00197 
00198         int thread_buffer_num, thread_result;
00199         int64_t total_samples_read;
00200 };
00201 
00202 
00203 
00204 #endif

Generated on Sun Jan 8 13:38:50 2006 for Cinelerra-svn by  doxygen 1.4.4