$OpenBSD: patch-sound_cc,v 1.2 2002/09/08 07:43:52 mark Exp $ --- sound.cc.orig Wed Jun 7 22:41:06 2000 +++ sound.cc Sun Sep 8 00:38:45 2002 @@ -34,16 +34,22 @@ #include #include #include -#ifndef __FreeBSD__ -#include -#include -//#include -#else +#ifdef __OpenBSD__ +#include +#include +#define CDROM_LEADOUT 0xAA +#define CD_FRAMES 75 /* frames per second */ +#define CDROM_DATA_TRACK 0x4 +#elif __FreeBSD__ #include #include #define CDROM_LEADOUT 0xAA #define CD_FRAMES 75 /* frames per second */ #define CDROM_DATA_TRACK 0x4 +#else +#include +#include +//#include #endif #include @@ -87,7 +93,7 @@ void getTrackInfo(void) { trackFrame = 0; trackCount = 0; -#ifndef __FreeBSD__ +#if defined(__linux__) cdrom_tochdr cdTochdr; if (-1 == ioctl(cdDevice, CDROMREADTOCHDR, &cdTochdr)) #else @@ -95,7 +101,7 @@ void getTrackInfo(void) { if (-1 == ioctl(cdDevice, CDIOREADTOCHEADER, (char *)&cdTochdr)) #endif return; -#ifndef __FreeBSD__ +#if defined(__linux__) trackCount = cdTochdr.cdth_trk1; #else trackCount = cdTochdr.ending_track - cdTochdr.starting_track + 1; @@ -104,7 +110,7 @@ void getTrackInfo(void) { int i; trackFrame = new int[trackCount+1]; for(i=trackCount;i>=0;i--) { -#ifndef __FreeBSD__ +#if defined(__linux__) cdrom_tocentry cdTocentry; cdTocentry.cdte_format = CDROM_MSF; cdTocentry.cdte_track = (i == trackCount ? CDROM_LEADOUT : i+1); @@ -120,7 +126,7 @@ void getTrackInfo(void) { //Bug fix: thanks to Ben Gertzfield (9/7/98) //Leadout track is sometimes reported as data. //Added check for this. -#ifndef __FreeBSD__ +#if defined(__linux__) if (-1 == ioctl(cdDevice, CDROMREADTOCENTRY, & cdTocentry) || (i != trackCount && (cdTocentry.cdte_ctrl & CDROM_DATA_TRACK))) trackFrame[i] = (i==trackCount?0:trackFrame[i+1]); @@ -153,7 +159,7 @@ int cdGetTrackFrame(int track) { } void cdPlay(int frame, int endFrame) { -#ifndef __FreeBSD__ +#if defined(__linux__) cdrom_msf msf; #else struct ioc_play_msf msf; @@ -168,7 +174,7 @@ void cdPlay(int frame, int endFrame) { // (Sybren Stuvel) cdStop(); -#ifndef __FreeBSD__ +#if defined(__linux__) msf.cdmsf_min0 = frame / (60*CD_FRAMES); msf.cdmsf_sec0 = frame / CD_FRAMES % 60; msf.cdmsf_frame0 = frame % CD_FRAMES; @@ -181,7 +187,7 @@ void cdPlay(int frame, int endFrame) { //Bug fix: thanks to Martin Mitchell //An out by one error that affects some CD players. //Have to use endFrame-1 rather than endFrame (9/7/98) -#ifndef __FreeBSD__ +#if defined(__linux__) msf.cdmsf_min1 = (endFrame-1) / (60*CD_FRAMES); msf.cdmsf_sec1 = (endFrame-1) / CD_FRAMES % 60; msf.cdmsf_frame1 = (endFrame-1) % CD_FRAMES; @@ -195,7 +201,7 @@ void cdPlay(int frame, int endFrame) { } void cdGetStatus(int &track, int &frames, SymbolID &state) { -#ifndef __FreeBSD__ +#if defined(__linux__) cdrom_subchnl subchnl; subchnl.cdsc_format = CDROM_MSF; if (-1 == ioctl(cdDevice, CDROMSUBCHNL, &subchnl)) { @@ -215,7 +221,7 @@ void cdGetStatus(int &track, int &frames state = (state == Open ? Open : NoCD); /* ? */ return; } -#ifndef __FreeBSD__ +#if defined(__linux__) track = subchnl.cdsc_trk; frames = subchnl.cdsc_reladdr.msf.minute*60*CD_FRAMES+ subchnl.cdsc_reladdr.msf.second*CD_FRAMES+ @@ -228,7 +234,7 @@ void cdGetStatus(int &track, int &frames #endif SymbolID oldState = state; -#ifndef __FreeBSD__ +#if defined(__linux__) switch(subchnl.cdsc_audiostatus) { case CDROM_AUDIO_PAUSED : state = Pause; break; case CDROM_AUDIO_PLAY : state = Play; break; @@ -259,38 +265,38 @@ void cdGetStatus(int &track, int &frames void cdStop(void) { //attemptNoDie(ioctl(cdDevice, CDROMSTOP),"stopping CD"); -#ifndef __FreeBSD__ +#if defined(__linux__) ioctl(cdDevice, CDROMSTOP); -#else - ioctl(cdDevice, CDIOCSTOP); +#elif defined(__OpenBSD__) || defined(__FreeBSD__) + ioctl(cdDevice, CDIOCSTOP, NULL); #endif } void cdPause(void) { -#ifndef __FreeBSD__ +#if defined(__linux__) attemptNoDie(ioctl(cdDevice, CDROMPAUSE),"pausing CD",true); -#else - attemptNoDie(ioctl(cdDevice, CDIOCPAUSE),"pausing CD",true); +#elif defined(__OpenBSD__) || defined(__FreeBSD__) + attemptNoDie(ioctl(cdDevice, CDIOCPAUSE, NULL),"pausing CD",true); #endif } void cdResume(void) { -#ifndef __FreeBSD__ +#if defined(__linux__) attemptNoDie(ioctl(cdDevice, CDROMRESUME),"resuming CD",true); -#else - attemptNoDie(ioctl(cdDevice, CDIOCRESUME),"resuming CD",true); +#elif defined(__OpenBSD__) || defined(__FreeBSD__) + attemptNoDie(ioctl(cdDevice, CDIOCRESUME, NULL),"resuming CD",true); #endif } void cdEject(void) { -#ifndef __FreeBSD__ +#if defined(__linux__) attemptNoDie(ioctl(cdDevice, CDROMEJECT),"ejecting CD",true); -#else - attemptNoDie(ioctl(cdDevice, CDIOCEJECT),"ejecting CD",true); +#elif defined(__OpenBSD__) || defined(__FreeBSD__) + attemptNoDie(ioctl(cdDevice, CDIOCEJECT, NULL),"ejecting CD",true); #endif } void cdCloseTray(void) { -#ifndef __FreeBSD__ +#if defined(__linux__) attemptNoDie(ioctl(cdDevice, CDROMCLOSETRAY),"ejecting CD",true); -#else - attemptNoDie(ioctl(cdDevice, CDIOCCLOSE),"ejecting CD",true); +#elif defined(__OpenBSD__) || defined(__FreeBSD__) + attemptNoDie(ioctl(cdDevice, CDIOCCLOSE, NULL),"ejecting CD",true); #endif } @@ -379,7 +385,7 @@ void openSound(SoundSource source, int i int format, stereo, fragment, fqc; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) attempt(device = open(dspName,O_WRONLY),"opening dsp device",true); format = SOUNDFORMAT; attempt(ioctl(device,SNDCTL_DSP_SETFMT,&format),"setting format",true); @@ -408,7 +414,7 @@ void openSound(SoundSource source, int i //Was 0x00010000 + m; attemptNoDie(ioctl(device,SNDCTL_DSP_SETFRAGMENT,&fragment),"setting fragment",true); -#ifndef __FreeBSD__ +#if !defined(__FreeBSD__) || !defined(__OpenBSD__) attempt(ioctl(device,SNDCTL_DSP_SETFMT,&format),"setting format",true); if (format != SOUNDFORMAT) error("setting format (2)"); #endif @@ -422,8 +428,12 @@ void openSound(SoundSource source, int i close(0); } } - - data = new short[NumSamples*2]; +#if defined(__FreeBSD__) || defined(__OpenBSD__) + data = new u_short[NumSamples*2]; +#else + data = new short[NumSamples*2]; +#endif + memset((char*)data,0,NumSamples*4); }