Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

hpux_audiodrv.cpp

Go to the documentation of this file.
00001 //
00002 // 1997/09/27 21:38:01
00003 //
00004 
00005 #include "audiodrv.h"
00006 
00007 audioDriver::audioDriver()
00008 {
00009         // Reset everything.
00010         errorString = "None";
00011         frequency = 0;
00012         channels = 0;
00013         encoding = 0;
00014         precision = 0;
00015         audioHd = (-1);
00016 }
00017 
00018 bool audioDriver::IsThere()
00019 {
00020         // Check device availability and write permissions.
00021         return (access(AUDIODEVICE,W_OK)==0);
00022 }
00023 
00024 bool audioDriver::Open(udword inFreq, int inPrecision, int inChannels,
00025                                            int inFragments, int inFragBase)
00026 {
00027         if ((audioHd=open(AUDIODEVICE,O_WRONLY,0)) == (-1))
00028     { 
00029                 errorString = "AUDIO: Could not open audio device.";
00030                 return false;
00031     }
00032         
00033         // Transfer input parameters to this object.
00034         // May later be replaced with driver defaults.
00035         frequency = inFreq;
00036         precision = inPrecision;
00037         channels = inChannels;
00038         
00039         int tmp_sampleSize;
00040         if (precision == SIDEMU_16BIT)
00041     {
00042                 tmp_sampleSize = AUDIO_FORMAT_LINEAR16BIT;
00043                 encoding = SIDEMU_SIGNED_PCM;
00044     }
00045         else  // if (precision == SIDEMU_8BIT)
00046     {
00047                 //errorString = "AUDIO: 8-bit samples not supported.";
00048                 //return false;
00049                 precision = SIDEMU_16BIT;
00050                 encoding = SIDEMU_SIGNED_PCM;
00051                 tmp_sampleSize = AUDIO_FORMAT_LINEAR16BIT;
00052     }
00053         if (ioctl(audioHd,AUDIO_SET_DATA_FORMAT,tmp_sampleSize) == (-1))
00054     {
00055                 errorString = "AUDIO: Could not set data format.";
00056                 return false;
00057     }
00058 
00059         int tmp_stereo;
00060         if (channels == SIDEMU_STEREO)
00061                 tmp_stereo = 2;
00062         else  // if (channels == SIDEMU_MONO)
00063                 tmp_stereo = 1;
00064         if (ioctl(audioHd,AUDIO_SET_CHANNELS,tmp_stereo) == (-1))
00065     {
00066                 errorString = "AUDIO: Could not set mono/stereo.";
00067                 return false;
00068     }
00069 
00070         int tmp_speed = frequency;
00071         if (ioctl(audioHd,AUDIO_SET_SAMPLE_RATE,tmp_speed) == (-1))
00072     {
00073                 errorString = "AUDIO: Could not set sample rate.";
00074                 return false;
00075     }
00076         blockSize = 2*tmp_stereo*frequency;  // dump mode
00077         
00078     return true
00079 }
00080 
00081 // Close an opened audio device, free any allocated buffers and
00082 // reset any variables that reflect the current state.
00083 void audioDriver::Close()
00084 {
00085         if (audioHd != (-1))
00086     {
00087                 close(audioHd);
00088                 audioHd = (-1);
00089     }
00090 }
00091 
00092 void audioDriver::Play(ubyte* pBuffer, int bufferSize)
00093 {
00094         if (audioHd != (-1))
00095         {
00096                 write(audioHd,pBuffer,bufferSize);
00097         }
00098 }

Generated on Tue Feb 8 04:13:58 2005 for Esidplay by doxygen 1.3.3