Add single sample push.

This commit is contained in:
Brandon Wright 2019-02-08 20:32:42 -06:00
parent 36406a6627
commit ac03facaa9
2 changed files with 19 additions and 4 deletions

View File

@ -33,7 +33,7 @@ namespace SNES
{ {
#include "bapu/dsp/blargg_endian.h" #include "bapu/dsp/blargg_endian.h"
CPU cpu; CPU cpu;
} } // namespace SNES
namespace spc namespace spc
{ {
@ -57,7 +57,7 @@ static uint32 ratio_numerator = APU_NUMERATOR_NTSC;
static uint32 ratio_denominator = APU_DENOMINATOR_NTSC; static uint32 ratio_denominator = APU_DENOMINATOR_NTSC;
static double dynamic_rate_multiplier = 1.0; static double dynamic_rate_multiplier = 1.0;
} } // namespace spc
namespace msu namespace msu
{ {
@ -66,7 +66,7 @@ static const int buffer_size = MAX_SAMPLE_FRAMES * 6;
static uint8 mixing_buffer[buffer_size]; static uint8 mixing_buffer[buffer_size];
static Resampler *resampler = NULL; static Resampler *resampler = NULL;
static std::vector<uint16> resample_buffer; static std::vector<uint16> resample_buffer;
} } // namespace msu
static void UpdatePlaybackRate(void); static void UpdatePlaybackRate(void);
static void SPCSnapshotCallback(void); static void SPCSnapshotCallback(void);

View File

@ -95,12 +95,27 @@ struct Resampler
return true; return true;
} }
inline void push(int16_t l, int16_t r)
{
if (space_empty() >= 2)
{
int end = start + size;
if (end > buffer_size)
end -= buffer_size;
buffer[end] = l;
buffer[end + 1] = r;
size += 2;
}
}
inline bool push(int16_t *src, int num_samples) inline bool push(int16_t *src, int num_samples)
{ {
if (space_empty() < num_samples) if (space_empty() < num_samples)
return false; return false;
int end = (start + size) % buffer_size; int end = start + size;
if (end > buffer_size)
end -= buffer_size;
int first_write_size = min(num_samples, buffer_size - end); int first_write_size = min(num_samples, buffer_size - end);
memcpy(buffer + end, src, first_write_size * 2); memcpy(buffer + end, src, first_write_size * 2);