bsnes/asnes/audio/audio.cpp
byuu 81f43a4d01 Update to snes-20100807 release.
This represents a major code restructuring. The dot-based and
scanline-based renderers are now split into two separate core
libraries, asnes and bsnes.

For now at least, these are -internal- names. I'm not entirely decided
on how I'm going to handle releasing these two separate builds.
Regardless, the folders need names.

asnes has had all of the processor subfolders collapsed back into
their parent folders. In other words, ppu's functions were moved into
ppu/sppu, and then ppu was deleted, and then ppu/sppu became the new
ppu. Repeat this for the cpu, smp and dsp and there you go.

asnes/dsp also removed the DSP_STATE_MACHINE option. This was done for
the sake of consistency with the rest of the core.

asnes' debugger mode is currently extremely broken, but I will be
fixing it in time.

And for now, bsnes has kept the processor abstraction layer. I may
keep it around, not sure yet. It doesn't hurt speed or anything, so
I'm not too worried about making a decision right away.

I may throw snesfilter, snesreader and supergameboy into this folder,
just to have everything in one place. The alternate GUI forks are
definitely going in there as dotnet, cocoa and python.

Compiled output goes to the out/ folder now, to prevent conflicts with
a file and folder named bsnes, for instance.
2010-08-07 15:07:24 +00:00

85 lines
2 KiB
C++

#ifdef SYSTEM_CPP
Audio audio;
void Audio::coprocessor_enable(bool state) {
coprocessor = state;
dsp_rdoffset = cop_rdoffset = 0;
dsp_wroffset = cop_wroffset = 0;
dsp_length = cop_length = 0;
r_sum_l = r_sum_r = 0;
}
void Audio::coprocessor_frequency(double input_frequency) {
double output_frequency;
output_frequency = system.apu_frequency() / 768.0;
r_step = input_frequency / output_frequency;
r_frac = 0;
}
void Audio::sample(int16 left, int16 right) {
if(coprocessor == false) {
system.interface->audio_sample(left, right);
} else {
dsp_buffer[dsp_wroffset] = ((uint16)left << 0) + ((uint16)right << 16);
dsp_wroffset = (dsp_wroffset + 1) & 32767;
dsp_length = (dsp_length + 1) & 32767;
flush();
}
}
void Audio::coprocessor_sample(int16 left, int16 right) {
if(r_frac >= 1.0) {
r_frac -= 1.0;
r_sum_l += left;
r_sum_r += right;
return;
}
r_sum_l += left * r_frac;
r_sum_r += right * r_frac;
uint16 output_left = sclamp<16>(int(r_sum_l / r_step));
uint16 output_right = sclamp<16>(int(r_sum_r / r_step));
double first = 1.0 - r_frac;
r_sum_l = left * first;
r_sum_r = right * first;
r_frac = r_step - first;
cop_buffer[cop_wroffset] = (output_left << 0) + (output_right << 16);
cop_wroffset = (cop_wroffset + 1) & 32767;
cop_length = (cop_length + 1) & 32767;
flush();
}
void Audio::init() {
}
void Audio::flush() {
while(dsp_length > 0 && cop_length > 0) {
uint32 dsp_sample = dsp_buffer[dsp_rdoffset];
uint32 cop_sample = cop_buffer[cop_rdoffset];
dsp_rdoffset = (dsp_rdoffset + 1) & 32767;
cop_rdoffset = (cop_rdoffset + 1) & 32767;
dsp_length--;
cop_length--;
int dsp_left = (int16)(dsp_sample >> 0);
int dsp_right = (int16)(dsp_sample >> 16);
int cop_left = (int16)(cop_sample >> 0);
int cop_right = (int16)(cop_sample >> 16);
system.interface->audio_sample(
sclamp<16>((dsp_left + cop_left ) / 2),
sclamp<16>((dsp_right + cop_right) / 2)
);
}
}
#endif