Skip to content

Commit

Permalink
Fix Windows build. Tweak XAudio a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alias Letterman committed Feb 9, 2019
1 parent 845366f commit b1039e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions apu/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ bool8 S9xMixSamples(uint8 *dest, int sample_count)
}
}

if (spc::resampler->space_empty() >= 535 * 2)
if (spc::resampler->space_empty() >= 535 * 2 || !Settings.SoundSync ||
Settings.TurboMode || Settings.Mute)
spc::sound_in_sync = true;
else
spc::sound_in_sync = false;
Expand All @@ -128,7 +129,8 @@ void S9xLandSamples(void)
if (spc::callback != NULL)
spc::callback(spc::callback_data);

if (spc::resampler->space_empty() >= 535 * 2)
if (spc::resampler->space_empty() >= 535 * 2 || !Settings.SoundSync ||
Settings.TurboMode || Settings.Mute)
spc::sound_in_sync = true;
else
spc::sound_in_sync = false;
Expand Down
4 changes: 2 additions & 2 deletions apu/resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class Resampler

while (r_frac <= 1.0 && o_position < num_samples)
{
hermite_val[0] = hermite(r_frac, r_left[0], r_left[1], r_left[2], r_left[3]);
hermite_val[1] = hermite(r_frac, r_right[0], r_right[1], r_right[2], r_right[3]);
hermite_val[0] = (int)hermite(r_frac, r_left[0], r_left[1], r_left[2], r_left[3]);
hermite_val[1] = (int)hermite(r_frac, r_right[0], r_right[1], r_right[2], r_right[3]);
data[o_position] = short_clamp(hermite_val[0]);
data[o_position + 1] = short_clamp(hermite_val[1]);

Expand Down
1 change: 1 addition & 0 deletions msu1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "memmap.h"
#include "display.h"
#include "msu1.h"
#include "apu/resampler.h"
#include "apu/bapu/dsp/blargg_endian.h"
#include <fstream>
#include <sys/stat.h>
Expand Down
2 changes: 1 addition & 1 deletion msu1.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef _MSU1_H_
#define _MSU1_H_
#include "snes9x.h"
#include "apu/resampler.h"

#define MSU1_REVISION 0x02

Expand Down Expand Up @@ -52,6 +51,7 @@ void S9xMSU1Generate(size_t sample_count);
uint8 S9xMSU1ReadPort(uint8 port);
void S9xMSU1WritePort(uint8 port, uint8 byte);
size_t S9xMSU1Samples(void);
class Resampler;
void S9xMSU1SetOutput(Resampler *resampler);
void S9xMSU1PostLoadState(void);

Expand Down
11 changes: 6 additions & 5 deletions win32/CXAudio2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool CXAudio2::InitVoices(void)
wfx.cbSize = 0;

if( FAILED(hr = pXAudio2->CreateSourceVoice(&pSourceVoice, (WAVEFORMATEX*)&wfx,
XAUDIO2_VOICE_USEFILTER, XAUDIO2_DEFAULT_FREQ_RATIO, this, NULL, NULL ) ) ) {
XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO, this, NULL, NULL ) ) ) {
DXTRACE_ERR_MSGBOX(TEXT("Unable to create source voice."),hr);
return false;
}
Expand Down Expand Up @@ -305,11 +305,12 @@ void CXAudio2::ProcessSound()

if (partialOffset != 0) {
BYTE *offsetBuffer = soundBuffer + writeOffset + partialOffset;
UINT32 samplesleftinblock = (singleBufferBytes - partialOffset) >> (Settings.SixteenBitSound ? 1 : 0);
if (availableSamples < ((singleBufferBytes - partialOffset) >> (Settings.SixteenBitSound ? 1 : 0)))
UINT32 samplesleftinblock = (singleBufferBytes - partialOffset) >> 1;

if (availableSamples <= samplesleftinblock)
{
S9xMixSamples(offsetBuffer, availableSamples);
partialOffset += availableSamples << (Settings.SixteenBitSound ? 1 : 0);
partialOffset += availableSamples << 1;
availableSamples = 0;
}
else
Expand All @@ -323,7 +324,7 @@ void CXAudio2::ProcessSound()
}
}

while (availableSamples > singleBufferSamples && bufferCount < blockCount) {
while (availableSamples >= singleBufferSamples && bufferCount < blockCount) {
BYTE *curBuffer = soundBuffer + writeOffset;
S9xMixSamples(curBuffer, singleBufferSamples);
PushBuffer(singleBufferBytes, curBuffer, NULL);
Expand Down

0 comments on commit b1039e7

Please sign in to comment.