SAA1099: fix SAASound on MSVC

This commit is contained in:
tildearrow 2024-04-27 23:52:19 -05:00
parent 4679501f75
commit aac3b719be
11 changed files with 51 additions and 50 deletions

View file

@ -3,3 +3,4 @@
this is a modified version of SAASound for Furnace. this is a modified version of SAASound for Furnace.
it fixes some warnings and doesn't use its CMakeLists because I need to static-link it and disable config file support. it fixes some warnings and doesn't use its CMakeLists because I need to static-link it and disable config file support.
it also replaces long with int, to fix a discrepancy between MSVC and GCC/Clang.

View file

@ -266,7 +266,7 @@ inline void CSAAEnv::Tick(void)
else // (m_nPhasePosition < 16) else // (m_nPhasePosition < 16)
{ {
// still within the same phase; // still within the same phase;
// but, importantly, we are no longer at the start of the phase ... // but, importantly, we are no inter at the start of the phase ...
// so new data cannot be acted on immediately, and must // so new data cannot be acted on immediately, and must
// be buffered // be buffered
m_bEnvelopeEnded = false; m_bEnvelopeEnded = false;
@ -365,7 +365,7 @@ inline void CSAAEnv::SetNewEnvData(int nData)
m_bEnvelopeEnded = false; m_bEnvelopeEnded = false;
// is this right? // is this right?
// YES. See test case EnvExt_34c (setting data multiple times // YES. See test case EnvExt_34c (setting data multiple times
// when at a point (3) resets the waveform so you're no longer // when at a point (3) resets the waveform so you're no inter
// at a point (3). // at a point (3).
} }
else else

View file

@ -173,7 +173,7 @@ void CSAAFreq::_SetClockRate(int nClockRate)
// initialise the frequency table based on the SAA clockrate // initialise the frequency table based on the SAA clockrate
// Each item in m_FreqTable corresponds to the frequency calculated by // Each item in m_FreqTable corresponds to the frequency calculated by
// the standard formula (15625 << octave) / (511 - offset) // the standard formula (15625 << octave) / (511 - offset)
// then multiplied by 8192 (and represented as a long integer value). // then multiplied by 8192 (and represented as a int integer value).
// We are therefore using 12 bits (i.e. 2^12 = 4096) as fractional part. // We are therefore using 12 bits (i.e. 2^12 = 4096) as fractional part.
// The reason we multiply by 8192, not 4096, is that we use this as a counter // The reason we multiply by 8192, not 4096, is that we use this as a counter
// to toggle the oscillator state, so we need to count half-waves (i.e. twice // to toggle the oscillator state, so we need to count half-waves (i.e. twice
@ -188,7 +188,7 @@ void CSAAFreq::_SetClockRate(int nClockRate)
int ix = 0; int ix = 0;
for (int nOctave = 0; nOctave < 8; nOctave++) for (int nOctave = 0; nOctave < 8; nOctave++)
for (int nOffset = 0; nOffset < 256; nOffset++) for (int nOffset = 0; nOffset < 256; nOffset++)
m_FreqTable[ix++] = (unsigned long)((8192.0 * 15625.0 * double(1 << nOctave) * (double(nClockRate) / 8000000.0)) / (511.0 - double(nOffset))); m_FreqTable[ix++] = (unsigned int)((8192.0 * 15625.0 * double(1 << nOctave) * (double(nClockRate) / 8000000.0)) / (511.0 - double(nOffset)));
} }
} }
#endif #endif

View file

@ -17,18 +17,18 @@ private:
// 'load in' the data for the static frequency lookup table // 'load in' the data for the static frequency lookup table
// precomputed for a fixed clockrate // precomputed for a fixed clockrate
// See: tools/freqdat.py // See: tools/freqdat.py
const static unsigned long m_FreqTable[2048]; const static unsigned int m_FreqTable[2048];
#else #else
// we'll calculate the frequency lookup table at runtime. // we'll calculate the frequency lookup table at runtime.
unsigned long m_FreqTable[2048]; unsigned int m_FreqTable[2048];
unsigned long m_nClockRate; unsigned int m_nClockRate;
#endif #endif
unsigned long m_nCounter; uint64_t m_nCounter;
unsigned long m_nAdd; uint64_t m_nAdd;
unsigned long m_nCounter_low; unsigned int m_nCounter_low;
unsigned int m_nOversample; unsigned int m_nOversample;
unsigned long m_nCounterLimit_low; unsigned int m_nCounterLimit_low;
int m_nLevel; int m_nLevel;
int m_nCurrentOffset; int m_nCurrentOffset;
@ -39,7 +39,7 @@ private:
bool m_bNewData; bool m_bNewData;
bool m_bSync; bool m_bSync;
unsigned long m_nSampleRate; uint64_t m_nSampleRate;
CSAANoise * const m_pcConnectedNoiseGenerator; CSAANoise * const m_pcConnectedNoiseGenerator;
CSAAEnv * const m_pcConnectedEnvGenerator; CSAAEnv * const m_pcConnectedEnvGenerator;
const int m_nConnectedMode; // 0 = nothing; 1 = envgenerator; 2 = noisegenerator const int m_nConnectedMode; // 0 = nothing; 1 = envgenerator; 2 = noisegenerator

View file

@ -230,12 +230,12 @@ unsigned short CSAASoundInternal::GetCurrentBytesPerSample(void)
} }
} }
unsigned long CSAASoundInternal::GetCurrentSampleRate(void) unsigned int CSAASoundInternal::GetCurrentSampleRate(void)
{ {
return CSAASound::GetSampleRate(m_uParamRate); return CSAASound::GetSampleRate(m_uParamRate);
} }
/*static*/ unsigned long CSAASound::GetSampleRate(SAAPARAM uParam) // static member function /*static*/ unsigned int CSAASound::GetSampleRate(SAAPARAM uParam) // static member function
{ {
switch (uParam & SAAP_MASK_SAMPLERATE) switch (uParam & SAAP_MASK_SAMPLERATE)
{ {
@ -298,13 +298,13 @@ void scale_for_output(unsigned int left_input, unsigned int right_input,
*pBuffer++ = (right_output >> 8) & 0x00ff; *pBuffer++ = (right_output >> 8) & 0x00ff;
} }
void CSAASoundInternal::GenerateMany(BYTE* pBuffer, unsigned long nSamples, DivDispatchOscBuffer** oscBuf) void CSAASoundInternal::GenerateMany(BYTE* pBuffer, unsigned int nSamples, DivDispatchOscBuffer** oscBuf)
{ {
unsigned int left_mixed, right_mixed; unsigned int left_mixed, right_mixed;
#if defined(DEBUGSAA) || defined(USE_CONFIG_FILE) #if defined(DEBUGSAA) || defined(USE_CONFIG_FILE)
BYTE* pBufferStart = pBuffer; BYTE* pBufferStart = pBuffer;
unsigned long nTotalSamples = nSamples; unsigned int nTotalSamples = nSamples;
#endif #endif
#if defined(DO_BOOST) #if defined(DO_BOOST)
@ -388,7 +388,7 @@ void CSAASoundInternal::GenerateMany(BYTE* pBuffer, unsigned long nSamples, DivD
if (m_Config.m_bGeneratePcmLogs) if (m_Config.m_bGeneratePcmLogs)
{ {
#endif #endif
m_pcmfile.write((const char *)pBufferStart, nTotalSamples * (unsigned long)GetCurrentBytesPerSample()); m_pcmfile.write((const char *)pBufferStart, nTotalSamples * (unsigned int)GetCurrentBytesPerSample());
m_nDebugSample += nTotalSamples; m_nDebugSample += nTotalSamples;
#ifdef USE_CONFIG_FILE #ifdef USE_CONFIG_FILE
} }

View file

@ -41,7 +41,7 @@ private:
SAAConfig m_Config; SAAConfig m_Config;
#endif #endif
#if defined(DEBUGSAA) || defined(USE_CONFIG_FILE) #if defined(DEBUGSAA) || defined(USE_CONFIG_FILE)
unsigned long m_nDebugSample; unsigned int m_nDebugSample;
std::ofstream m_dbgfile, m_pcmfile; std::ofstream m_dbgfile, m_pcmfile;
#if defined(USE_CONFIG_FILE) #if defined(USE_CONFIG_FILE)
std::ofstream m_channel_pcmfile[6]; std::ofstream m_channel_pcmfile[6];
@ -64,12 +64,12 @@ public:
void Clear(void); void Clear(void);
SAAPARAM GetCurrentSoundParameters(void); SAAPARAM GetCurrentSoundParameters(void);
unsigned long GetCurrentSampleRate(void); unsigned int GetCurrentSampleRate(void);
static unsigned long GetSampleRate(SAAPARAM uParam); static unsigned int GetSampleRate(SAAPARAM uParam);
unsigned short GetCurrentBytesPerSample(void); unsigned short GetCurrentBytesPerSample(void);
static unsigned short GetBytesPerSample(SAAPARAM uParam); static unsigned short GetBytesPerSample(SAAPARAM uParam);
void GenerateMany(BYTE * pBuffer, unsigned long nSamples, DivDispatchOscBuffer** oscBuf); void GenerateMany(BYTE * pBuffer, unsigned int nSamples, DivDispatchOscBuffer** oscBuf);
}; };

View file

@ -36,7 +36,7 @@ m_nRand(1)
m_nAdd = m_nAddBase; m_nAdd = m_nAddBase;
} }
CSAANoise::CSAANoise(unsigned long seed) CSAANoise::CSAANoise(unsigned int seed)
: :
m_nCounter(0), m_nCounter(0),
m_nCounter_low(0), m_nCounter_low(0),
@ -65,7 +65,7 @@ void CSAANoise::_SetClockRate(int nClockRate)
m_nAddBase = nClockRate << (12 - 8); m_nAddBase = nClockRate << (12 - 8);
} }
void CSAANoise::Seed(unsigned long seed) void CSAANoise::Seed(unsigned int seed)
{ {
m_nRand = seed; m_nRand = seed;
} }

