Fix 1000 Sound, remove old sound.cpp

This commit is contained in:
Steam Deck User 2023-03-13 15:06:34 -04:00
parent 70c0967d7c
commit 2fbd7303d3
4 changed files with 3 additions and 161 deletions

View file

@ -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 \

View file

@ -89,7 +89,7 @@ namespace quake
#else
static size_t heapSize = 9 * 1024 * 1024;
static size_t heapSize = 10 * 1024 * 1024;
#endif // SLIM

View file

@ -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 <pspaudiolib.h>
#include <pspkernel.h>
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<Sample*> (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)
{
}

View file

@ -189,7 +189,7 @@ void S_Init (void)
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");