4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 12:29:32 +08:00

* 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>
* autoload.cc: Add load statements for `LookupAccountNameW',

View File

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