mirror of https://github.com/stella-emu/stella.git
Various fixes to latest sound code (style, clang-tidy, etc.)
This commit is contained in:
parent
e8a9fe282a
commit
637c194f80
|
@ -18,7 +18,7 @@
|
|||
#ifndef STATE_MANAGER_HXX
|
||||
#define STATE_MANAGER_HXX
|
||||
|
||||
#define STATE_HEADER "06070002state"
|
||||
#define STATE_HEADER "06070010state"
|
||||
|
||||
class OSystem;
|
||||
class RewindManager;
|
||||
|
|
|
@ -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<AudioQueue>& 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<uInt8>(mySumChannel0 / mySumCt);
|
||||
const auto sample1 = static_cast<uInt8>(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<uInt64>(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);
|
||||
|
|
|
@ -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<Int16, 0x1e + 1> myMixingTableSum;
|
||||
std::array<Int16, 0x0f + 1> 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<uInt32>(myChannel0.actualVolume());
|
||||
mySumChannel1 += static_cast<uInt32>(myChannel1.actualVolume());
|
||||
mySumCt++;
|
||||
|
||||
switch (myCounter) {
|
||||
case 9:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class AudioChannel : public Serializable
|
|||
|
||||
void phase1();
|
||||
|
||||
uInt8 actualVolume();
|
||||
uInt8 actualVolume() const;
|
||||
|
||||
void audc(uInt8 value);
|
||||
|
||||
|
|
Loading…
Reference in New Issue