aboutsummaryrefslogtreecommitdiff
path: root/source/apu_blargg.c
diff options
context:
space:
mode:
authorTwinaphex2018-03-14 22:48:44 +0100
committerGitHub2018-03-14 22:48:44 +0100
commit0f00cc72e8801a9b7ac0afe3e535897d5fbb0181 (patch)
tree34fd52905295056bd4140333dcd7b8c2117243bf /source/apu_blargg.c
parentea4775801b424594e309a3413815b67cc53d6ac1 (diff)
parent4420a2155cba408ec20a340ecd06d9fdad56ab8f (diff)
downloadsnes9x2005-0f00cc72e8801a9b7ac0afe3e535897d5fbb0181.tar.gz
snes9x2005-0f00cc72e8801a9b7ac0afe3e535897d5fbb0181.tar.bz2
snes9x2005-0f00cc72e8801a9b7ac0afe3e535897d5fbb0181.zip
Merge pull request #52 from Dwedit/master
Flush audio buffer at end of retro_run, and bypass resampler
Diffstat (limited to 'source/apu_blargg.c')
-rw-r--r--source/apu_blargg.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/source/apu_blargg.c b/source/apu_blargg.c
index d87d8d3..e335bbe 100644
--- a/source/apu_blargg.c
+++ b/source/apu_blargg.c
@@ -2891,7 +2891,6 @@ static int32_t r_left[4], r_right[4];
#define SPACE_EMPTY() (rb_buffer_size - rb_size)
#define SPACE_FILLED() (rb_size)
#define MAX_WRITE() (SPACE_EMPTY() >> 1)
-#define AVAIL() (((((uint32_t) rb_size) << 14) - r_frac) / r_step * 2)
#define RESAMPLER_MIN(a, b) ((a) < (b) ? (a) : (b))
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
@@ -2934,6 +2933,34 @@ static void resampler_time_ratio(double ratio)
static void resampler_read(int16_t *data, int32_t num_samples)
{
+ if (r_step == 65536)
+ {
+ //direct copy if we are not resampling
+ int bytesUntilBufferEnd = rb_buffer_size - rb_start;
+ while (num_samples > 0)
+ {
+ int bytesToConsume = num_samples * sizeof(int16_t);
+ if (bytesToConsume >= bytesUntilBufferEnd)
+ {
+ bytesToConsume = bytesUntilBufferEnd;
+ }
+ if (rb_start >= rb_buffer_size)
+ {
+ rb_start = 0;
+ }
+ memcpy(data, &rb_buffer[rb_start], bytesToConsume);
+ data += bytesToConsume / sizeof(int16_t);
+ rb_start += bytesToConsume;
+ rb_size -= bytesToConsume;
+ num_samples -= bytesToConsume / sizeof(int16_t);
+ if (rb_start >= rb_buffer_size)
+ {
+ rb_start = 0;
+ }
+ }
+ return;
+ }
+
int32_t i_position, o_position, consumed;
int16_t *internal_buffer;
@@ -3045,7 +3072,7 @@ static INLINE void resampler_resize (int32_t num_samples)
bool S9xMixSamples (int16_t *buffer, uint32_t sample_count)
{
- if (AVAIL() >= (sample_count + lag))
+ if (S9xGetSampleCount() >= (sample_count + lag))
{
resampler_read(buffer, sample_count);
if (lag == lag_master)
@@ -3065,7 +3092,11 @@ bool S9xMixSamples (int16_t *buffer, uint32_t sample_count)
int32_t S9xGetSampleCount()
{
- return AVAIL();
+ if (r_step == 65536)
+ {
+ return rb_size / sizeof(int16_t);
+ }
+ return (((((uint32_t)rb_size) << 14) - r_frac) / r_step * 2);
}
/* Sets destination for output samples */