Added DirectSound audio backend
This commit adds the DirectSound audio backend, which is a modified version of core/oslib/ds_audiostream.cpp. Porting this was a bit tricky, since ds_audiostream.cpp defined 3 extern functions that the other backends didn't have: * bool os_IsAudioBuffered(); * bool os_IsAudioBufferedLots(); * int os_getusedSamples(); I came to the conclusion that these methods are obsolete since they are only used core/windows/winmain.cpp in the function void os_wait_cycl(u32 cycl) - which is used nowhere. Thus, I removed os_wait_cycl and the headers of the three functions in core/oslib/oslib.h. I also removed the functions themselves (except for int os_getusedSamples(), which is still used inside the directsound backend, but can safely declared static for that purpose). The DirectSound backend will be included during compilation if HOST_OS is OS_WINDOWS.
This commit is contained in:
parent
167fba4c9f
commit
a65b752592
|
@ -1,10 +1,8 @@
|
|||
#include "types.h"
|
||||
|
||||
#include "oslib/audiobackend_directsound.h"
|
||||
#if HOST_OS==OS_WINDOWS
|
||||
#include "oslib.h"
|
||||
#include <initguid.h>
|
||||
#include <dsound.h>
|
||||
#include "audiostream.h"
|
||||
#include "oslib.h"
|
||||
|
||||
void* SoundThread(void* param);
|
||||
#define V2_BUFFERSZ (16*1024)
|
||||
|
@ -14,7 +12,7 @@ IDirectSoundBuffer8* buffer;
|
|||
|
||||
u32 ds_ring_size;
|
||||
|
||||
void os_InitAudio()
|
||||
static void directsound_init()
|
||||
{
|
||||
verifyc(DirectSoundCreate8(NULL,&dsound,NULL));
|
||||
|
||||
|
@ -80,7 +78,7 @@ void os_InitAudio()
|
|||
DWORD wc=0;
|
||||
|
||||
|
||||
int os_getfreesz()
|
||||
static int directsound_getfreesz()
|
||||
{
|
||||
DWORD pc,wch;
|
||||
|
||||
|
@ -96,25 +94,12 @@ int os_getfreesz()
|
|||
return fsz;
|
||||
}
|
||||
|
||||
int os_getusedSamples()
|
||||
static int directsound_getusedSamples()
|
||||
{
|
||||
return (ds_ring_size-os_getfreesz())/4;
|
||||
return (ds_ring_size-directsound_getfreesz())/4;
|
||||
}
|
||||
|
||||
|
||||
bool os_IsAudioBuffered()
|
||||
{
|
||||
return os_getusedSamples()>=3000;
|
||||
}
|
||||
|
||||
|
||||
bool os_IsAudioBufferedLots()
|
||||
{
|
||||
u32 xxx=os_getusedSamples();
|
||||
return xxx>=4096;
|
||||
}
|
||||
|
||||
u32 os_Push_nw(void* frame, u32 samplesb)
|
||||
static u32 directsound_push_nw(void* frame, u32 samplesb)
|
||||
{
|
||||
DWORD pc,wch;
|
||||
|
||||
|
@ -155,8 +140,7 @@ u32 os_Push_nw(void* frame, u32 samplesb)
|
|||
//ds_ring_size
|
||||
}
|
||||
|
||||
#if 0
|
||||
u32 PushAudio(void* frame, u32 samples, bool wait)
|
||||
static u32 directsound_push(void* frame, u32 samples, bool wait)
|
||||
{
|
||||
|
||||
u16* f=(u16*)frame;
|
||||
|
@ -176,18 +160,17 @@ u32 PushAudio(void* frame, u32 samples, bool wait)
|
|||
|
||||
int ffs=1;
|
||||
|
||||
while (os_IsAudioBufferedLots() && wait)
|
||||
while (directsound_IsAudioBufferedLots() && wait)
|
||||
if (ffs == 0)
|
||||
ffs = printf("AUD WAIT %d\n",os_getusedSamples());
|
||||
ffs = printf("AUD WAIT %d\n", directsound_getusedSamples());
|
||||
|
||||
while(!os_Push_nw(frame,samples) && wait)
|
||||
printf("FAILED waiting on audio FAILED %d\n",os_getusedSamples());
|
||||
while(!directsound_Push_nw(frame,samples) && wait)
|
||||
printf("FAILED waiting on audio FAILED %d\n", directsound_getusedSamples());
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void os_TermAudio()
|
||||
static void directsound_term()
|
||||
{
|
||||
buffer->Stop();
|
||||
|
||||
|
@ -195,4 +178,11 @@ void os_TermAudio()
|
|||
dsound->Release();
|
||||
}
|
||||
|
||||
audiobackend_t audiobackend_directsound = {
|
||||
"directsound", // Slug
|
||||
"Microsoft DirectSound", // Name
|
||||
&directsound_init,
|
||||
&directsound_push,
|
||||
&directsound_term
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_directsound;
|
|
@ -2,6 +2,7 @@
|
|||
#include "cfg/cfg.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "audiostream.h"
|
||||
#include "oslib/audiobackend_directsound.h"
|
||||
#include "oslib/audiobackend_alsa.h"
|
||||
#include "oslib/audiobackend_oss.h"
|
||||
|
||||
|
@ -69,6 +70,9 @@ bool RegisterAudioBackend(audiobackend_t *backend)
|
|||
}
|
||||
|
||||
void RegisterAllAudioBackends() {
|
||||
#if HOST_OS==OS_WINDOWS
|
||||
RegisterAudioBackend(&audiobackend_directsound);
|
||||
#endif
|
||||
#if USE_OSS
|
||||
RegisterAudioBackend(&audiobackend_oss);
|
||||
#endif
|
||||
|
|
|
@ -7,9 +7,6 @@ double os_GetSeconds();
|
|||
|
||||
void os_DoEvents();
|
||||
void os_CreateWindow();
|
||||
bool os_IsAudioBuffered();
|
||||
int os_getusedSamples();
|
||||
bool os_IsAudioBufferedLots();
|
||||
void WriteSample(s16 right, s16 left);
|
||||
|
||||
#if BUILD_COMPILER==COMPILER_VC
|
||||
|
|
|
@ -365,48 +365,6 @@ cResetEvent evt_hld(false,true);
|
|||
double speed_load_mspdf;
|
||||
extern double full_rps;
|
||||
|
||||
void os_wait_cycl(u32 cycl)
|
||||
{
|
||||
if (cycl>8*1000*1000)
|
||||
cycl=8*1000*1000;
|
||||
|
||||
|
||||
static double trolol=os_GetSeconds();
|
||||
|
||||
double newt=os_GetSeconds();
|
||||
double ets=(newt-trolol)*200*1000*1000;
|
||||
|
||||
bool fast_enough=ets < cycl;
|
||||
|
||||
bool wait = full_rps >5 && (fast_enough || os_IsAudioBufferedLots());
|
||||
|
||||
speed_load_mspdf=(speed_load_mspdf*0.96235 + ets/cycl*10)/1.96235;
|
||||
|
||||
if (wait && os_IsAudioBuffered())
|
||||
{
|
||||
while (cycl_glob<cycl && os_IsAudioBuffered())
|
||||
evt_hld.Wait(8);
|
||||
|
||||
if (cycl_glob>cycl)
|
||||
InterlockedExchangeSubtract(&cycl_glob,cycl);
|
||||
}
|
||||
else //if (os_IsAudioBufferedLots())
|
||||
{
|
||||
//cycl_glob=0;
|
||||
}
|
||||
|
||||
|
||||
static int last_fe=fast_enough;
|
||||
if (!fast_enough || !last_fe)
|
||||
printf("Speed %.2f (%.2f%%) (%d)\n",ets/cycl*10,cycl/ets*100,os_getusedSamples());
|
||||
|
||||
last_fe=fast_enough;
|
||||
|
||||
|
||||
|
||||
trolol=os_GetSeconds();
|
||||
}
|
||||
|
||||
|
||||
void os_consume(double t)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue