diff --git a/src/common/StateManager.hxx b/src/common/StateManager.hxx index 1576a969d..018f07dad 100644 --- a/src/common/StateManager.hxx +++ b/src/common/StateManager.hxx @@ -18,7 +18,7 @@ #ifndef STATE_MANAGER_HXX #define STATE_MANAGER_HXX -#define STATE_HEADER "06070002state" +#define STATE_HEADER "06070010state" class OSystem; class RewindManager; diff --git a/src/emucore/tia/Audio.cxx b/src/emucore/tia/Audio.cxx index 49b3145f6..76506da43 100644 --- a/src/emucore/tia/Audio.cxx +++ b/src/emucore/tia/Audio.cxx @@ -36,8 +36,10 @@ namespace { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Audio::Audio() { - for (uInt8 i = 0; i <= 0x1e; ++i) myMixingTableSum[i] = mixingTableEntry(i, 0x1e); - for (uInt8 i = 0; i <= 0x0f; ++i) myMixingTableIndividual[i] = mixingTableEntry(i, 0x0f); + for (uInt8 i = 0; i <= 0x1e; ++i) + myMixingTableSum[i] = mixingTableEntry(i, 0x1e); + for (uInt8 i = 0; i <= 0x0f; ++i) + myMixingTableIndividual[i] = mixingTableEntry(i, 0x0f); reset(); } @@ -45,11 +47,9 @@ Audio::Audio() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Audio::reset() { + mySumChannel0 = mySumChannel1 = mySumCt = 0; myCounter = 0; mySampleIndex = 0; - sumChannel0 = 0; - sumChannel1 = 0; - sumCt = 0; myChannel0.reset(); myChannel1.reset(); @@ -67,13 +67,11 @@ void Audio::setAudioQueue(const shared_ptr& queue) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Audio::createSample() { - // calculate average of all recent volume samples. the average for each + // Calculate average of all recent volume samples. the average for each // channel is mixed to create a single audible value - const uInt8 sample0 = (uInt8)(sumChannel0/sumCt); - const uInt8 sample1 = (uInt8)(sumChannel1/sumCt); - sumChannel0 = 0; - sumChannel1 = 0; - sumCt = 0; + const auto sample0 = static_cast(mySumChannel0 / mySumCt); + const auto sample1 = static_cast(mySumChannel1 / mySumCt); + mySumChannel0 = mySumChannel1 = mySumCt = 0; addSample(sample0, sample1); #ifdef GUI_SUPPORT @@ -115,6 +113,11 @@ bool Audio::save(Serializer& out) const if (!myChannel0.save(out)) return false; if (!myChannel1.save(out)) return false; + + out.putInt(mySumChannel0); + out.putInt(mySumChannel1); + out.putInt(mySumCt); + #ifdef GUI_SUPPORT out.putLong(static_cast(mySamples.size())); out.putByteArray(mySamples.data(), mySamples.size()); @@ -144,6 +147,11 @@ bool Audio::load(Serializer& in) if (!myChannel0.load(in)) return false; if (!myChannel1.load(in)) return false; + + mySumChannel0 = in.getInt(); + mySumChannel1 = in.getInt(); + mySumCt = in.getInt(); + #ifdef GUI_SUPPORT const uInt64 sampleSize = in.getLong(); ByteArray samples(sampleSize); diff --git a/src/emucore/tia/Audio.hxx b/src/emucore/tia/Audio.hxx index a18019b80..161e0c91f 100644 --- a/src/emucore/tia/Audio.hxx +++ b/src/emucore/tia/Audio.hxx @@ -68,9 +68,9 @@ class Audio : public Serializable AudioChannel myChannel0; AudioChannel myChannel1; - uInt32 sumChannel0; - uInt32 sumChannel1; - uInt32 sumCt; + uInt32 mySumChannel0{0}; + uInt32 mySumChannel1{0}; + uInt32 mySumCt{0}; std::array myMixingTableSum; std::array myMixingTableIndividual; @@ -96,11 +96,11 @@ class Audio : public Serializable // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Audio::tick() { - // volume for each channel is sampled every color clock. the average of + // Volume for each channel is sampled every color clock. the average of // these samples will be taken twice a scanline in the phase1() function - sumChannel0 += (uInt32)myChannel0.actualVolume(); - sumChannel1 += (uInt32)myChannel1.actualVolume(); - sumCt++; + mySumChannel0 += static_cast(myChannel0.actualVolume()); + mySumChannel1 += static_cast(myChannel1.actualVolume()); + mySumCt++; switch (myCounter) { case 9: diff --git a/src/emucore/tia/AudioChannel.cxx b/src/emucore/tia/AudioChannel.cxx index ad82fd801..679a92cd3 100644 --- a/src/emucore/tia/AudioChannel.cxx +++ b/src/emucore/tia/AudioChannel.cxx @@ -120,9 +120,10 @@ void AudioChannel::phase1() } } -// the actual volume of a chaneel is the volume register multiplied by the +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// The actual volume of a chaneel is the volume register multiplied by the // lowest of the pulse counter -uInt8 AudioChannel::actualVolume() +uInt8 AudioChannel::actualVolume() const { return (myPulseCounter & 0x01) * myAudv; } diff --git a/src/emucore/tia/AudioChannel.hxx b/src/emucore/tia/AudioChannel.hxx index ed62afafb..fc292ff6d 100644 --- a/src/emucore/tia/AudioChannel.hxx +++ b/src/emucore/tia/AudioChannel.hxx @@ -32,7 +32,7 @@ class AudioChannel : public Serializable void phase1(); - uInt8 actualVolume(); + uInt8 actualVolume() const; void audc(uInt8 value);