libretro: slam out the audio based on the old libretro interface. didnt think about it much.

This commit is contained in:
zeromus 2017-05-01 04:33:09 -05:00
parent 112e6ca1f2
commit ac4f0e97d8
6 changed files with 74 additions and 14 deletions

View File

@ -30,6 +30,8 @@ namespace BizHawk.Emulation.Cores.Libretro
SIG_InputState,
SIG_VideoUpdate,
SIG_Sample,
SIG_SampleBatch,
};

View File

@ -22,6 +22,20 @@ namespace BizHawk.Emulation.Cores.Libretro
core.SIG_VideoUpdate();
break;
case eMessage.SIG_Sample:
{
short* samples = (short*)comm->buf[(int)BufId.Param0];
core.retro_audio_sample(samples[0], samples[1]);
}
break;
case eMessage.SIG_SampleBatch:
{
void* samples = (void*)comm->buf[(int)BufId.Param0];
core.retro_audio_sample_batch(samples, comm->buf_size[(int)BufId.Param0]/4);
}
break;
default:
return false;

View File

@ -86,6 +86,8 @@ namespace BizHawk.Emulation.Cores.Libretro
vidBufferHandle.Free();
}
public CoreComm CoreComm { get; private set; }
public RetroDescription Description { get; private set; }
public bool LoadData(byte[] data, string id)
@ -124,6 +126,13 @@ namespace BizHawk.Emulation.Cores.Libretro
//UPDATE: well, they wrote in the docs that they CANT. they can ask the frontend if it's supported. (we wont support it unless we have to)
savebuff = new byte[api.comm->env.retro_serialize_size];
savebuff2 = new byte[savebuff.Length + 13];
// TODO: more precise
CoreComm.VsyncNum = (int)(10000000 * api.comm->env.retro_system_av_info.timing.fps);
CoreComm.VsyncDen = 10000000;
SetupResampler(api.comm->env.retro_system_av_info.timing.fps, api.comm->env.retro_system_av_info.timing.sample_rate);
(ServiceProvider as BasicServiceProvider).Register<ISoundProvider>(resampler);
}
public IEmulatorServiceProvider ServiceProvider { get; private set; }
@ -204,6 +213,44 @@ namespace BizHawk.Emulation.Cores.Libretro
int IVideoProvider.BufferWidth { get { return vidWidth; } }
int IVideoProvider.BufferHeight { get { return vidHeight; } }
#region ISoundProvider
SpeexResampler resampler;
short[] sampbuff = new short[0];
// debug
int nsamprecv = 0;
void SetupResampler(double fps, double sps)
{
Console.WriteLine("FPS {0} SPS {1}", fps, sps);
// todo: more precise?
uint spsnum = (uint)sps * 1000;
uint spsden = (uint)1000;
resampler = new SpeexResampler(5, 44100 * spsden, spsnum, (uint)sps, 44100, null, null);
}
//TODO: handle these in c++ (queue there and blast after frameadvance to c#)
public void retro_audio_sample(short left, short right)
{
resampler.EnqueueSample(left, right);
nsamprecv++;
}
public void retro_audio_sample_batch(void* data, int frames)
{
if (sampbuff.Length < frames * 2)
sampbuff = new short[frames * 2];
Marshal.Copy(new IntPtr(data), sampbuff, 0, (int)(frames * 2));
resampler.EnqueueSamples(sampbuff, (int)frames);
nsamprecv += (int)frames;
}
#endregion
public static ControllerDefinition CreateControllerDefinition(SyncSettings syncSettings)
{
ControllerDefinition definition = new ControllerDefinition();
@ -364,19 +411,6 @@ namespace BizHawk.Emulation.Cores.Libretro
#endregion
public CoreComm CoreComm { get; private set; }
SpeexResampler resampler;
void InitAudio()
{
resampler = new SpeexResampler(6, 64081, 88200, 32041, 44100);
}
void snes_audio_sample(ushort left, ushort right)
{
resampler.EnqueueSample((short)left, (short)right);
}
} //class

View File

@ -95,6 +95,8 @@ enum eMessage : s32
SIG_InputState,
SIG_VideoUpdate,
SIG_Sample,
SIG_SampleBatch,
};
enum eStatus : s32
@ -622,10 +624,15 @@ void retro_video_refresh(const void *data, unsigned width, unsigned height, size
void retro_audio_sample(s16 left, s16 right)
{
s16 samples[] = {left,right};
comm.SetBuffer(BufId::Param0,(void*)&samples,4);
BREAK(SIG_Sample);
}
size_t retro_audio_sample_batch(const s16 *data, size_t frames)
{
return 0;
comm.SetBuffer(BufId::Param0, (void*)data, frames*4);
BREAK(SIG_SampleBatch);
return frames;
}
void retro_input_poll()
{

View File

@ -156,6 +156,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
</Link>
<PostBuildEvent>
<Command>..\..\dist\upx -9 $(TargetPath)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>

Binary file not shown.