* fhandler_dsp.cc: Reformat to GNU standards.

(s_audio): Change to a pointer throughout.
(fhandler_dev_dsp::open): Initialize s_audio, if required.
This commit is contained in:
Christopher Faylor 2001-05-20 17:31:06 +00:00
parent 1fcc912f13
commit 1b72f36e89
2 changed files with 292 additions and 281 deletions

View File

@ -1,3 +1,9 @@
Sun May 20 13:26:25 2001 Christopher Faylor <cgf@cygnus.com>
* fhandler_dsp.cc: Reformat to GNU standards.
(s_audio): Change to a pointer throughout.
(fhandler_dev_dsp::open): Initialize s_audio, if required.
Sat May 19 23:40:00 2001 Corinna Vinschen <corinna@vinschen.de> Sat May 19 23:40:00 2001 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc: Add load statements for `LookupAccountNameW', * autoload.cc: Add load statements for `LookupAccountNameW',

View File

@ -332,7 +332,8 @@ Audio::flush()
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Call back routine // Call back routine
static void CALLBACK static void CALLBACK
wave_callback(HWAVE hWave, UINT msg, DWORD instance, DWORD param1, DWORD param2) wave_callback (HWAVE hWave, UINT msg, DWORD instance, DWORD param1,
DWORD param2)
{ {
if (msg == WOM_DONE) if (msg == WOM_DONE)
{ {
@ -343,7 +344,7 @@ wave_callback(HWAVE hWave, UINT msg, DWORD instance, DWORD param1, DWORD param2)
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// /dev/dsp handler // /dev/dsp handler
static Audio s_audio; // static instance of the Audio handler static Audio *s_audio; // static instance of the Audio handler
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// wav file detection.. // wav file detection..
@ -394,11 +395,11 @@ fhandler_dev_dsp::setupwav(const char *pData, int nBytes)
// //
// FIXME: should through away all the header & not output // FIXME: should through away all the header & not output
// it to the soundcard. // it to the soundcard.
s_audio.close(); s_audio->close ();
if (s_audio.open(format->dwSamplesPerSec, format->wBitsPerSample, if (s_audio->open (format->dwSamplesPerSec, format->wBitsPerSample,
format->wChannels) == false) format->wChannels) == false)
{ {
s_audio.open(audiofreq_, audiobits_, audiochannels_); s_audio->open (audiofreq_, audiobits_, audiochannels_);
} }
else else
{ {
@ -415,8 +416,8 @@ fhandler_dev_dsp::setupwav(const char *pData, int nBytes)
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
fhandler_dev_dsp::fhandler_dev_dsp (const char *name) fhandler_dev_dsp::fhandler_dev_dsp (const char *name):
: fhandler_base (FH_OSS_DSP, name) fhandler_base (FH_OSS_DSP, name)
{ {
set_cb (sizeof *this); set_cb (sizeof *this);
} }
@ -434,6 +435,9 @@ fhandler_dev_dsp::open (const char *path, int flags, mode_t mode = 0)
set_flags (flags); set_flags (flags);
if (!s_audio)
s_audio = new Audio;
// Work out initial sample format & frequency // Work out initial sample format & frequency
if (strcmp (path, "/dev/dsp") == 0L) if (strcmp (path, "/dev/dsp") == 0L)
{ {
@ -444,7 +448,7 @@ fhandler_dev_dsp::open (const char *path, int flags, mode_t mode = 0)
audiochannels_ = 1; audiochannels_ = 1;
} }
if (!s_audio.open(audiofreq_, audiobits_, audiochannels_)) if (!s_audio->open (audiofreq_, audiobits_, audiochannels_))
debug_printf ("/dev/dsp: failed to open\n"); debug_printf ("/dev/dsp: failed to open\n");
else else
{ {
@ -457,18 +461,18 @@ fhandler_dev_dsp::open (const char *path, int flags, mode_t mode = 0)
int int
fhandler_dev_dsp::write (const void *ptr, size_t len) fhandler_dev_dsp::write (const void *ptr, size_t len)
{ {
if (s_audio.numbytesoutput() == 0) if (s_audio->numbytesoutput () == 0)
{ {
// check for wave file & setup frequencys properly if possible. // check for wave file & setup frequencys properly if possible.
setupwav ((const char *) ptr, len); setupwav ((const char *) ptr, len);
// Open audio device properly with callbacks. // Open audio device properly with callbacks.
s_audio.close(); s_audio->close ();
if (!s_audio.open(audiofreq_, audiobits_, audiochannels_, true)) if (!s_audio->open (audiofreq_, audiobits_, audiochannels_, true))
return 0; return 0;
} }
s_audio.write(ptr, len); s_audio->write (ptr, len);
return len; return len;
} }
@ -487,7 +491,7 @@ fhandler_dev_dsp::lseek (off_t offset, int whence)
int int
fhandler_dev_dsp::close (void) fhandler_dev_dsp::close (void)
{ {
s_audio.close(); s_audio->close ();
return 0; return 0;
} }
@ -534,31 +538,32 @@ fhandler_dev_dsp::ioctl(unsigned int cmd, void *ptr)
nBits = 8; nBits = 8;
if (nBits) if (nBits)
{ {
s_audio.setformat(*intptr); s_audio->setformat (*intptr);
s_audio.close(); s_audio->close ();
if (s_audio.open(audiofreq_, nBits, audiochannels_) == true) if (s_audio->open (audiofreq_, nBits, audiochannels_) == true)
{ {
audiobits_ = nBits; audiobits_ = nBits;
return 1; return 1;
} }
else else
{ {
s_audio.open(audiofreq_, audiobits_, audiochannels_); s_audio->open (audiofreq_, audiobits_, audiochannels_);
return -1; return -1;
} }
} }
} break; }
break;
CASE (SNDCTL_DSP_SPEED) CASE (SNDCTL_DSP_SPEED)
s_audio.close(); s_audio->close ();
if (s_audio.open(*intptr, audiobits_, audiochannels_) == true) if (s_audio->open (*intptr, audiobits_, audiochannels_) == true)
{ {
audiofreq_ = *intptr; audiofreq_ = *intptr;
return 1; return 1;
} }
else else
{ {
s_audio.open(audiofreq_, audiobits_, audiochannels_); s_audio->open (audiofreq_, audiobits_, audiochannels_);
return -1; return -1;
} }
break; break;
@ -567,26 +572,28 @@ fhandler_dev_dsp::ioctl(unsigned int cmd, void *ptr)
{ {
int nChannels = *intptr + 1; int nChannels = *intptr + 1;
s_audio.close(); s_audio->close ();
if (s_audio.open(audiofreq_, audiobits_, nChannels) == true) if (s_audio->open (audiofreq_, audiobits_, nChannels) == true)
{ {
audiochannels_ = nChannels; audiochannels_ = nChannels;
return 1; return 1;
} }
else else
{ {
s_audio.open(audiofreq_, audiobits_, audiochannels_); s_audio->open (audiofreq_, audiobits_, audiochannels_);
return -1; return -1;
} }
} break; }
break;
CASE (SNDCTL_DSP_GETOSPACE) CASE (SNDCTL_DSP_GETOSPACE)
{ {
audio_buf_info *p = (audio_buf_info *) ptr; audio_buf_info *p = (audio_buf_info *) ptr;
int nBlocks = s_audio.blocks(); int nBlocks = s_audio->blocks ();
int leftblocks = ((Audio::MAX_BLOCKS - nBlocks) - 1); int leftblocks = ((Audio::MAX_BLOCKS - nBlocks) - 1);
if (leftblocks < 0) leftblocks = 0; if (leftblocks < 0)
leftblocks = 0;
if (leftblocks > 1) if (leftblocks > 1)
leftblocks = 1; leftblocks = 1;
int left = leftblocks * Audio::BLOCK_SIZE; int left = leftblocks * Audio::BLOCK_SIZE;
@ -596,21 +603,20 @@ fhandler_dev_dsp::ioctl(unsigned int cmd, void *ptr)
p->fragsize = Audio::BLOCK_SIZE; p->fragsize = Audio::BLOCK_SIZE;
p->bytes = left; p->bytes = left;
debug_printf("ptr: %p " debug_printf ("ptr %p nblocks %d leftblocks %d left bytes %d ",
"nblocks: %d " ptr, nBlocks, leftblocks, left);
"leftblocks: %d "
"left bytes: %d ", ptr, nBlocks, leftblocks, left);
return 1; return 1;
} break; }
break;
CASE (SNDCTL_DSP_SETFRAGMENT) CASE (SNDCTL_DSP_SETFRAGMENT)
{ {
// Fake!! esound & mikmod require this on non PowerPC platforms. // Fake!! esound & mikmod require this on non PowerPC platforms.
// //
return 1; return 1;
} break; }
break;
default: default:
debug_printf ("/dev/dsp: ioctl not handled yet! FIXME:\n"); debug_printf ("/dev/dsp: ioctl not handled yet! FIXME:\n");
@ -626,4 +632,3 @@ fhandler_dev_dsp::dump ()
{ {
paranoid_printf ("here, fhandler_dev_dsp"); paranoid_printf ("here, fhandler_dev_dsp");
} }