00001
00002
00003
00004
00005 #include "audiodrv.h"
00006
00007 audioDriver::audioDriver()
00008 {
00009
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
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
00028
00029 frequency = inFreq;
00030
00031 long chpars[] = {AL_OUTPUT_RATE, 0};
00032
00033
00034
00035 chpars[1] = frequency;
00036 ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
00037 ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
00038 config = ALnewconfig();
00039
00040
00041
00042 ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
00043 encoding = SIDEMU_SIGNED_PCM;
00044
00045
00046
00047 ALsetchannels(config, AL_MONO);
00048 channels = SIDEMU_MONO;
00049
00050
00051
00052 ALsetwidth(config, AL_SAMPLE_8);
00053 precision = SIDEMU_8BIT;
00054
00055
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;
00063 }
00064
00065
00066 blockSize = frequency;
00067 ALsetqueuesize(config,blockSize);
00068
00069 return true;
00070 }
00071
00072
00073
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 }