mirror of https://github.com/snes9xgit/snes9x.git
Revert "Revert "APU: Big refactor." I'll put this in a branch."
This reverts commit 19f03c44de
.
This commit is contained in:
parent
19f03c44de
commit
c376908f2e
836
apu/apu.cpp
836
apu/apu.cpp
File diff suppressed because it is too large
Load Diff
|
@ -62,7 +62,7 @@ class HermiteResampler : public Resampler
|
||||||
clear (void)
|
clear (void)
|
||||||
{
|
{
|
||||||
ring_buffer::clear ();
|
ring_buffer::clear ();
|
||||||
r_frac = 1.0;
|
r_frac = 0.0;
|
||||||
r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
|
r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
|
||||||
r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
|
r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ class HermiteResampler : public Resampler
|
||||||
return (ring_buffer::space_filled() + sizeof(short) - 1) / sizeof(short);
|
return (ring_buffer::space_filled() + sizeof(short) - 1) / sizeof(short);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) floor (((size >> 2) - r_frac) / r_step) * 2;
|
return (int) trunc (((size >> 2) - r_frac) / r_step) * 2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,17 +85,17 @@ bool S9xAlsaSoundDriver::open_device()
|
||||||
}
|
}
|
||||||
|
|
||||||
printf (" --> (%s, %s, %dhz, %d ms)...\n",
|
printf (" --> (%s, %s, %dhz, %d ms)...\n",
|
||||||
Settings.SixteenBitSound ? "16-bit" : "8-bit",
|
"16-bit",
|
||||||
Settings.Stereo ? "Stereo" : "Mono",
|
"Stereo",
|
||||||
Settings.SoundPlaybackRate,
|
Settings.SoundPlaybackRate,
|
||||||
gui_config->sound_buffer_size);
|
gui_config->sound_buffer_size);
|
||||||
|
|
||||||
snd_pcm_hw_params_alloca (&hw_params);
|
snd_pcm_hw_params_alloca (&hw_params);
|
||||||
snd_pcm_hw_params_any (pcm, hw_params);
|
snd_pcm_hw_params_any (pcm, hw_params);
|
||||||
snd_pcm_hw_params_set_format (pcm, hw_params, Settings.SixteenBitSound ? SND_PCM_FORMAT_S16 : SND_PCM_FORMAT_U8);
|
snd_pcm_hw_params_set_format (pcm, hw_params, SND_PCM_FORMAT_S16);
|
||||||
snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
|
snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||||
snd_pcm_hw_params_set_rate_resample (pcm, hw_params, 0);
|
snd_pcm_hw_params_set_rate_resample (pcm, hw_params, 0);
|
||||||
snd_pcm_hw_params_set_channels (pcm, hw_params, Settings.Stereo ? 2 : 1);
|
snd_pcm_hw_params_set_channels (pcm, hw_params, 2);
|
||||||
|
|
||||||
snd_pcm_hw_params_get_rate_min (hw_params, &min, NULL);
|
snd_pcm_hw_params_get_rate_min (hw_params, &min, NULL);
|
||||||
snd_pcm_hw_params_get_rate_max (hw_params, &max, NULL);
|
snd_pcm_hw_params_get_rate_max (hw_params, &max, NULL);
|
||||||
|
@ -190,14 +190,14 @@ S9xAlsaSoundDriver::samples_available ()
|
||||||
{
|
{
|
||||||
// Using rate control, we should always keep the emulator's sound buffers empty to
|
// Using rate control, we should always keep the emulator's sound buffers empty to
|
||||||
// maintain an accurate measurement.
|
// maintain an accurate measurement.
|
||||||
if (frames < (S9xGetSampleCount () >> (Settings.Stereo ? 1 : 0)))
|
if (frames < (S9xGetSampleCount () >> 1))
|
||||||
{
|
{
|
||||||
S9xClearSamples ();
|
S9xClearSamples ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frames = MIN (frames, S9xGetSampleCount () >> (Settings.Stereo ? 1 : 0));
|
frames = MIN (frames, S9xGetSampleCount () >> 1);
|
||||||
|
|
||||||
bytes = snd_pcm_frames_to_bytes (pcm, frames);
|
bytes = snd_pcm_frames_to_bytes (pcm, frames);
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ S9xAlsaSoundDriver::samples_available ()
|
||||||
sound_buffer_size = bytes;
|
sound_buffer_size = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
S9xMixSamples (sound_buffer, frames << (Settings.Stereo ? 1 : 0));
|
S9xMixSamples (sound_buffer, frames * 2);
|
||||||
|
|
||||||
frames_written = 0;
|
frames_written = 0;
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,7 @@ bool S9xOSSSoundDriver::open_device()
|
||||||
|
|
||||||
output_buffer_size = (gui_config->sound_buffer_size * Settings.SoundPlaybackRate) / 1000;
|
output_buffer_size = (gui_config->sound_buffer_size * Settings.SoundPlaybackRate) / 1000;
|
||||||
|
|
||||||
if (Settings.Stereo)
|
output_buffer_size *= 4;
|
||||||
output_buffer_size *= 2;
|
|
||||||
if (Settings.SixteenBitSound)
|
|
||||||
output_buffer_size *= 2;
|
|
||||||
if (output_buffer_size < 256)
|
if (output_buffer_size < 256)
|
||||||
output_buffer_size = 256;
|
output_buffer_size = 256;
|
||||||
|
|
||||||
|
@ -106,35 +103,16 @@ bool S9xOSSSoundDriver::open_device()
|
||||||
printf ("OK\n");
|
printf ("OK\n");
|
||||||
|
|
||||||
|
|
||||||
if (Settings.SixteenBitSound)
|
printf (" --> (Format: 16-bit)...");
|
||||||
{
|
|
||||||
printf (" --> (Format: 16-bit)...");
|
|
||||||
|
|
||||||
temp = AFMT_S16_LE;
|
temp = AFMT_S16_LE;
|
||||||
if (ioctl (filedes, SNDCTL_DSP_SETFMT, &temp) < 0)
|
if (ioctl (filedes, SNDCTL_DSP_SETFMT, &temp) < 0)
|
||||||
goto close_fail;
|
goto close_fail;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf (" --> (Format: 8-bit)...");
|
|
||||||
|
|
||||||
temp = AFMT_U8;
|
|
||||||
if (ioctl (filedes, SNDCTL_DSP_SETFMT, &temp) < 0)
|
|
||||||
goto close_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ("OK\n");
|
printf ("OK\n");
|
||||||
|
|
||||||
if (Settings.Stereo)
|
temp = 2;
|
||||||
{
|
printf (" --> (Stereo)...");
|
||||||
temp = 2;
|
|
||||||
printf (" --> (Stereo)...");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = 1;
|
|
||||||
printf (" --> (Mono)...");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioctl (filedes, SNDCTL_DSP_CHANNELS, &temp) < 0)
|
if (ioctl (filedes, SNDCTL_DSP_CHANNELS, &temp) < 0)
|
||||||
goto close_fail;
|
goto close_fail;
|
||||||
|
@ -160,9 +138,7 @@ bool S9xOSSSoundDriver::open_device()
|
||||||
|
|
||||||
printf (" --> (Buffer size: %d bytes, %dms latency)...",
|
printf (" --> (Buffer size: %d bytes, %dms latency)...",
|
||||||
output_buffer_size,
|
output_buffer_size,
|
||||||
(((output_buffer_size * 1000) >> (Settings.Stereo ? 1 : 0))
|
(output_buffer_size * 250) / Settings.SoundPlaybackRate);
|
||||||
>> (Settings.SixteenBitSound ? 1 : 0))
|
|
||||||
/ (Settings.SoundPlaybackRate));
|
|
||||||
|
|
||||||
printf ("OK\n");
|
printf ("OK\n");
|
||||||
|
|
||||||
|
@ -203,29 +179,28 @@ S9xOSSSoundDriver::samples_available ()
|
||||||
{
|
{
|
||||||
// Using rate control, we should always keep the emulator's sound buffers empty to
|
// Using rate control, we should always keep the emulator's sound buffers empty to
|
||||||
// maintain an accurate measurement.
|
// maintain an accurate measurement.
|
||||||
if (samples_to_write > (info.bytes >> (Settings.SixteenBitSound ? 1 : 0)))
|
if (samples_to_write > (info.bytes >> 1))
|
||||||
{
|
{
|
||||||
S9xClearSamples ();
|
S9xClearSamples ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
samples_to_write = MIN (info.bytes >> (Settings.SixteenBitSound ? 1 : 0),
|
samples_to_write = MIN (info.bytes >> 1, samples_to_write) & ~1;
|
||||||
samples_to_write);
|
|
||||||
|
|
||||||
if (samples_to_write < 0)
|
if (samples_to_write < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sound_buffer_size < samples_to_write << (Settings.SixteenBitSound ? 1 : 0))
|
if (sound_buffer_size < samples_to_write * 2)
|
||||||
{
|
{
|
||||||
sound_buffer = (uint8 *) realloc (sound_buffer, samples_to_write << (Settings.SixteenBitSound ? 1 : 0));
|
sound_buffer = (uint8 *) realloc (sound_buffer, samples_to_write * 2);
|
||||||
sound_buffer_size = samples_to_write << (Settings.SixteenBitSound ? 1 : 0);
|
sound_buffer_size = samples_to_write * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
S9xMixSamples (sound_buffer, samples_to_write);
|
S9xMixSamples (sound_buffer, samples_to_write);
|
||||||
|
|
||||||
bytes_written = 0;
|
bytes_written = 0;
|
||||||
bytes_to_write = samples_to_write << (Settings.SixteenBitSound ? 1 : 0);
|
bytes_to_write = samples_to_write * 2;
|
||||||
|
|
||||||
while (bytes_to_write > bytes_written)
|
while (bytes_to_write > bytes_written)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
static inline int
|
static inline int
|
||||||
frames_to_bytes (int frames)
|
frames_to_bytes (int frames)
|
||||||
{
|
{
|
||||||
return (frames * (Settings.SixteenBitSound ? 2 : 1) * (Settings.Stereo ? 2 : 1));
|
return frames * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -106,8 +106,8 @@ bool S9xPortAudioSoundDriver::open_device()
|
||||||
audio_stream = NULL;
|
audio_stream = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
param.channelCount = Settings.Stereo ? 2 : 1;
|
param.channelCount = 2;
|
||||||
param.sampleFormat = Settings.SixteenBitSound ? paInt16 : paUInt8;
|
param.sampleFormat = paInt16;
|
||||||
param.hostApiSpecificStreamInfo = NULL;
|
param.hostApiSpecificStreamInfo = NULL;
|
||||||
|
|
||||||
printf ("PortAudio sound driver initializing...\n");
|
printf ("PortAudio sound driver initializing...\n");
|
||||||
|
@ -200,14 +200,14 @@ S9xPortAudioSoundDriver::samples_available ()
|
||||||
{
|
{
|
||||||
// Using rate control, we should always keep the emulator's sound buffers empty to
|
// Using rate control, we should always keep the emulator's sound buffers empty to
|
||||||
// maintain an accurate measurement.
|
// maintain an accurate measurement.
|
||||||
if (frames < (S9xGetSampleCount () >> (Settings.Stereo ? 1 : 0)))
|
if (frames < (S9xGetSampleCount () >> 1))
|
||||||
{
|
{
|
||||||
S9xClearSamples ();
|
S9xClearSamples ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frames = MIN (frames, S9xGetSampleCount () >> (Settings.Stereo ? 1 : 0));
|
frames = MIN (frames, S9xGetSampleCount () >> 1);
|
||||||
bytes = frames_to_bytes (frames);
|
bytes = frames_to_bytes (frames);
|
||||||
|
|
||||||
if (sound_buffer_size < bytes || sound_buffer == NULL)
|
if (sound_buffer_size < bytes || sound_buffer == NULL)
|
||||||
|
@ -216,7 +216,7 @@ S9xPortAudioSoundDriver::samples_available ()
|
||||||
sound_buffer_size = bytes;
|
sound_buffer_size = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
S9xMixSamples (sound_buffer, frames << (Settings.Stereo ? 1 : 0));
|
S9xMixSamples (sound_buffer, frames << 1);
|
||||||
|
|
||||||
Pa_WriteStream (audio_stream, sound_buffer, frames);
|
Pa_WriteStream (audio_stream, sound_buffer, frames);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,12 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
static void
|
static void pulse_samples_available(void *data)
|
||||||
pulse_samples_available (void *data)
|
|
||||||
{
|
{
|
||||||
((S9xPulseSoundDriver *) data)->samples_available ();
|
((S9xPulseSoundDriver *)data)->samples_available();
|
||||||
}
|
}
|
||||||
|
|
||||||
S9xPulseSoundDriver::S9xPulseSoundDriver ()
|
S9xPulseSoundDriver::S9xPulseSoundDriver()
|
||||||
{
|
{
|
||||||
mainloop = NULL;
|
mainloop = NULL;
|
||||||
context = NULL;
|
context = NULL;
|
||||||
|
@ -25,94 +24,85 @@ S9xPulseSoundDriver::S9xPulseSoundDriver ()
|
||||||
buffer_size = 0;
|
buffer_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::init()
|
||||||
S9xPulseSoundDriver::init ()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::terminate()
|
||||||
S9xPulseSoundDriver::terminate ()
|
|
||||||
{
|
{
|
||||||
S9xSetSamplesAvailableCallback (NULL, NULL);
|
S9xSetSamplesAvailableCallback(NULL, NULL);
|
||||||
|
|
||||||
if (mainloop)
|
if (mainloop)
|
||||||
pa_threaded_mainloop_stop (mainloop);
|
pa_threaded_mainloop_stop(mainloop);
|
||||||
|
|
||||||
if (stream)
|
if (stream)
|
||||||
{
|
{
|
||||||
pa_stream_disconnect (stream);
|
pa_stream_disconnect(stream);
|
||||||
pa_stream_unref (stream);
|
pa_stream_unref(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context)
|
if (context)
|
||||||
{
|
{
|
||||||
pa_context_disconnect (context);
|
pa_context_disconnect(context);
|
||||||
pa_context_unref (context);
|
pa_context_unref(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainloop)
|
if (mainloop)
|
||||||
{
|
{
|
||||||
pa_threaded_mainloop_free (mainloop);
|
pa_threaded_mainloop_free(mainloop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::start()
|
||||||
S9xPulseSoundDriver::start ()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::stop()
|
||||||
S9xPulseSoundDriver::stop ()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::lock()
|
||||||
S9xPulseSoundDriver::lock ()
|
|
||||||
{
|
{
|
||||||
pa_threaded_mainloop_lock (mainloop);
|
pa_threaded_mainloop_lock(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::unlock()
|
||||||
S9xPulseSoundDriver::unlock ()
|
|
||||||
{
|
{
|
||||||
pa_threaded_mainloop_unlock (mainloop);
|
pa_threaded_mainloop_unlock(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::wait()
|
||||||
S9xPulseSoundDriver::wait ()
|
|
||||||
{
|
{
|
||||||
pa_threaded_mainloop_wait (mainloop);
|
pa_threaded_mainloop_wait(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void context_state_cb(pa_context *c, void *userdata)
|
||||||
context_state_cb (pa_context *c, void *userdata)
|
|
||||||
{
|
{
|
||||||
S9xPulseSoundDriver *driver = (S9xPulseSoundDriver *) userdata;
|
S9xPulseSoundDriver *driver = (S9xPulseSoundDriver *)userdata;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
state = pa_context_get_state (c);
|
state = pa_context_get_state(c);
|
||||||
|
|
||||||
if (state == PA_CONTEXT_READY ||
|
if (state == PA_CONTEXT_READY ||
|
||||||
state == PA_CONTEXT_FAILED ||
|
state == PA_CONTEXT_FAILED ||
|
||||||
state == PA_CONTEXT_TERMINATED)
|
state == PA_CONTEXT_TERMINATED)
|
||||||
{
|
{
|
||||||
pa_threaded_mainloop_signal (driver->mainloop, 0);
|
pa_threaded_mainloop_signal(driver->mainloop, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void stream_state_callback(pa_stream *p, void *userdata)
|
||||||
stream_state_callback (pa_stream *p, void *userdata)
|
|
||||||
{
|
{
|
||||||
S9xPulseSoundDriver *driver = (S9xPulseSoundDriver *) userdata;
|
S9xPulseSoundDriver *driver = (S9xPulseSoundDriver *)userdata;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
state = pa_stream_get_state (p);
|
state = pa_stream_get_state(p);
|
||||||
|
|
||||||
if (state == PA_STREAM_READY ||
|
if (state == PA_STREAM_READY ||
|
||||||
state == PA_STREAM_FAILED ||
|
state == PA_STREAM_FAILED ||
|
||||||
state == PA_STREAM_TERMINATED)
|
state == PA_STREAM_TERMINATED)
|
||||||
{
|
{
|
||||||
pa_threaded_mainloop_signal (driver->mainloop, 0);
|
pa_threaded_mainloop_signal(driver->mainloop, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,154 +113,154 @@ bool S9xPulseSoundDriver::open_device()
|
||||||
pa_buffer_attr buffer_attr;
|
pa_buffer_attr buffer_attr;
|
||||||
const pa_buffer_attr *actual_buffer_attr;
|
const pa_buffer_attr *actual_buffer_attr;
|
||||||
|
|
||||||
ss.channels = Settings.Stereo ? 2 : 1;
|
ss.channels = 2;
|
||||||
ss.format = Settings.SixteenBitSound ? PA_SAMPLE_S16NE : PA_SAMPLE_U8;
|
ss.format = PA_SAMPLE_S16NE;
|
||||||
ss.rate = Settings.SoundPlaybackRate;
|
ss.rate = Settings.SoundPlaybackRate;
|
||||||
|
|
||||||
buffer_attr.fragsize = -1;
|
buffer_attr.fragsize = -1;
|
||||||
buffer_attr.tlength = pa_usec_to_bytes (gui_config->sound_buffer_size * 1000, &ss);
|
buffer_attr.tlength = pa_usec_to_bytes(gui_config->sound_buffer_size * 1000, &ss);
|
||||||
buffer_attr.maxlength = -1;
|
buffer_attr.maxlength = buffer_attr.tlength * 2;
|
||||||
buffer_attr.minreq = -1;
|
buffer_attr.minreq = -1;
|
||||||
buffer_attr.prebuf = -1;
|
buffer_attr.prebuf = -1;
|
||||||
|
|
||||||
printf ("PulseAudio sound driver initializing...\n");
|
printf("PulseAudio sound driver initializing...\n");
|
||||||
|
|
||||||
printf (" --> (%dhz, %s %s, %dms)...",
|
printf(" --> (%dhz, %s %s, %dms)...",
|
||||||
Settings.SoundPlaybackRate,
|
Settings.SoundPlaybackRate,
|
||||||
Settings.SixteenBitSound ? "16-bit" : "8-bit",
|
"16-bit",
|
||||||
Settings.Stereo ? "Stereo" : "Mono",
|
"Stereo",
|
||||||
gui_config->sound_buffer_size);
|
gui_config->sound_buffer_size);
|
||||||
fflush (stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
mainloop = pa_threaded_mainloop_new ();
|
mainloop = pa_threaded_mainloop_new();
|
||||||
if (!mainloop)
|
if (!mainloop)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Failed to create mainloop.\n");
|
fprintf(stderr, "Failed to create mainloop.\n");
|
||||||
goto error0;
|
goto error0;
|
||||||
}
|
}
|
||||||
|
|
||||||
context = pa_context_new (pa_threaded_mainloop_get_api (mainloop), "Snes9x");
|
context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "Snes9x");
|
||||||
if (!context)
|
if (!context)
|
||||||
goto error1;
|
goto error1;
|
||||||
|
|
||||||
pa_context_set_state_callback (context, context_state_cb, this);
|
pa_context_set_state_callback(context, context_state_cb, this);
|
||||||
if ((err = pa_context_connect (context, NULL, PA_CONTEXT_NOFLAGS, NULL)) != 0)
|
if ((err = pa_context_connect(context, NULL, PA_CONTEXT_NOFLAGS, NULL)) != 0)
|
||||||
goto error2;
|
goto error2;
|
||||||
|
|
||||||
lock ();
|
lock();
|
||||||
|
|
||||||
if ((err = pa_threaded_mainloop_start (mainloop)) != 0)
|
if ((err = pa_threaded_mainloop_start(mainloop)) != 0)
|
||||||
goto error2;
|
goto error2;
|
||||||
wait ();
|
wait();
|
||||||
|
|
||||||
if ((err = pa_context_get_state (context)) != PA_CONTEXT_READY)
|
if ((err = pa_context_get_state(context)) != PA_CONTEXT_READY)
|
||||||
{
|
{
|
||||||
printf ("Coundn't create context: State: %d\n", err);
|
printf("Coundn't create context: State: %d\n", err);
|
||||||
goto error2;
|
goto error2;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = pa_stream_new (context, "Game", &ss, NULL);
|
stream = pa_stream_new(context, "Game", &ss, NULL);
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
goto error2;
|
goto error2;
|
||||||
|
|
||||||
pa_stream_set_state_callback (stream, stream_state_callback, this);
|
pa_stream_set_state_callback(stream, stream_state_callback, this);
|
||||||
|
|
||||||
if (pa_stream_connect_playback (stream,
|
if (pa_stream_connect_playback(stream,
|
||||||
NULL,
|
NULL,
|
||||||
&buffer_attr,
|
&buffer_attr,
|
||||||
PA_STREAM_ADJUST_LATENCY,
|
PA_STREAM_ADJUST_LATENCY,
|
||||||
NULL,
|
NULL,
|
||||||
NULL) < 0)
|
NULL) < 0)
|
||||||
goto error3;
|
goto error3;
|
||||||
wait ();
|
wait();
|
||||||
|
|
||||||
if (pa_stream_get_state (stream) != PA_STREAM_READY)
|
if (pa_stream_get_state(stream) != PA_STREAM_READY)
|
||||||
{
|
{
|
||||||
goto error3;
|
goto error3;
|
||||||
}
|
}
|
||||||
|
|
||||||
actual_buffer_attr = pa_stream_get_buffer_attr (stream);
|
actual_buffer_attr = pa_stream_get_buffer_attr(stream);
|
||||||
|
|
||||||
buffer_size = actual_buffer_attr->tlength;
|
buffer_size = actual_buffer_attr->tlength;
|
||||||
|
|
||||||
printf ("OK\n");
|
printf("OK\n");
|
||||||
|
|
||||||
S9xSetSamplesAvailableCallback (pulse_samples_available, this);
|
S9xSetSamplesAvailableCallback(pulse_samples_available, this);
|
||||||
|
|
||||||
unlock ();
|
unlock();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error3:
|
error3:
|
||||||
pa_stream_disconnect (stream);
|
pa_stream_disconnect(stream);
|
||||||
pa_stream_unref (stream);
|
pa_stream_unref(stream);
|
||||||
error2:
|
error2:
|
||||||
pa_context_disconnect (context);
|
pa_context_disconnect(context);
|
||||||
pa_context_unref (context);
|
pa_context_unref(context);
|
||||||
unlock ();
|
unlock();
|
||||||
error1:
|
error1:
|
||||||
pa_threaded_mainloop_free (mainloop);
|
pa_threaded_mainloop_free(mainloop);
|
||||||
error0:
|
error0:
|
||||||
printf ("Failed: %s\n", pa_strerror (err));
|
printf("Failed: %s\n", pa_strerror(err));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void S9xPulseSoundDriver::samples_available()
|
||||||
S9xPulseSoundDriver::samples_available ()
|
|
||||||
{
|
{
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
int samples;
|
int samples;
|
||||||
const pa_buffer_attr *buffer_attr;
|
const pa_buffer_attr *buffer_attr;
|
||||||
void *output_buffer = NULL;
|
void *output_buffer = NULL;
|
||||||
|
|
||||||
lock ();
|
lock();
|
||||||
bytes = pa_stream_writable_size (stream);
|
bytes = pa_stream_writable_size(stream);
|
||||||
buffer_attr = pa_stream_get_buffer_attr (stream);
|
buffer_attr = pa_stream_get_buffer_attr(stream);
|
||||||
unlock ();
|
unlock();
|
||||||
|
|
||||||
buffer_size = buffer_attr->tlength;
|
buffer_size = buffer_attr->tlength;
|
||||||
|
|
||||||
if (Settings.DynamicRateControl)
|
if (Settings.DynamicRateControl)
|
||||||
{
|
{
|
||||||
S9xUpdateDynamicRate (bytes, buffer_size);
|
S9xUpdateDynamicRate(bytes, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
S9xFinalizeSamples ();
|
S9xFinalizeSamples();
|
||||||
|
|
||||||
samples = S9xGetSampleCount ();
|
samples = S9xGetSampleCount();
|
||||||
|
|
||||||
if (Settings.DynamicRateControl)
|
if (Settings.DynamicRateControl)
|
||||||
{
|
{
|
||||||
if ((int) bytes < (samples << (Settings.SixteenBitSound ? 1 : 0)))
|
if ((int)bytes < (samples * 2))
|
||||||
{
|
{
|
||||||
S9xClearSamples ();
|
S9xClearSamples();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = MIN ((int) bytes, (samples << (Settings.SixteenBitSound ? 1 : 0)));
|
bytes = MIN((int)bytes, samples * 2) & ~1;
|
||||||
|
|
||||||
if (!bytes)
|
if (!bytes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock ();
|
lock();
|
||||||
|
|
||||||
if (pa_stream_begin_write (stream, &output_buffer, &bytes) != 0)
|
if (pa_stream_begin_write(stream, &output_buffer, &bytes) != 0)
|
||||||
{
|
{
|
||||||
pa_stream_flush (stream, NULL, NULL);
|
pa_stream_flush(stream, NULL, NULL);
|
||||||
unlock ();
|
unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes <= 0 || !output_buffer)
|
if (bytes <= 0 || !output_buffer)
|
||||||
{
|
{
|
||||||
unlock ();
|
unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
S9xMixSamples ((uint8 *) output_buffer, bytes >> (Settings.SixteenBitSound ? 1 : 0));
|
S9xMixSamples((uint8 *)output_buffer, bytes >> 1);
|
||||||
pa_stream_write (stream, output_buffer, bytes, NULL, 0, PA_SEEK_RELATIVE);
|
pa_stream_write(stream, output_buffer, bytes, NULL, 0, PA_SEEK_RELATIVE);
|
||||||
|
|
||||||
unlock ();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue