mirror of
https://github.com/perfect-dark-pc-port/perfect_dark.git
synced 2026-10-24 00:02:43 +02:00
port: make audio tick at 30hz, add hack to prevent popping
this is a shit solution, but it'll do for now
This commit is contained in:
1 parent
af3e235348
commit
063df3243d
5 files changed
+20
-24
No files matched your search
@@ -5,6 +5,7 @@
|
||||
|
||||
s32 audioInit(void);
|
||||
s32 audioGetBytesBuffered(void);
|
||||
s32 audioGetSamplesBuffered(void);
|
||||
void audioSetNextBuffer(const s16 *buf, u32 len);
|
||||
void audioEndFrame(void);
|
||||
|
||||
|
||||
+9
-5
@@ -3,9 +3,6 @@
|
||||
#include <SDL.h>
|
||||
#include "audio.h"
|
||||
|
||||
#define SAMPLES_HIGH 736
|
||||
#define SAMPLES_LOW 720
|
||||
|
||||
static SDL_AudioDeviceID dev;
|
||||
static const s16 *nextBuf;
|
||||
static u32 nextSize = 0;
|
||||
@@ -19,7 +16,7 @@ s32 audioInit(void)
|
||||
|
||||
SDL_AudioSpec want, have;
|
||||
SDL_zero(want);
|
||||
want.freq = 22020;
|
||||
want.freq = 22020; // TODO: this might cause trouble for some platforms
|
||||
want.format = AUDIO_S16SYS;
|
||||
want.channels = 2;
|
||||
want.samples = 512;
|
||||
@@ -43,6 +40,11 @@ s32 audioGetBytesBuffered(void)
|
||||
return SDL_GetQueuedAudioSize(dev);
|
||||
}
|
||||
|
||||
s32 audioGetSamplesBuffered(void)
|
||||
{
|
||||
return audioGetBytesBuffered() / 4;
|
||||
}
|
||||
|
||||
void audioSetNextBuffer(const s16 *buf, u32 len)
|
||||
{
|
||||
nextBuf = buf;
|
||||
@@ -52,7 +54,9 @@ void audioSetNextBuffer(const s16 *buf, u32 len)
|
||||
void audioEndFrame(void)
|
||||
{
|
||||
if (nextBuf && nextSize) {
|
||||
SDL_QueueAudio(dev, nextBuf, nextSize);
|
||||
if (audioGetSamplesBuffered() < 8192) {
|
||||
SDL_QueueAudio(dev, nextBuf, nextSize);
|
||||
}
|
||||
nextBuf = NULL;
|
||||
nextSize = 0;
|
||||
}
|
||||
|
||||
+2
-17
@@ -145,23 +145,8 @@ void osViSetYScale(f32 value)
|
||||
|
||||
s32 osAiSetFrequency(u32 frequency)
|
||||
{
|
||||
register unsigned int dacRate;
|
||||
register char bitRate;
|
||||
register float f;
|
||||
f = osViClock / (float)frequency + .5f;
|
||||
dacRate = f;
|
||||
|
||||
if (dacRate < AI_MIN_DAC_RATE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bitRate = dacRate / 66;
|
||||
|
||||
if (bitRate > AI_MAX_BIT_RATE) {
|
||||
bitRate = AI_MAX_BIT_RATE;
|
||||
}
|
||||
|
||||
return osViClock / (s32)dacRate;
|
||||
// we can allow for any freq
|
||||
return (s32)frequency;
|
||||
}
|
||||
|
||||
u32 osAiGetLength(void)
|
||||
|
||||
+4
-2
@@ -235,11 +235,13 @@ void schedStartFrame(OSSched *sc)
|
||||
|
||||
void schedAudioFrame(OSSched *sc)
|
||||
{
|
||||
if (!g_SndDisabled)
|
||||
{
|
||||
// audio ticks at 30hz
|
||||
static s32 runFrame = 0;
|
||||
if (!g_SndDisabled && runFrame) {
|
||||
amgrFrame();
|
||||
audioEndFrame();
|
||||
}
|
||||
runFrame ^= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -258,6 +258,10 @@ void amgrHandleFrameMsg(AudioInfo *info, AudioInfo *previnfo)
|
||||
somevalue = IO_READ(OS_PHYSICAL_TO_K1(AI_LEN_REG)) / 4;
|
||||
#else
|
||||
somevalue = osAiGetLength() / 4;
|
||||
// HACK: only allow small frames if really needed
|
||||
if (somevalue < 1100) {
|
||||
somevalue = 248;
|
||||
}
|
||||
#endif
|
||||
datastart = g_AudioManager.ACMDList[var8005cf90];
|
||||
outbuffer = (s16 *) osVirtualToPhysical(info->data);
|
||||
|
||||
Reference in new issue
Block a user