1 // -------------------------------------------------------------------------- 2 // ``Open Sound System (OSS)'' specific audio driver interface. 3 // -------------------------------------------------------------------------- 4 5 #ifndef AUDIODRV_H 6 #define AUDIODRV_H 7 8 9 #include <sys/ioctl.h> 10 #include <errno.h> 11 #include <fcntl.h> 12 #include <stdio.h> 13 #include <unistd.h> 14 15 #include <sidplay/emucfg.h> 16 17 #if defined(HAVE_LINUX) && defined(HAVE_LINUX_SOUNDCARD_H) 18 #include <linux/soundcard.h> 19 #elif defined(HAVE_FREEBSD) && defined(HAVE_SYS_SOUNDCARD_H) 20 #include <sys/soundcard.h> 21 #elif defined(HAVE_OPENBSD) && defined(HAVE_SOUNDCARD_H) 22 #include <soundcard.h> 23 #elif defined(HAVE_NETBSD) && defined(HAVE_SOUNDCARD_H) 24 #include <soundcard.h> 25 #else 26 #error Audio driver not supported. 27 #endif 28 29 class audioDriver 30 { 31 32 public: // --------------------------------------------------------- public 33 34 audioDriver(); 35 36 bool IsThere(); 37 38 bool Open(udword freq, int precision, int channels, 39 int fragments, int fragBase); div_rem(x: usize, d: usize) -> (usize, usize)40 41 void Close(); 42 43 void Play(ubyte* buffer, int bufferSize); 44 45 bool Reset() 46 { 47 return (ioctl(audioHd,SNDCTL_DSP_RESET,0)!=(-1)); 48 } 49 50 int GetAudioHandle() 51 { 52 return audioHd; 53 } 54 55 udword GetFrequency() 56 { 57 return frequency; 58 } 59 60 int GetChannels() with_capacity(bits: usize) -> Self61 { 62 return channels; 63 } 64 65 int GetSamplePrecision() 66 { 67 return precision; 68 } 69 70 int GetSampleEncoding() grow(&mut self, bits: usize)71 { 72 return encoding; 73 } 74 75 int GetBlockSize() 76 { 77 return blockSize; 78 } 79 80 int GetFragments() 81 { len(&self) -> usize82 return fragments; 83 } 84 85 int GetFragSizeBase() 86 { 87 return fragSizeBase; 88 } 89 90 const char* GetErrorString() contains(&self, bit: usize) -> bool91 { 92 return errorString; 93 } 94 95 private: // ------------------------------------------------------- private 96 97 static const char AUDIODEVICE[]; 98 int audioHd; 99 100 char* errorString; 101 clear(&mut self)102 int blockSize; 103 int fragments; 104 int fragSizeBase; 105 106 udword frequency; 107 108 // These are constants/enums from ``libsidplay/include/emucfg.h''. 109 int encoding; 110 int precision; 111 int channels; 112 insert(&mut self, bit: usize)113 bool swapEndian; 114 }; 115 116 117 #endif // AUDIODRV_H 118