Merge branch 'master' into elf

This commit is contained in:
Stephen Anthony 2024-08-07 12:14:59 -02:30
commit 9c80fc2308
5 changed files with 46 additions and 10 deletions

View File

@ -18,7 +18,7 @@
#ifndef STATE_MANAGER_HXX #ifndef STATE_MANAGER_HXX
#define STATE_MANAGER_HXX #define STATE_MANAGER_HXX
#define STATE_HEADER "06070002state" #define STATE_HEADER "06070010state"
class OSystem; class OSystem;
class RewindManager; class RewindManager;

View File

@ -36,8 +36,10 @@ namespace {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Audio::Audio() Audio::Audio()
{ {
for (uInt8 i = 0; i <= 0x1e; ++i) myMixingTableSum[i] = mixingTableEntry(i, 0x1e); for (uInt8 i = 0; i <= 0x1e; ++i)
for (uInt8 i = 0; i <= 0x0f; ++i) myMixingTableIndividual[i] = mixingTableEntry(i, 0x0f); myMixingTableSum[i] = mixingTableEntry(i, 0x1e);
for (uInt8 i = 0; i <= 0x0f; ++i)
myMixingTableIndividual[i] = mixingTableEntry(i, 0x0f);
reset(); reset();
} }
@ -45,6 +47,7 @@ Audio::Audio()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::reset() void Audio::reset()
{ {
mySumChannel0 = mySumChannel1 = mySumCt = 0;
myCounter = 0; myCounter = 0;
mySampleIndex = 0; mySampleIndex = 0;
@ -62,10 +65,13 @@ void Audio::setAudioQueue(const shared_ptr<AudioQueue>& queue)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::phase1() void Audio::createSample()
{ {
const uInt8 sample0 = myChannel0.phase1(); // Calculate average of all recent volume samples. the average for each
const uInt8 sample1 = myChannel1.phase1(); // channel is mixed to create a single audible value
const auto sample0 = static_cast<uInt8>(mySumChannel0 / mySumCt);
const auto sample1 = static_cast<uInt8>(mySumChannel1 / mySumCt);
mySumChannel0 = mySumChannel1 = mySumCt = 0;
addSample(sample0, sample1); addSample(sample0, sample1);
#ifdef GUI_SUPPORT #ifdef GUI_SUPPORT
@ -107,6 +113,11 @@ bool Audio::save(Serializer& out) const
if (!myChannel0.save(out)) return false; if (!myChannel0.save(out)) return false;
if (!myChannel1.save(out)) return false; if (!myChannel1.save(out)) return false;
out.putInt(mySumChannel0);
out.putInt(mySumChannel1);
out.putInt(mySumCt);
#ifdef GUI_SUPPORT #ifdef GUI_SUPPORT
out.putLong(static_cast<uInt64>(mySamples.size())); out.putLong(static_cast<uInt64>(mySamples.size()));
out.putByteArray(mySamples.data(), mySamples.size()); out.putByteArray(mySamples.data(), mySamples.size());
@ -136,6 +147,11 @@ bool Audio::load(Serializer& in)
if (!myChannel0.load(in)) return false; if (!myChannel0.load(in)) return false;
if (!myChannel1.load(in)) return false; if (!myChannel1.load(in)) return false;
mySumChannel0 = in.getInt();
mySumChannel1 = in.getInt();
mySumCt = in.getInt();
#ifdef GUI_SUPPORT #ifdef GUI_SUPPORT
const uInt64 sampleSize = in.getLong(); const uInt64 sampleSize = in.getLong();
ByteArray samples(sampleSize); ByteArray samples(sampleSize);

View File

@ -58,7 +58,7 @@ class Audio : public Serializable
bool load(Serializer& in) override; bool load(Serializer& in) override;
private: private:
void phase1(); void createSample();
void addSample(uInt8 sample0, uInt8 sample1); void addSample(uInt8 sample0, uInt8 sample1);
private: private:
@ -69,6 +69,10 @@ class Audio : public Serializable
AudioChannel myChannel0; AudioChannel myChannel0;
AudioChannel myChannel1; AudioChannel myChannel1;
uInt32 mySumChannel0{0};
uInt32 mySumChannel1{0};
uInt32 mySumCt{0};
std::array<Int16, 0x1e + 1> myMixingTableSum; std::array<Int16, 0x1e + 1> myMixingTableSum;
std::array<Int16, 0x0f + 1> myMixingTableIndividual; std::array<Int16, 0x0f + 1> myMixingTableIndividual;
@ -93,6 +97,12 @@ class Audio : public Serializable
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::tick() void Audio::tick()
{ {
// Volume for each channel is sampled every color clock. the average of
// these samples will be taken twice a scanline in the phase1() function
mySumChannel0 += static_cast<uInt32>(myChannel0.actualVolume());
mySumChannel1 += static_cast<uInt32>(myChannel1.actualVolume());
mySumCt++;
switch (myCounter) { switch (myCounter) {
case 9: case 9:
case 81: case 81:
@ -102,7 +112,9 @@ void Audio::tick()
case 37: case 37:
case 149: case 149:
phase1(); myChannel0.phase1();
myChannel1.phase1();
createSample();
break; break;
default: default:

View File

@ -77,7 +77,7 @@ void AudioChannel::phase0()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 AudioChannel::phase1() void AudioChannel::phase1()
{ {
if (myClockEnable) { if (myClockEnable) {
bool pulseFeedback = false; bool pulseFeedback = false;
@ -118,7 +118,13 @@ uInt8 AudioChannel::phase1()
} }
} }
} }
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// The actual volume of a chaneel is the volume register multiplied by the
// lowest of the pulse counter
uInt8 AudioChannel::actualVolume() const
{
return (myPulseCounter & 0x01) * myAudv; return (myPulseCounter & 0x01) * myAudv;
} }

View File

@ -31,7 +31,9 @@ class AudioChannel : public Serializable
void phase0(); void phase0();
uInt8 phase1(); void phase1();
uInt8 actualVolume() const;
void audc(uInt8 value); void audc(uInt8 value);