View file

@ -10,25 +10,25 @@
class CSAANoise class CSAANoise
{ {
private: private:
unsigned long m_nCounter; unsigned int m_nCounter;
unsigned long m_nAdd; uint64_t m_nAdd;
unsigned long m_nCounter_low; unsigned int m_nCounter_low;
unsigned int m_nOversample; unsigned int m_nOversample;
unsigned long m_nCounterLimit_low; unsigned int m_nCounterLimit_low;
bool m_bSync; // see description of "SYNC" bit of register 28 bool m_bSync; // see description of "SYNC" bit of register 28
unsigned long m_nSampleRate; // = 44100 when RateMode=0, for example uint64_t m_nSampleRate; // = 44100 when RateMode=0, for example
int m_nSourceMode; int m_nSourceMode;
unsigned long m_nAddBase; // nAdd for 31.25 kHz noise at 44.1 kHz samplerate uint64_t m_nAddBase; // nAdd for 31.25 kHz noise at 44.1 kHz samplerate
// pseudo-random number generator // pseudo-random number generator
unsigned long m_nRand; unsigned int m_nRand;
void ChangeLevel(void); void ChangeLevel(void);
public: public:
CSAANoise(); CSAANoise();
CSAANoise(unsigned long seed); CSAANoise(unsigned int seed);
~CSAANoise(); ~CSAANoise();
void SetSource(int nSource); void SetSource(int nSource);
@ -36,7 +36,7 @@ public:
void _SetSampleRate(int nSampleRate); void _SetSampleRate(int nSampleRate);
void _SetOversample(unsigned int oversample); void _SetOversample(unsigned int oversample);
void _SetClockRate(int nClockRate); void _SetClockRate(int nClockRate);
void Seed(unsigned long seed); void Seed(unsigned int seed);
void Tick(void); void Tick(void);
int Level(void) const; int Level(void) const;

View file

@ -69,17 +69,17 @@ unsigned short SAAAPI SAASNDGetBytesPerSample(SAAPARAM uParam)
return CSAASound::GetBytesPerSample(uParam); return CSAASound::GetBytesPerSample(uParam);
} }
unsigned long SAAAPI SAASNDGetCurrentSampleRate(SAASND object) unsigned int SAAAPI SAASNDGetCurrentSampleRate(SAASND object)
{ {
return ((LPCSAASOUND)(object))->GetCurrentSampleRate(); return ((LPCSAASOUND)(object))->GetCurrentSampleRate();
} }
unsigned long SAAAPI SAASNDGetSampleRate(SAAPARAM uParam) unsigned int SAAAPI SAASNDGetSampleRate(SAAPARAM uParam)
{ {
return CSAASound::GetSampleRate(uParam); return CSAASound::GetSampleRate(uParam);
} }
void SAAAPI SAASNDGenerateMany(SAASND object, BYTE * pBuffer, unsigned long nSamples) void SAAAPI SAASNDGenerateMany(SAASND object, BYTE * pBuffer, unsigned int nSamples)
{ {
((LPCSAASOUND)(object))->GenerateMany(pBuffer, nSamples, NULL); ((LPCSAASOUND)(object))->GenerateMany(pBuffer, nSamples, NULL);
} }

