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

sgi_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         audio = (config = NULL);
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         // Transfer input parameters to this object.
00028         // May later be replaced with driver defaults.
00029         frequency = inFreq;
00030 
00031         long chpars[] = {AL_OUTPUT_RATE, 0};
00032  
00033         // Frequency
00034  
00035         chpars[1] = frequency;
00036         ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
00037         ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
00038         config = ALnewconfig();
00039  
00040         // Set sample format
00041  
00042         ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
00043         encoding = SIDEMU_SIGNED_PCM;  // unlike other systems
00044         
00045         // Mono output
00046  
00047         ALsetchannels(config, AL_MONO);
00048         channels = SIDEMU_MONO;
00049  
00050         // 8-bit sampleSize
00051  
00052         ALsetwidth(config, AL_SAMPLE_8);
00053         precision = SIDEMU_8BIT;
00054  
00055         // Allocate an audio port
00056  
00057         if((audio = ALopenport("SIDPLAY sound", "w", config)) == NULL)
00058     {
00059                 errorString = "AUDIO: Could not open audio port.";
00060                 oserror();
00061                 ALfreeconfig(config);
00062                 return false;  //(1);
00063     }
00064  
00065         // Allocate sound buffers
00066         blockSize = frequency;
00067         ALsetqueuesize(config,blockSize);
00068         
00069         return true;
00070 }
00071 
00072 // Close an opened audio device, free any allocated buffers and
00073 // reset any variables that reflect the current state.
00074 void audioDriver::Close()
00075 {
00076         if (audio != NULL)
00077     {
00078                 ALcloseport(audio);
00079                 ALfreeconfig(config);
00080                 audio = (config = NULL);
00081     }
00082 }
00083 
00084 void audioDriver::Play(ubyte* pBuffer, int bufferSize)
00085 {
00086         if (audio != NULL)
00087         {
00088                 ALwritesamps(audio,pBuffer,bufferSize);
00089         }
00090 }

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