diff --git a/MakePHAT b/MakePHAT index 3f765da..9d507ad 100644 --- a/MakePHAT +++ b/MakePHAT @@ -13,7 +13,6 @@ PSP_FW_VERSION=660 MODE=-DKERNEL_MODE - ifeq ($(USE_GPROF),1) GPROF_LIBS = -lpspprof GPROF_FLAGS = -pg -DPROFILE @@ -28,7 +27,6 @@ COMMON_OBJS = \ source/psp/input.o \ source/psp/main.o \ source/psp/math.o \ - source/psp/sound.o \ source/psp/system.o \ source/psp/module.o \ source/psp/network.o \ @@ -64,6 +62,7 @@ COMMON_OBJS = \ source/pr_cmds.o \ source/pr_edict.o \ source/pr_exec.o \ + source/snd_sdl.o \ source/snd_dma.o \ source/snd_mem.o \ source/snd_mix.o \ @@ -109,16 +108,14 @@ HARDWARE_VIDEO_ONLY_FLAGS = -DPSP_HARDWARE_VIDEO OBJS = $(COMMON_OBJS) $(HARDWARE_VIDEO_ONLY_OBJS) - -#LIBS = -lpspaudiolib -lpspaudio -lpspgum -lpspgu -lpsprtc -lpsppower -lpspwlan -lstdc++ -lm - +SDL_LIBS = -lSDL2 -lvorbisfile -lvorbis -logg -lGL -lGLU -lglut GU_LIBS = -lpspgum_vfpu -lpspvfpu -lpspgu -lpspvram AUDIO_LIBS = -lpspaudiolib -lpspaudio -lpspmp3 source/psp/m33libs/libpspaudiocodec.a source/psp/m33libs/libpspkubridge.a -MISC_LIBS = -lpsprtc -lpspmath -lpsppower -lpsphprm -ljpeg -lpng source/psp/m33libs/libz.a +MISC_LIBS = -lpsprtc -lpsppower -lpspmath -lpsphprm -ljpeg -lpng source/psp/m33libs/libz.a NET_LIBS = -lpspwlan -lpspnet_adhoc -lpspnet_adhocctl STD_LIBS = -lstdc++ -lm -lc -LIBS = $(GPROF_LIBS) $(GU_LIBS) $(AUDIO_LIBS) $(MISC_LIBS) $(STD_LIBS) $(NET_LIBS) +LIBS = $(GPROF_LIBS) $(SDL_LIBS) $(GU_LIBS) $(AUDIO_LIBS) $(MISC_LIBS) $(STD_LIBS) $(NET_LIBS) CFLAGS = -ffast-math -O3 -G0 -Wall $(GPROF_FLAGS) -Did386="0" -DPSP $(MODE) $(HARDWARE_VIDEO_ONLY_FLAGS) -DSWIZZLE32 -DPSP_MP3_HWDECODE -DFULLBRIGHT -DHL_RENDER -Wno-strict-aliasing -DPSP_VFPU CXXFLAGS = -fno-rtti -Wcast-qual -Wno-write-strings -Wno-sign-compare -Wno-strict-aliasing diff --git a/MakeSLIM b/MakeSLIM index fd75daf..c3c2c5e 100644 --- a/MakeSLIM +++ b/MakeSLIM @@ -29,7 +29,6 @@ COMMON_OBJS = \ source/psp/input.o \ source/psp/main.o \ source/psp/math.o \ - source/psp/sound.o \ source/psp/system.o \ source/psp/module.o \ source/psp/network.o \ @@ -65,6 +64,7 @@ COMMON_OBJS = \ source/pr_cmds.o \ source/pr_edict.o \ source/pr_exec.o \ + source/snd_sdl.o \ source/snd_dma.o \ source/snd_mem.o \ source/snd_mix.o \ @@ -110,16 +110,14 @@ HARDWARE_VIDEO_ONLY_FLAGS = -DPSP_HARDWARE_VIDEO OBJS = $(COMMON_OBJS) $(HARDWARE_VIDEO_ONLY_OBJS) - -#LIBS = -lpspaudiolib -lpspaudio -lpspgum -lpspgu -lpsprtc -lpsppower -lpspwlan -lstdc++ -lm - +SDL_LIBS = -lSDL2 -lvorbisfile -lvorbis -logg -lGL -lGLU -lglut GU_LIBS = -lpspgum_vfpu -lpspvfpu -lpspgu -lpspvram AUDIO_LIBS = -lpspaudiolib -lpspaudio -lpspmp3 source/psp/m33libs/libpspaudiocodec.a source/psp/m33libs/libpspkubridge.a MISC_LIBS = -lpsprtc -lpsppower -lpspmath -lpsphprm -ljpeg -lpng source/psp/m33libs/libz.a NET_LIBS = -lpspwlan -lpspnet_adhoc -lpspnet_adhocctl STD_LIBS = -lstdc++ -lm -lc -LIBS = $(GPROF_LIBS) $(GU_LIBS) $(AUDIO_LIBS) $(MISC_LIBS) $(STD_LIBS) $(NET_LIBS) +LIBS = $(GPROF_LIBS) $(SDL_LIBS) $(GU_LIBS) $(AUDIO_LIBS) $(MISC_LIBS) $(STD_LIBS) $(NET_LIBS) CFLAGS = -ffast-math -O3 -G0 -Wall $(GPROF_FLAGS) -Did386="0" -DPSP $(MODE) $(HARDWARE_VIDEO_ONLY_FLAGS) -DSWIZZLE32 -DSLIM -DPSP_MP3_HWDECODE -DFULLBRIGHT -DHL_RENDER -Wno-strict-aliasing -DPSP_VFPU CXXFLAGS = -fno-rtti -Wcast-qual -Wno-write-strings -Wno-sign-compare -Wno-strict-aliasing diff --git a/source/host.c b/source/host.c index 49b5ab3..254bec2 100644 --- a/source/host.c +++ b/source/host.c @@ -759,18 +759,11 @@ void _Host_Frame (float time) // update audio if (cls.signon == SIGNONS) { - Thread_UpdateSound(r_origin, vpn, vright, vup); - //S_Update (r_origin, vpn, vright, vup); + S_Update (r_origin, vpn, vright, vup); CL_DecayLights (); } else - Thread_UpdateSound(vec3_origin, vec3_origin, vec3_origin, vec3_origin); - //S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin); - - //if (bmg_type_changed == true) { - CDAudio_Update(); - // bmg_type_changed = false; - //} + S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin); if (host_speeds.value) { diff --git a/source/psp/cd.cpp b/source/psp/cd.cpp index 159d5e8..8eccd09 100644 --- a/source/psp/cd.cpp +++ b/source/psp/cd.cpp @@ -180,7 +180,7 @@ void CDAudio_Track(char* trackname) void CDAudio_Play(byte track, qboolean looping) { - last_track = track; + /*last_track = track; CDAudio_Stop(); if (track < 1) @@ -207,7 +207,7 @@ void CDAudio_Play(byte track, qboolean looping) } - CDAudio_VolumeChange(bgmvolume.value); + CDAudio_VolumeChange(bgmvolume.value);*/ } void CDAudio_Stop(void) diff --git a/source/psp/main.cpp b/source/psp/main.cpp index e64a054..71a8d77 100644 --- a/source/psp/main.cpp +++ b/source/psp/main.cpp @@ -36,6 +36,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include +#include + extern "C" { #include "../quakedef.h" @@ -86,7 +89,7 @@ namespace quake #else - static size_t heapSize = 9 * 1024 * 1024; + static size_t heapSize = 10 * 1024 * 1024; #endif // SLIM @@ -528,9 +531,16 @@ int user_main(SceSize argc, void* argp) // operations. disableFloatingPointExceptions(); - // Initialise the Common module. + // Initialize the Common module. InitExtModules (); + // Initialize SDL + if (SDL_Init(SDL_INIT_AUDIO) < 0) + { + Sys_Error("SDL2: Could not initialize!\n"); + return 0; + } + // Get the current working dir. char currentDirectory[1024]; char gameDirectory[1024]; @@ -633,9 +643,6 @@ int user_main(SceSize argc, void* argp) u64 lastTicks; sceRtcGetCurrentTick(&lastTicks); - // Set up threads - Sys_InitThreads(); - // Enter the main loop. while (!quit) { diff --git a/source/psp/sound.cpp b/source/psp/sound.cpp deleted file mode 100644 index 3318730..0000000 --- a/source/psp/sound.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. -Copyright (C) 2007 Peter Mackay and Chris Swindle. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include -#include - -extern "C" -{ -#include "../quakedef.h" -} - -namespace quake -{ - namespace sound - { - struct Sample - { - short left; - short right; - }; - - static const unsigned int channelCount = 2; - static const unsigned int inputBufferSize = 16384; - static const unsigned int inputFrequency = 11025; - static const unsigned int outputFrequency = 44100; - static const unsigned int inputSamplesPerOutputSample = outputFrequency / inputFrequency; - static Sample inputBuffer[inputBufferSize]; - static volatile unsigned int samplesRead; - - static inline void copySamples(const Sample* first, const Sample* last, Sample* destination) - { - // just assume inputSamplesPerOutputSample is 4. - for (const Sample* source = first; source != last; ++source) - { - const Sample sample = *source; - *destination++ = sample; - *destination++ = sample; - *destination++ = sample; - *destination++ = sample; - } - } - - static void fillOutputBuffer(void* buffer, unsigned int samplesToWrite, void* userData) - { - // Where are we writing to? - Sample* const destination = static_cast (buffer); - - // Where are we reading from? - const Sample* const firstSampleToRead = &inputBuffer[samplesRead]; - - // How many samples to read? - const unsigned int samplesToRead = samplesToWrite / inputSamplesPerOutputSample; - - // Going to wrap past the end of the input buffer? - const unsigned int samplesBeforeEndOfInput = inputBufferSize - samplesRead; - if (samplesToRead > samplesBeforeEndOfInput) - { - // Yes, so write the first chunk from the end of the input buffer. - copySamples( - firstSampleToRead, - firstSampleToRead + samplesBeforeEndOfInput, - &destination[0]); - - // Write the second chunk from the start of the input buffer. - const unsigned int samplesToReadFromBeginning = samplesToRead - samplesBeforeEndOfInput; - copySamples( - &inputBuffer[0], - &inputBuffer[samplesToReadFromBeginning], - &destination[samplesBeforeEndOfInput * inputSamplesPerOutputSample]); - } - else - { - // No wrapping, just copy. - copySamples( - firstSampleToRead, - firstSampleToRead + samplesToRead, - &destination[0]); - } - - // Update the read offset. - samplesRead = (samplesRead + samplesToRead) % inputBufferSize; - } - } -} - -using namespace quake; -using namespace quake::sound; - -qboolean SNDDMA_Init(void) -{ - // Set up Quake's audio. - shm = &sn; - shm->channels = channelCount; - shm->samplebits = 16; - shm->speed = inputFrequency; - shm->soundalive = qtrue; - shm->splitbuffer = qfalse; - shm->samples = inputBufferSize * channelCount; - shm->samplepos = 0; - shm->submission_chunk = 1; - shm->buffer = (unsigned char *) inputBuffer; - - // Initialise the audio system. This initialises it for the CD audio module - // too. - pspAudioInit(); - - // Set the channel callback. - // Sound effects use channel 0, CD audio uses channel 1. - pspAudioSetChannelCallback(0, fillOutputBuffer, 0); - - return qtrue; -} - -void SNDDMA_Shutdown(void) -{ - // Clear the mixing buffer so we don't get any noise during cleanup. - memset(inputBuffer, 0, sizeof(inputBuffer)); - - // Clear the channel callback. - pspAudioSetChannelCallback(0, 0, 0); - - // Stop the audio system? - pspAudioEndPre(); - - // Insert a false delay so the thread can be cleaned up. - sceKernelDelayThread(50 * 1000); - - // Shut down the audio system. - pspAudioEnd(); -} - -int SNDDMA_GetDMAPos(void) -{ - return samplesRead * channelCount; -} - -void SNDDMA_Submit(void) -{ -} diff --git a/source/psp/video_hardware_model.cpp b/source/psp/video_hardware_model.cpp index eac9b86..3120cf6 100644 --- a/source/psp/video_hardware_model.cpp +++ b/source/psp/video_hardware_model.cpp @@ -2112,12 +2112,21 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype) COM_StripExtension(loadmodel->name, model); // HACK HACK HACK sprintf (model2, "%s.mdl_%i", model, i); + + // Sigh.. something is totally awry with memory and the Slim kinda band-aids it.. + // Textures can occupy RAM and VRAM at the same time, ie RAM isnt being freed properly + // So PHAT ends up kicking the bucket with a lot of external textures. +#ifdef SLIM + pheader->gl_texturenum[i][0] = pheader->gl_texturenum[i][1] = pheader->gl_texturenum[i][2] = pheader->gl_texturenum[i][3] = loadtextureimage (model2, 0, 0, qtrue, GU_LINEAR); if (pheader->gl_texturenum[i][0] == 0)// did not find a matching TGA... + +#endif // SLIM + { sprintf (name, "%s_%i", loadmodel->name, i); if(mod_h2) diff --git a/source/snd_dma.c b/source/snd_dma.c index e3d6fd3..fc87811 100644 --- a/source/snd_dma.c +++ b/source/snd_dma.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program 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. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // snd_dma.c -- main control for any streaming sound output device #include "quakedef.h" -#include "thread.h" void S_Play(void); void S_PlayVol(void); @@ -60,7 +59,7 @@ int num_sfx; sfx_t *ambient_sfx[NUM_AMBIENTS]; -int desired_speed = 11025; +int desired_speed = 44100; //11025; int desired_bits = 16; int sound_started=0; @@ -115,7 +114,7 @@ void S_SoundInfo_f(void) Con_Printf ("sound system not started\n"); return; } - + Con_Printf("%5d stereo\n", shm->channels - 1); Con_Printf("%5d samples\n", shm->samples); Con_Printf("%5d samplepos\n", shm->samplepos); @@ -184,14 +183,13 @@ void S_Init (void) Cvar_RegisterVariable(&loadas8bit); Cvar_RegisterVariable(&bgmvolume); Cvar_RegisterVariable(&bgmbuffer); - Cvar_RegisterVariable(&bgmtype); Cvar_RegisterVariable(&ambient_level); Cvar_RegisterVariable(&ambient_fade); Cvar_RegisterVariable(&snd_noextraupdate); Cvar_RegisterVariable(&snd_show); Cvar_RegisterVariable(&_snd_mixahead); - if (host_parms.memsize < 0x800000) + //if (host_parms.memsize < 0x800000) { Cvar_Set ("loadas8bit", "1"); Con_Printf ("loading all sounds as 8bit\n"); @@ -225,15 +223,17 @@ void S_Init (void) shm->buffer = Hunk_AllocName(1<<16, "shmbuf"); } - Con_Printf ("Sound sampling rate: %i\n", shm->speed); + if ( shm ) { + Con_Printf ("Sound sampling rate: %i\n", shm->speed); + } // provides a tick sound until washed clean // if (shm->buffer) // shm->buffer[4] = shm->buffer[5] = 0x7f; // force a pop for debugging - ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("sounds/ambience/water1.wav"); - ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("sounds/ambience/wind2.wav"); + ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav"); + ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav"); S_StopAllSounds (true); } @@ -292,12 +292,12 @@ sfx_t *S_FindName (char *name) if (num_sfx == MAX_SFX) Sys_Error ("S_FindName: out of sfx_t"); - + sfx = &known_sfx[i]; strcpy (sfx->name, name); num_sfx++; - + return sfx; } @@ -311,7 +311,7 @@ S_TouchSound void S_TouchSound (char *name) { sfx_t *sfx; - + if (!sound_started) return; @@ -333,11 +333,11 @@ sfx_t *S_PrecacheSound (char *name) return NULL; sfx = S_FindName (name); - + // cache it in if (precache.value) S_LoadSound (sfx); - + return sfx; } @@ -385,8 +385,8 @@ channel_t *SND_PickChannel(int entnum, int entchannel) if (channels[first_to_die].sfx) channels[first_to_die].sfx = NULL; - return &channels[first_to_die]; -} + return &channels[first_to_die]; +} /* ================= @@ -396,7 +396,7 @@ SND_Spatialize void SND_Spatialize(channel_t *ch) { vec_t dot; - vec_t dist; + vec_t ldist, rdist, dist; vec_t lscale, rscale, scale; vec3_t source_vec; sfx_t *snd; @@ -413,9 +413,9 @@ void SND_Spatialize(channel_t *ch) snd = ch->sfx; VectorSubtract(ch->origin, listener_origin, source_vec); - + dist = VectorNormalize(source_vec) * ch->dist_mult; - + dot = DotProduct(listener_right, source_vec); if (shm->channels == 1) @@ -439,7 +439,7 @@ void SND_Spatialize(channel_t *ch) ch->leftvol = (int) (ch->master_vol * scale); if (ch->leftvol < 0) ch->leftvol = 0; -} +} // ======================================================================= @@ -469,7 +469,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f target_chan = SND_PickChannel(entnum, entchannel); if (!target_chan) return; - + // spatialize memset (target_chan, 0, sizeof(*target_chan)); VectorCopy(origin, target_chan->origin); @@ -492,7 +492,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f target_chan->sfx = sfx; target_chan->pos = 0.0; - target_chan->end = paintedtime + sc->length; + target_chan->end = paintedtime + sc->length; // if an identical sound has also been started this frame, offset the pos // a bit to keep it from just making the first one louder @@ -510,7 +510,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f target_chan->end -= skip; break; } - + } } @@ -557,7 +557,7 @@ void S_StopAllSoundsC (void) void S_ClearBuffer (void) { int clear; - + if (!sound_started || !shm || !shm->buffer) return; @@ -566,10 +566,7 @@ void S_ClearBuffer (void) else clear = 0; - - { - Q_memset(shm->buffer, clear, shm->samples * shm->samplebits/8); - } + Q_memset(shm->buffer, clear, shm->samples * shm->samplebits/8); } @@ -604,13 +601,13 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation) Con_Printf ("Sound %s not looped\n", sfx->name); return; } - + ss->sfx = sfx; VectorCopy (origin, ss->origin); ss->master_vol = vol; ss->dist_mult = (attenuation/64) / sound_nominal_clip_dist; - ss->end = paintedtime + sc->length; - + ss->end = paintedtime + sc->length; + SND_Spatialize (ss); } @@ -646,9 +643,9 @@ void S_UpdateAmbientSounds (void) for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++) { - chan = &channels[ambient_channel]; + chan = &channels[ambient_channel]; chan->sfx = ambient_sfx[ambient_channel]; - + vol = ambient_level.value * l->ambient_sound_level[ambient_channel]; if (vol < 8) vol = 0; @@ -666,7 +663,7 @@ void S_UpdateAmbientSounds (void) if (chan->master_vol < vol) chan->master_vol = vol; } - + chan->leftvol = chan->rightvol = chan->master_vol; } } @@ -693,13 +690,13 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) VectorCopy(forward, listener_forward); VectorCopy(right, listener_right); VectorCopy(up, listener_up); - + // update general area ambient sound sources S_UpdateAmbientSounds (); combine = NULL; -// update spatialization for static and dynamic sounds +// update spatialization for static and dynamic sounds ch = channels+NUM_AMBIENTS; for (i=NUM_AMBIENTS ; i= MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS) { // see if it can just use the last one @@ -727,7 +724,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) for (j=MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS ; jsfx == ch->sfx) break; - + if (j == total_channels) { combine = NULL; @@ -743,8 +740,8 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) continue; } } - - + + } // @@ -760,7 +757,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) //Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name); total++; } - + Con_Printf ("----(%i)----\n", total); } @@ -774,7 +771,7 @@ void GetSoundtime(void) static int buffers; static int oldsamplepos; int fullsamples; - + fullsamples = shm->samples / shm->channels; // it is possible to miscount buffers if it has wrapped twice between @@ -785,7 +782,7 @@ void GetSoundtime(void) if (samplepos < oldsamplepos) { buffers++; // buffer wrapped - + if (paintedtime > 0x40000000) { // time to chop things off to avoid 32 bit limits buffers = 0; @@ -800,9 +797,6 @@ void GetSoundtime(void) void S_ExtraUpdate (void) { - - - if (snd_noextraupdate.value) return; // don't pollute timings S_Update_(); @@ -810,9 +804,11 @@ void S_ExtraUpdate (void) void S_Update_(void) { +/*#ifndef SDL + unsigned endtime; int samps; - + if (!sound_started || (snd_blocked > 0)) return; @@ -835,6 +831,7 @@ void S_Update_(void) S_PaintChannels (endtime); SNDDMA_Submit (); +#endif*/ } /* @@ -851,7 +848,7 @@ void S_Play(void) int i; char name[256]; sfx_t *sfx; - + i = 1; while (i +#include +#include "quakedef.h" + +static dma_t the_shm; +static int snd_inited; + +extern int desired_speed; +extern int desired_bits; + +static void paint_audio(void *unused, Uint8 *stream, int len) +{ + if ( shm ) { + shm->buffer = stream; + shm->samplepos += len/(shm->samplebits/8)/2; + // Check for samplepos overflow? + S_PaintChannels (shm->samplepos); + } +} + +qboolean SNDDMA_Init(void) +{ + SDL_AudioSpec desired, obtained; + + snd_inited = 0; + + /* Set up the desired format */ + desired.freq = desired_speed; + switch (desired_bits) { + case 8: + desired.format = AUDIO_U8; + break; + case 16: + desired.format = AUDIO_S16LSB; + break; + default: + Con_Printf("Unknown number of audio bits: %d\n", + desired_bits); + return 0; + } + desired.channels = 2; + desired.samples = 512; + desired.callback = paint_audio; + + /* Open the audio device */ + if ( SDL_OpenAudio(&desired, &obtained) < 0 ) { + Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError()); + return 0; + } + + /* Make sure we can support the audio format */ + switch (obtained.format) { + case AUDIO_U8: + /* Supported */ + break; + case AUDIO_S16LSB: + case AUDIO_S16MSB: + /* Supported */ + break; + /* Unsupported, fall through */; + default: + /* Not supported -- force SDL to do our bidding */ + SDL_CloseAudio(); + if ( SDL_OpenAudio(&desired, NULL) < 0 ) { + Con_Printf("Couldn't open SDL audio: %s\n", + SDL_GetError()); + return 0; + } + memcpy(&obtained, &desired, sizeof(desired)); + break; + } + SDL_PauseAudio(0); + + /* Fill the audio DMA information block */ + shm = &the_shm; + shm->splitbuffer = 0; + shm->samplebits = (obtained.format & 0xFF); + shm->speed = obtained.freq; + shm->channels = obtained.channels; + shm->samples = obtained.samples*shm->channels; + shm->samplepos = 0; + shm->submission_chunk = 1; + shm->buffer = NULL; + + snd_inited = 1; + return 1; +} + +int SNDDMA_GetDMAPos(void) +{ + return shm->samplepos; +} + +void SNDDMA_Shutdown(void) +{ + if (snd_inited) + { + SDL_CloseAudio(); + snd_inited = 0; + } +} \ No newline at end of file