View file

@ -35,7 +35,7 @@
#define SAAP_MONO 0x00000001 #define SAAP_MONO 0x00000001
// Bitmasks for use with GetCurrentSoundParameters, for example, // Bitmasks for use with GetCurrentSoundParameters, for example,
// unsigned long CurrentSampleRateParameter = GetCurrentSoundParameters() // unsigned int CurrentSampleRateParameter = GetCurrentSoundParameters()
#define SAAP_MASK_FILTER 0x00000f00 #define SAAP_MASK_FILTER 0x00000f00
#define SAAP_MASK_FILTER_HIGHPASS 0x00000c00 #define SAAP_MASK_FILTER_HIGHPASS 0x00000c00
#define SAAP_MASK_FILTER_OVERSAMPLE 0x00000300 #define SAAP_MASK_FILTER_OVERSAMPLE 0x00000300
@ -43,7 +43,7 @@
#define SAAP_MASK_BITDEPTH 0x0000000c #define SAAP_MASK_BITDEPTH 0x0000000c
#define SAAP_MASK_CHANNELS 0x00000003 #define SAAP_MASK_CHANNELS 0x00000003
typedef unsigned long SAAPARAM; typedef unsigned int SAAPARAM;
#ifndef BYTE #ifndef BYTE
@ -85,10 +85,10 @@ BYTE EXTAPI SAASNDReadAddress(SAASND object);
SAAPARAM EXTAPI SAASNDGetCurrentSoundParameters(SAASND object); SAAPARAM EXTAPI SAASNDGetCurrentSoundParameters(SAASND object);
unsigned short EXTAPI SAASNDGetCurrentBytesPerSample(SAASND object); unsigned short EXTAPI SAASNDGetCurrentBytesPerSample(SAASND object);
unsigned short EXTAPI SAASNDGetBytesPerSample(SAAPARAM uParam); unsigned short EXTAPI SAASNDGetBytesPerSample(SAAPARAM uParam);
unsigned long EXTAPI SAASNDGetCurrentSampleRate(SAASND object); unsigned int EXTAPI SAASNDGetCurrentSampleRate(SAASND object);
unsigned long EXTAPI SAASNDGetSampleRate(SAAPARAM uParam); unsigned int EXTAPI SAASNDGetSampleRate(SAAPARAM uParam);
void EXTAPI SAASNDGenerateMany(SAASND object, BYTE * pBuffer, unsigned long nSamples); void EXTAPI SAASNDGenerateMany(SAASND object, BYTE * pBuffer, unsigned int nSamples);
void EXTAPI SAASNDSetClockRate(SAASND object, unsigned int nClockRate); void EXTAPI SAASNDSetClockRate(SAASND object, unsigned int nClockRate);
void EXTAPI SAASNDSetSampleRate(SAASND object, unsigned int nSampleRate); void EXTAPI SAASNDSetSampleRate(SAASND object, unsigned int nSampleRate);

View file

