Final merge of Google Summer of Code 2008 work...

Port SDL 1.3 to the Nintendo DS
by Darren Alton, mentored by Sam Lantinga

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403188
This commit is contained in:
Sam Lantinga 2008-08-27 15:10:03 +00:00
parent e6faee6b2a
commit ede44c4b85
123 changed files with 6082 additions and 388 deletions

View file

@ -70,6 +70,7 @@ extern AudioBootStrap DUMMYAUD_bootstrap;
extern AudioBootStrap DCAUD_bootstrap;
extern AudioBootStrap MMEAUDIO_bootstrap;
extern AudioBootStrap DART_bootstrap;
extern AudioBootStrap NDSAUD_bootstrap;
/* Available audio drivers */
@ -144,6 +145,9 @@ static AudioBootStrap *bootstrap[] = {
#endif
#if SDL_AUDIO_DRIVER_DART
&DART_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_NDS
&NDSAUD_bootstrap,
#endif
NULL
};
@ -167,31 +171,38 @@ SDL_AudioDetectDevices_Default(int iscapture)
{
return -1;
}
static void
SDL_AudioThreadInit_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioWaitDevice_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioPlayDevice_Default(_THIS)
{ /* no-op. */
}
static Uint8 *
SDL_AudioGetDeviceBuf_Default(_THIS)
{
return NULL;
}
static void
SDL_AudioWaitDone_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioCloseDevice_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioDeinitialize_Default(void)
{ /* no-op. */

View file

@ -462,8 +462,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
}
/* 2 Uint32's for chunk header+len, plus the lenread */
headerDiff += lenread + 2 * sizeof(Uint32);
}
while ((chunk.magic == FACT) || (chunk.magic == LIST));
} while ((chunk.magic == FACT) || (chunk.magic == LIST));
/* Decode the audio data format */
format = (WaveFMT *) chunk.data;
@ -564,8 +563,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
*audio_buf = chunk.data;
if (chunk.magic != DATA)
headerDiff += lenread + 2 * sizeof(Uint32);
}
while (chunk.magic != DATA);
} while (chunk.magic != DATA);
headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */
if (MS_ADPCM_encoded) {

View file

@ -259,16 +259,19 @@ swizzle_alsa_channels_6_64bit(_THIS)
{
SWIZ6(Uint64);
}
static __inline__ void
swizzle_alsa_channels_6_32bit(_THIS)
{
SWIZ6(Uint32);
}
static __inline__ void
swizzle_alsa_channels_6_16bit(_THIS)
{
SWIZ6(Uint16);
}
static __inline__ void
swizzle_alsa_channels_6_8bit(_THIS)
{

View file

@ -270,8 +270,7 @@ BSDAUDIO_PlayDevice(_THIS)
|| ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
SDL_Delay(1); /* Let a little CPU time go by */
}
}
while (p < written);
} while (p < written);
/* If timer synchronization is enabled, set the next write frame */
if (this->hidden->frame_ticks) {

View file

@ -62,8 +62,8 @@ DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
pBufDesc->iBufferUsage = BUFFER_EMPTY;
// And notify DART feeder thread that it will have to work a bit.
if (pSDLAudioDevice)
DosPostEventSem(pSDLAudioDevice->hidden->
hevAudioBufferPlayed);
DosPostEventSem(pSDLAudioDevice->
hidden->hevAudioBufferPlayed);
}
}
}
@ -312,10 +312,11 @@ DART_PlayDevice(_THIS)
(pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
pBufDesc->iBufferUsage = BUFFER_USED;
// Send it to DART to be queued
_this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.
ulMixHandle,
&(_this->hidden->
pMixBuffers[iFreeBuf]), 1);
_this->hidden->MixSetupParms.pmixWrite(_this->hidden->
MixSetupParms.ulMixHandle,
&(_this->
hidden->pMixBuffers[iFreeBuf]),
1);
_this->hidden->iLastPlayedBuf = iFreeBuf;
iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs;
@ -333,8 +334,8 @@ DART_GetDeviceBuf(_THIS)
if (_this->hidden) {
iFreeBuf = _this->hidden->iNextFreeBuffer;
pBufDesc =
(pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].
ulUserParm;
(pMixBufferDesc) _this->hidden->
pMixBuffers[iFreeBuf].ulUserParm;
if (pBufDesc) {
if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {

View file

@ -498,8 +498,7 @@ DMA_GetDeviceBuf(_THIS)
this->enabled = 0;
return (NULL);
}
}
while (frame_ticks && (info.blocks < 1));
} while (frame_ticks && (info.blocks < 1));
#ifdef DEBUG_AUDIO
if (info.blocks > 1) {
printf("Warning: audio underflow (%d frags)\n", info.blocks - 1);

View file

@ -154,9 +154,8 @@ ESD_PlayDevice(_THIS)
if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
SDL_Delay(1); /* Let a little CPU time go by */
}
}
while ((written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
} while ((written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
/* Set the next write frame */
this->hidden->next_frame += this->hidden->frame_ticks;

View file

@ -0,0 +1,130 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
This file written by Ryan C. Gordon (icculus@icculus.org)
*/
#include "SDL_config.h"
/* Output audio to NDS */
#include <nds.h>
#include "SDL_audio.h"
#include "../SDL_audio_c.h"
#include "SDL_ndsaudio.h"
static int
NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
int valid_datatype = 0;
this->hidden = SDL_malloc(sizeof(*(this->hidden)));
if (!this->hidden) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
while ((!valid_datatype) && (test_format)) {
this->spec.format = test_format;
switch (test_format) {
case AUDIO_S8:
/*case AUDIO_S16LSB: */
valid_datatype = 1;
break;
default:
test_format = SDL_NextAudioFormat();
break;
}
}
/* set the generic sound parameters */
setGenericSound(22050, /* sample rate */
127, /* volume */
64, /* panning/balance */
0); /* sound format */
return 1;
}
static void
NDSAUD_PlayDevice(_THIS)
{
TransferSoundData *sound = SDL_malloc(sizeof(TransferSoundData));
if (!sound) {
SDL_OutOfMemory();
}
playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
#if 0
// sound->data = this->hidden->mixbuf;/* pointer to raw audio data */
// sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
// sound->rate = 22050; /* sample rate = 22050Hz */
// sound->vol = 127; /* volume [0..127] for [min..max] */
// sound->pan = 64; /* balance [0..127] for [left..right] */
// sound->format = 0; /* 0 for 16-bit, 1 for 8-bit */
// playSound(sound);
#endif
}
static Uint8 *
NDSAUD_GetDeviceBuf(_THIS)
{
return this->hidden->mixbuf; /* is this right? */
}
static void
NDSAUD_WaitDevice(_THIS)
{
/* stub */
}
static void
NDSAUD_CloseDevice(_THIS)
{
/* stub */
}
static int
NDSAUD_Init(SDL_AudioDriverImpl * impl)
{
/* Set the function pointers */
impl->OpenDevice = NDSAUD_OpenDevice;
impl->PlayDevice = NDSAUD_PlayDevice;
impl->WaitDevice = NDSAUD_WaitDevice;
impl->GetDeviceBuf = NDSAUD_GetDeviceBuf;
impl->CloseDevice = NDSAUD_CloseDevice;
/* and the capabilities */
impl->HasCaptureSupport = 1;
impl->OnlyHasDefaultOutputDevice = 1;
impl->OnlyHasDefaultInputDevice = 1;
return 1;
}
AudioBootStrap NDSAUD_bootstrap = {
"nds", "SDL NDS audio driver", NDSAUD_Init, 0 /*1? */
};
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,44 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_ndsaudio_h
#define _SDL_ndsaudio_h
#include "../SDL_sysaudio.h"
#include <nds/arm9/sound.h>
/* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData
{
TransferSoundData *sound;
/* The file descriptor for the audio device */
Uint8 *mixbuf;
Uint32 mixlen;
Uint32 write_delay;
Uint32 initial_calls;
};
#endif /* _SDL_ndsaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -154,8 +154,7 @@ NTO_WaitDevice(_THIS)
}
break;
}
}
while (1);
} while (1);
}
static void
@ -213,8 +212,7 @@ NTO_PlayDevice(_THIS)
towrite -= written;
pcmbuffer += written * this->spec.channels;
}
}
while ((towrite > 0) && (this->enabled));
} while ((towrite > 0) && (this->enabled));
/* If we couldn't write, assume fatal error for now */
if (towrite != 0) {

View file

@ -208,9 +208,8 @@ PAUDIO_PlayDevice(_THIS)
if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
SDL_Delay(1); /* Let a little CPU time go by */
}
}
while ((written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
} while ((written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
/* If timer synchronization is enabled, set the next write frame */
if (this->hidden->frame_ticks) {

View file

@ -218,8 +218,7 @@ UMS_PlayAudio(_THIS)
#endif
return;
}
}
while (samplesToWrite > 0);
} while (samplesToWrite > 0);
SDL_LockAudio();
SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer));
@ -326,8 +325,7 @@ UMS_OpenAudio(_THIS, SDL_AudioSpec * spec)
if (!success) {
test_format = SDL_NextAudioFormat();
}
}
while (!success && test_format);
} while (!success && test_format);
if (success == 0) {
SDL_SetError("Couldn't find any hardware audio formats");

View file

@ -107,8 +107,8 @@ WINWAVEOUT_WaitDevice(_THIS)
Uint8 *
WINWAVEOUT_GetDeviceBuf(_THIS)
{
return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer].
lpData);
return (Uint8 *) (this->hidden->
wavebuf[this->hidden->next_buffer].lpData);
}
void
@ -136,8 +136,7 @@ WINWAVEOUT_WaitDone(_THIS)
if (left > 0) {
SDL_Delay(100);
}
}
while (left > 0);
} while (left > 0);
}
void

View file

@ -278,8 +278,9 @@ DSOUND_GetDeviceBuf(_THIS)
IDirectSoundBuffer_Restore(this->hidden->mixbuf);
result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
this->hidden->mixlen,
(LPVOID *) & this->hidden->
locked_buf, &rawlen, NULL, &junk, 0);
(LPVOID *) & this->
hidden->locked_buf, &rawlen, NULL,
&junk, 0);
}
if (result != DS_OK) {
SetDSerror("DirectSound Lock", result);