Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

audio.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2000 Open Source Telecom Corporation.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release 
00019 // of ccaudio.
00020 // 
00021 // The exception is that, if you link the ccaudio library with other
00022 // files to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the ccaudio library code into it.
00026 // 
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 // 
00030 // This exception applies only to the code released under the 
00031 // name ccaudio.  If you copy code from other releases into a copy of
00032 // ccaudio, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for ccaudio, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.  
00040 
00041 #ifndef __CCXX_AUDIO_H__
00042 #define __CCXX_AUDIO_H__
00043 
00044 #ifndef __EXPORT
00045 #define __EXPORT
00046 #endif
00047 
00048 typedef enum
00049 {
00050         SAMPLE_RATE_UNKNOWN,
00051         SAMPLE_RATE_6KHZ = 6000,
00052         SAMPLE_RATE_8KHZ = 8000,
00053         SAMPLE_RATE_44KHZ = 44100
00054 }       samplerate_t;
00055 
00056 typedef enum
00057 {
00058         UNKNOWN_AUDIO_ENCODING = 0,
00059         G721_ADPCM_ENCODING,
00060         G722_AUDIO_ENCODING,
00061         G722_7BIT_ENCODING,
00062         G722_6BIT_ENCODING,
00063         G723_3BIT_ENCODING,
00064         G723_5BIT_ENCODING,
00065         GSM_VOICE_ENCODING,
00066         MULAW_AUDIO_ENCODING,
00067         ALAW_AUDIO_ENCODING,
00068         OKI_ADPCM_ENCODING,
00069         DIALOGIC_ADPCM_ENCODING,
00070         CDA_STEREO_ENCODING,
00071         CDA_MONO_ENCODING,
00072         PCM8_STEREO_ENCODING,
00073         PCM8_AUDIO_ENCODING,
00074         PCM16_STEREO_ENCODING,
00075         PCM16_AUDIO_ENCODING,
00076         PCM32_STEREO_ENCODING,
00077         PCM32_AUDIO_ENCODING
00078 }       audioencoding_t;
00079 
00080 typedef enum
00081 {
00082         AUDIO_FORMAT_RAW,
00083         AUDIO_FORMAT_SUN,
00084         AUDIO_FORMAT_RIFF,
00085         AUDIO_FORMAT_WAVE
00086 } audioformat_t;
00087 
00088 typedef enum
00089 {
00090         AUDIO_SUCCESS = 0,
00091         AUDIO_READ_LASTFRAME,
00092         AUDIO_NOT_OPENED,
00093         AUDIO_END_OF_FILE,
00094         AUDIO_START_OF_FILE,
00095         AUDIO_RATE_UNSUPPORTED,
00096         AUDIO_ENCODING_UNSUPPORTED,
00097         AUDIO_READ_INTERRUPTED,
00098         AUDIO_WRITE_INTERRUPTED,
00099         AUDIO_READ_FAILURE,
00100         AUDIO_WRITE_FAILURE,
00101         AUDIO_READ_INCOMPLETE,
00102         AUDIO_WRITE_INCOMPLETE,
00103         AUDIO_REQUEST_INVALID,
00104         AUDIO_TOC_FAILED,
00105         AUDIO_STAT_FAILED,
00106         AUDIO_INVALID_TRACK,
00107         AUDIO_PLAYBACK_FAILED,
00108         AUDIO_NOT_PLAYING
00109 } audioerror_t;
00110 
00111 typedef struct
00112 {
00113         audioformat_t format;
00114         audioencoding_t encoding;
00115         unsigned rate;
00116         unsigned order;
00117         char *annotation;
00118 }       audioinfo_t;
00119 
00120 bool ismono(audioencoding_t encoding);
00121 bool issterio(audioencoding_t encoding);
00122 samplerate_t samplerate(audioencoding_t encoding);
00123 int sampleframe(audioencoding_t encoding, int samples = 0);
00124 int samplecount(audioencoding_t);
00125 unsigned long tosamples(audioencoding_t encoding, size_t bytes);
00126 unsigned long tobytes(audioencoding_t encoding, unsigned long samples);
00127 void samplefill(unsigned char *addr, int samples, audioencoding_t encoding);
00128 
00137 class __EXPORT AudioFile
00138 {
00139 private:
00140         union
00141         {
00142                 int fd;
00143                 void *handle;
00144         }       file;
00145 
00146         char *pathname;
00147         audioerror_t error;
00148         audioinfo_t info;
00149         unsigned long header;           // offset to start of audio
00150         unsigned long minimum;          // minimum sample size required
00151 
00152         void Initialize(void);
00153         void getWaveFormat(int size);
00154 
00155 protected:
00156         virtual char *getContinuation(void)
00157                 {return NULL;};
00158 
00159         audioerror_t setError(audioerror_t err);
00160 
00161         unsigned short getaushort(unsigned char *data);
00162         void setaushort(unsigned char *data, unsigned short value);
00163         unsigned long getaulong(unsigned char *data);
00164         void setaulong(unsigned char *data, unsigned long value);
00165 
00166 public:
00167         AudioFile(const char *fname, unsigned long samples = 0);
00168         AudioFile(const char *fname, audioinfo_t *info, unsigned long min = 0);
00169 
00170         AudioFile()
00171                 {Initialize();};
00172 
00173         ~AudioFile()
00174                 {Close();};
00175 
00176         void Open(const char *fname);
00177         void Create(const char *fname, audioinfo_t *info);
00178         void Close(void);
00179         audioerror_t getSamples(void *addr, unsigned samples);
00180         audioerror_t putSamples(void *addr, unsigned samples);
00181         audioerror_t Skip(long samples);
00182         audioerror_t setPosition(unsigned long samples = ~0l);
00183         audioerror_t getInfo(audioinfo_t *info);
00184         audioerror_t setMinimum(unsigned long samples);
00185         unsigned long getPosition(void);
00186         bool isOpen(void);
00187 
00188         inline audioencoding_t getEncoding(void)
00189                 {return info.encoding;};
00190 
00191         inline audioformat_t getFormat(void)
00192                 {return info.format;};
00193 
00194         inline unsigned getSampleRate(void)
00195                 {return info.rate;};
00196 
00197         inline char *getAnnotation(void)
00198                 {return info.annotation;};
00199 
00200         inline audioerror_t getError(void)
00201                 {return error;};
00202 
00203         inline bool operator!(void)
00204                 {return !isOpen();};
00205 };
00206 
00215 class __EXPORT CDAudio
00216 {
00217 private:
00218         union
00219         {
00220                 int fd;
00221         } file;
00222         unsigned char v0, v1;
00223 #ifdef  __WIN32__
00224         CRITICAL_SECTION crit;
00225         bool paused;
00226         bool opened;
00227         char position[20];
00228         char endmark[24];
00229         char ret[256];
00230         DWORD command(char *fmt, ...);
00231 #endif
00232         audioerror_t err;
00233 
00234 public:
00235         CDAudio(int devnbr = 0);
00236         ~CDAudio();
00237 
00238         audioerror_t Play(int start, int end = 0);      
00239         audioerror_t Stop(void);
00240         audioerror_t Pause(void);
00241         audioerror_t Resume(void);
00242         audioerror_t Eject(void);
00243         audioerror_t Reload(void);
00244         int getFirst(void);
00245         int getLast(void);
00246         bool isPaused(void);
00247         bool isAudio(int track);
00248         bool isOpen(void);
00249 
00250         unsigned char getVolume(int speaker);
00251         void setVolume(unsigned char left, unsigned char right);
00252 
00253         inline unsigned char getVolumeLeft(void)
00254                 {return getVolume(0);};
00255 
00256         inline unsigned char getVolumeRight(void)
00257                 {return getVolume(1);};
00258 
00259         inline audioerror_t getError(void)
00260                 {return err;};
00261 
00262         inline bool operator!(void)
00263                 {return !isOpen();};
00264 };
00265 
00272 class AudioSample
00273 {
00274 private:
00275         audioencoding_t encoding;
00276         unsigned rate;
00277         unsigned count;
00278         unsigned char *samples;
00279 
00280 public:
00281         AudioSample(unsigned size, audioencoding_t coding = PCM16_AUDIO_ENCODING, unsigned rate = 8000);
00282         ~AudioSample();
00283 
00284         inline unsigned getCount(void)
00285                 {return count;};
00286 
00287         inline unsigned getRate(void)
00288                 {return rate;};
00289 
00290         inline audioencoding_t getEncoding(void)
00291                 {return encoding;};
00292 
00293         inline unsigned char *getSamples(void)
00294                 {return samples;};
00295 };      
00296 
00305 class AudioTone : public AudioSample
00306 {
00307 private:
00308         unsigned f1, f2;
00309 
00310 public:
00311         AudioTone(unsigned size, unsigned f1, unsigned rate = 8000);
00312         AudioTone(unsigned size, unsigned f1, unsigned f2, unsigned rate  = 8000);
00313 
00314         inline unsigned getFreq1(void)
00315                 {return f1;};
00316 
00317         inline unsigned getFreq2(void)
00318                 {return f2;};
00319 };
00320 #endif
00321 

Generated at Fri Dec 15 12:25:43 2000 for ccaudio by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000