@ -3,12 +3,12 @@
// SAASound.h: interface for the CSAASound class. // SAASound.h: interface for the CSAASound class.
// //
// This corresponds to the public (exported) DLL interface, so all // This corresponds to the public (exported) DLL interface, so all
// APIs and client factory methods belong here. // APIs and client factory methods beint here.
// //
// Compatibility notes : the intention is for this to be fully backwards // Compatibility notes : the intention is for this to be fully backwards
// compatible across minor and patch versions. Any backwards breaking changes // compatible across minor and patch versions. Any backwards breaking changes
// should be reflected as a major version increment. New functionality can be added // should be reflected as a major version increment. New functionality can be added
// in minor versions so long as backwards compatiblity is maintained // in minor versions so int as backwards compatiblity is maintained
// //
// Version 3.3.0 (4th Dec 2018) // Version 3.3.0 (4th Dec 2018)
// //
@ -37,7 +37,7 @@
#define SAAP_MONO 0x00000001 #define SAAP_MONO 0x00000001
// Bitmasks for use with GetCurrentSoundParameters, for example, // Bitmasks for use with GetCurrentSoundParameters, for example,
// unsigned long CurrentSampleRateParameter = GetCurrentSoundParameters() // unsigned int CurrentSampleRateParameter = GetCurrentSoundParameters()
#define SAAP_MASK_FILTER 0x00000f00 #define SAAP_MASK_FILTER 0x00000f00
#define SAAP_MASK_FILTER_HIGHPASS 0x00000c00 #define SAAP_MASK_FILTER_HIGHPASS 0x00000c00
#define SAAP_MASK_FILTER_OVERSAMPLE 0x00000300 #define SAAP_MASK_FILTER_OVERSAMPLE 0x00000300
@ -45,7 +45,7 @@
#define SAAP_MASK_BITDEPTH 0x0000000c #define SAAP_MASK_BITDEPTH 0x0000000c
#define SAAP_MASK_CHANNELS 0x00000003 #define SAAP_MASK_CHANNELS 0x00000003
typedef unsigned long SAAPARAM; typedef unsigned int SAAPARAM;
#ifndef BYTE #ifndef BYTE
@ -76,12 +76,12 @@ public:
virtual BYTE ReadAddress () = 0; virtual BYTE ReadAddress () = 0;
virtual SAAPARAM GetCurrentSoundParameters () = 0; virtual SAAPARAM GetCurrentSoundParameters () = 0;
virtual unsigned long GetCurrentSampleRate () = 0; virtual unsigned int GetCurrentSampleRate () = 0;
static unsigned long GetSampleRate (SAAPARAM uParam); static unsigned int GetSampleRate (SAAPARAM uParam);
virtual unsigned short GetCurrentBytesPerSample () = 0; virtual unsigned short GetCurrentBytesPerSample () = 0;
static unsigned short GetBytesPerSample (SAAPARAM uParam); static unsigned short GetBytesPerSample (SAAPARAM uParam);
virtual void GenerateMany (BYTE * pBuffer, unsigned long nSamples, DivDispatchOscBuffer** oscBuf) = 0; virtual void GenerateMany (BYTE * pBuffer, unsigned int nSamples, DivDispatchOscBuffer** oscBuf) = 0;
virtual void SetClockRate(unsigned int nClockRate) = 0; virtual void SetClockRate(unsigned int nClockRate) = 0;
virtual void SetSampleRate(unsigned int nSampleRate) = 0; virtual void SetSampleRate(unsigned int nSampleRate) = 0;
@ -115,10 +115,10 @@ void SAAAPI SAASNDClear(SAASND object);
SAAPARAM SAAAPI SAASNDGetCurrentSoundParameters(SAASND object); SAAPARAM SAAAPI SAASNDGetCurrentSoundParameters(SAASND object);
unsigned short SAAAPI SAASNDGetCurrentBytesPerSample(SAASND object); unsigned short SAAAPI SAASNDGetCurrentBytesPerSample(SAASND object);
unsigned short SAAAPI SAASNDGetBytesPerSample(SAAPARAM uParam); unsigned short SAAAPI SAASNDGetBytesPerSample(SAAPARAM uParam);
unsigned long SAAAPI SAASNDGetCurrentSampleRate(SAASND object); unsigned int SAAAPI SAASNDGetCurrentSampleRate(SAASND object);
unsigned long SAAAPI SAASNDGetSampleRate(SAAPARAM uParam); unsigned int SAAAPI SAASNDGetSampleRate(SAAPARAM uParam);
void SAAAPI SAASNDGenerateMany(SAASND object, BYTE * pBuffer, unsigned long nSamples); void SAAAPI SAASNDGenerateMany(SAASND object, BYTE * pBuffer, unsigned int nSamples);
void SAAAPI SAASNDSetClockRate(SAASND object, unsigned int nClockRate); void SAAAPI SAASNDSetClockRate(SAASND object, unsigned int nClockRate);
void SAAAPI SAASNDSetSampleRate(SAASND object, unsigned int nSampleRate); void SAAAPI SAASNDSetSampleRate(SAASND object, unsigned int nSampleRate);
void SAAAPI SAASNDSetOversample(SAASND object, unsigned int nOversample); void SAAAPI SAASNDSetOversample(SAASND object, unsigned int nOversample);