[Scummvm-git-logs] scummvm master -> 6cf34878031fa4f726faf2d04bbba8a9de4470c3
bluegr
noreply at scummvm.org
Wed Nov 30 22:29:01 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
6cf3487803 AUDIO: Merge the DOSBoxCMS and CMSEmulator classes
Commit: 6cf34878031fa4f726faf2d04bbba8a9de4470c3
https://github.com/scummvm/scummvm/commit/6cf34878031fa4f726faf2d04bbba8a9de4470c3
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2022-12-01T00:28:56+02:00
Commit Message:
AUDIO: Merge the DOSBoxCMS and CMSEmulator classes
Changed paths:
audio/cms.cpp
audio/cms.h
audio/softsynth/cms.cpp
audio/softsynth/cms.h
diff --git a/audio/cms.cpp b/audio/cms.cpp
index 64dc2d359f2..89ba55d8145 100644
--- a/audio/cms.cpp
+++ b/audio/cms.cpp
@@ -20,6 +20,7 @@
*/
#include "audio/cms.h"
+#include "audio/softsynth/cms.h"
namespace CMS {
@@ -126,37 +127,4 @@ void EmulatedCMS::setCallbackFrequency(int timerFrequency) {
_samplesPerTick = (d << FIXP_SHIFT) + (r << FIXP_SHIFT) / _baseFreq;
}
-DOSBoxCMS::DOSBoxCMS() : _cms(nullptr) { }
-
-DOSBoxCMS::~DOSBoxCMS() {
- if (_cms)
- delete _cms;
-}
-
-bool DOSBoxCMS::init() {
- _cms = new CMSEmulator(getRate());
- return _cms != nullptr;
-}
-
-void DOSBoxCMS::reset() {
- _cms->reset();
-}
-
-void DOSBoxCMS::write(int a, int v) {
- _cms->portWrite(a, v);
-}
-
-void DOSBoxCMS::writeReg(int r, int v) {
- int address = 0x220;
- if (r >= 0x100)
- address += 0x002;
-
- _cms->portWrite(address + 1, r & 0x1F);
- _cms->portWrite(address, v);
-}
-
-void DOSBoxCMS::generateSamples(int16 *buffer, int numSamples) {
- _cms->readBuffer(buffer, numSamples);
-}
-
} // End of namespace CMS
diff --git a/audio/cms.h b/audio/cms.h
index fce144646f4..63857e3f354 100644
--- a/audio/cms.h
+++ b/audio/cms.h
@@ -27,7 +27,6 @@
#include "audio/audiostream.h"
#include "audio/mixer.h"
-#include "audio/softsynth/cms.h"
namespace CMS {
@@ -169,26 +168,6 @@ private:
Audio::SoundHandle *_handle;
};
-/**
- * A CMS that represents the DOSBox CMS emulator.
- */
-class DOSBoxCMS : public EmulatedCMS {
-public:
- DOSBoxCMS();
- ~DOSBoxCMS() override;
-
- bool init() override;
- void reset() override;
- void write(int a, int v) override;
- void writeReg(int r, int v) override;
-
-protected:
- void generateSamples(int16 *buffer, int numSamples) override;
-
-private:
- CMSEmulator *_cms;
-};
-
} // End of namespace CMS
#endif
diff --git a/audio/softsynth/cms.cpp b/audio/softsynth/cms.cpp
index 5d2c3e8d38a..99123485c70 100644
--- a/audio/softsynth/cms.cpp
+++ b/audio/softsynth/cms.cpp
@@ -84,40 +84,54 @@ static const int amplitude_lookup[16] = {
12*32767/16, 13*32767/16, 14*32767/16, 15*32767/16
};
-void CMSEmulator::portWrite(int port, int val) {
- switch (port-_basePort) {
+void DOSBoxCMS::write(int a, int v) {
+ switch (a-_basePort) {
case 0:
- portWriteIntern(0, 0, val);
+ portWriteIntern(0, 0, v);
break;
case 1:
- portWriteIntern(0, 1, val);
+ portWriteIntern(0, 1, v);
break;
case 2:
- portWriteIntern(1, 0, val);
+ portWriteIntern(1, 0, v);
break;
case 3:
- portWriteIntern(1, 1, val);
+ portWriteIntern(1, 1, v);
break;
default:
- warning("CMSEmulator got port: 0x%X", port);
+ warning("DOSBoxCMS got port: 0x%X", a);
break;
}
}
-void CMSEmulator::readBuffer(int16 *buffer, const int numSamples) {
+void DOSBoxCMS::writeReg(int r, int v) {
+ int chip = 0;
+ if (r >= 0x100)
+ chip = 1;
+
+ portWriteIntern(chip, 1, r & 0x1F);
+ portWriteIntern(chip, 0, v);
+}
+
+void DOSBoxCMS::generateSamples(int16 *buffer, const int numSamples) {
update(0, &buffer[0], numSamples);
update(1, &buffer[0], numSamples);
}
-void CMSEmulator::reset() {
+bool DOSBoxCMS::init() {
+ reset();
+ return true;
+}
+
+void DOSBoxCMS::reset() {
memset(_saa1099, 0, sizeof(SAA1099) * 2);
}
-void CMSEmulator::envelope(int chip, int ch) {
+void DOSBoxCMS::envelope(int chip, int ch) {
SAA1099 *saa = &_saa1099[chip];
if (saa->env_enable[ch]) {
int step, mode, mask;
@@ -152,8 +166,9 @@ void CMSEmulator::envelope(int chip, int ch) {
}
}
-void CMSEmulator::update(int chip, int16 *buffer, int length) {
+void DOSBoxCMS::update(int chip, int16 *buffer, int length) {
struct SAA1099 *saa = &_saa1099[chip];
+ int32 rate;
int j, ch;
if (chip == 0) {
@@ -175,6 +190,8 @@ void CMSEmulator::update(int chip, int16 *buffer, int length) {
}
}
+ rate = getRate() * FRAC_ONE_CMS;
+
/* fill all data needed */
for (j = 0; j < length; ++j) {
int output_l = 0, output_r = 0;
@@ -192,7 +209,7 @@ void CMSEmulator::update(int chip, int16 *buffer, int length) {
saa->channels[ch].freq = (((2 * MASTER_CLOCK) / 512) << saa->channels[ch].octave) /
(511 - saa->channels[ch].frequency);
- saa->channels[ch].counter += _sampleRate * FRAC_ONE_CMS;
+ saa->channels[ch].counter += rate;
saa->channels[ch].level ^= 1;
/* eventually clock the envelope counters */
@@ -226,7 +243,7 @@ void CMSEmulator::update(int chip, int16 *buffer, int length) {
/* check the actual position in noise generator */
saa->noise[ch].counter -= saa->noise[ch].freq;
while (saa->noise[ch].counter < 0) {
- saa->noise[ch].counter += _sampleRate * FRAC_ONE_CMS;
+ saa->noise[ch].counter += rate;
if (((saa->noise[ch].level & 0x4000) == 0) == ((saa->noise[ch].level & 0x0040) == 0) )
saa->noise[ch].level = (saa->noise[ch].level << 1) | 1;
else
@@ -239,7 +256,7 @@ void CMSEmulator::update(int chip, int16 *buffer, int length) {
}
}
-void CMSEmulator::portWriteIntern(int chip, int offset, int data) {
+void DOSBoxCMS::portWriteIntern(int chip, int offset, int data) {
SAA1099 *saa = &_saa1099[chip];
if(offset == 1) {
// address port
diff --git a/audio/softsynth/cms.h b/audio/softsynth/cms.h
index 95048616c92..fcd9b13045d 100644
--- a/audio/softsynth/cms.h
+++ b/audio/softsynth/cms.h
@@ -22,7 +22,7 @@
#ifndef AUDIO_SOFTSYNTH_CMS_H
#define AUDIO_SOFTSYNTH_CMS_H
-#include "common/scummsys.h"
+#include "audio/cms.h"
/* this structure defines a channel */
struct saa1099_channel {
@@ -64,22 +64,24 @@ struct SAA1099 {
struct saa1099_noise noise[2]; /* noise generators */
};
-class CMSEmulator {
+class DOSBoxCMS : public ::CMS::EmulatedCMS {
public:
- CMSEmulator(uint32 sampleRate, uint32 basePort = 0x220) {
- _sampleRate = sampleRate;
+ DOSBoxCMS(uint32 basePort = 0x220) {
memset(_saa1099, 0, sizeof(SAA1099)*2);
_basePort = basePort;
}
- ~CMSEmulator() { }
+ ~DOSBoxCMS() override { }
- void portWrite(int port, int val);
- void readBuffer(int16 *buffer, const int numSamples);
- void reset();
+ bool init() override;
+ void reset() override;
+ void write(int a, int v) override;
+ void writeReg(int r, int v) override;
+
+protected:
+ void generateSamples(int16 *buffer, int numSamples) override;
private:
- uint32 _sampleRate;
uint32 _basePort;
SAA1099 _saa1099[2];
More information about the Scummvm-git-logs
mailing list