[Scummvm-git-logs] scummvm master -> 1a5459b25ef2f8a4f6435435683249d3a2b40e7f
mduggan
mgithub at guarana.org
Sat Feb 20 05:49:24 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
498a2fed2e AUDIO: Const correctness for mod loader and stream
1a5459b25e AUDIO: Support mod files which loop
Commit: 498a2fed2e03607677b0646d66d35efbe986bd79
https://github.com/scummvm/scummvm/commit/498a2fed2e03607677b0646d66d35efbe986bd79
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-02-20T14:48:06+09:00
Commit Message:
AUDIO: Const correctness for mod loader and stream
Changed paths:
audio/mods/mod_xm_s3m.cpp
audio/mods/module_mod_xm_s3m.h
diff --git a/audio/mods/mod_xm_s3m.cpp b/audio/mods/mod_xm_s3m.cpp
index b21e63a86f..4a038e99f4 100644
--- a/audio/mods/mod_xm_s3m.cpp
+++ b/audio/mods/mod_xm_s3m.cpp
@@ -111,8 +111,8 @@ private:
static const int16 sinetable[];
int calculateDuration();
- int calculateTickLength() { return (_sampleRate * 5) / (_tempo * 2); }
- int calculateMixBufLength() { return (calculateTickLength() + 65) * 4; }
+ int calculateTickLength() const { return (_sampleRate * 5) / (_tempo * 2); }
+ int calculateMixBufLength() const { return (calculateTickLength() + 65) * 4; }
int initPlayCount(int8 **playCount);
void setSequencePos(int pos);
@@ -122,7 +122,7 @@ private:
// Sample
void downsample(int *buf, int count);
- void resample(Channel &channel, int *mixBuf, int offset, int count, int sampleRate);
+ void resample(const Channel &channel, int *mixBuf, int offset, int count, int sampleRate);
void updateSampleIdx(Channel &channel, int count, int sampleRate);
// Channel
@@ -147,8 +147,8 @@ private:
// Envelopes
void updateEnvelopes(Channel &channel);
- int envelopeNextTick(Envelope &envelope, int tick, int keyOn);
- int calculateAmpl(Envelope &envelope, int tick);
+ int envelopeNextTick(const Envelope &envelope, int tick, int keyOn);
+ int calculateAmpl(const Envelope &envelope, int tick);
// Read stream
int getAudio(int *mixBuf);
@@ -159,10 +159,10 @@ public:
bool loadSuccess() const { return _loadSuccess; }
// Implement virtual functions
- virtual int readBuffer(int16 *buffer, const int numSamples);
- virtual bool isStereo() const { return true; }
- virtual int getRate() const { return _sampleRate; }
- virtual bool endOfData() const { return _dataLeft <= 0; }
+ virtual int readBuffer(int16 *buffer, const int numSamples) override;
+ virtual bool isStereo() const override { return true; }
+ virtual int getRate() const override { return _sampleRate; }
+ virtual bool endOfData() const override { return _dataLeft <= 0; }
ModXmS3mStream(Common::SeekableReadStream *stream, int rate, int interpolation);
~ModXmS3mStream();
@@ -1006,7 +1006,7 @@ void ModXmS3mStream::updateRow() {
}
_breakPos = -1;
}
- Pattern &pattern = _module.patterns[_module.sequence[_seqPos]];
+ const Pattern &pattern = _module.patterns[_module.sequence[_seqPos]];
_row = _nextRow;
if (_row >= pattern.numRows) {
_row = 0;
@@ -1109,7 +1109,7 @@ void ModXmS3mStream::updateRow() {
}
}
-int ModXmS3mStream::envelopeNextTick(Envelope &envelope, int currentTick, int keyOn) {
+int ModXmS3mStream::envelopeNextTick(const Envelope &envelope, int currentTick, int keyOn) {
int nextTick = currentTick + 1;
if (envelope.looped && nextTick >= envelope.loopEndTick) {
nextTick = envelope.loopStartTick;
@@ -1120,7 +1120,7 @@ int ModXmS3mStream::envelopeNextTick(Envelope &envelope, int currentTick, int ke
return nextTick;
}
-int ModXmS3mStream::calculateAmpl(Envelope &envelope, int currentTick) {
+int ModXmS3mStream::calculateAmpl(const Envelope &envelope, int currentTick) {
int idx, point, dt, da;
int ampl = envelope.pointsAmpl[envelope.numPoints - 1];
if (currentTick < envelope.pointsTick[envelope.numPoints - 1]) {
@@ -1166,7 +1166,7 @@ int ModXmS3mStream::seek(int samplePos) {
return currentPos;
}
-void ModXmS3mStream::resample(Channel &channel, int *mixBuf, int offset, int count, int sampleRate) {
+void ModXmS3mStream::resample(const Channel &channel, int *mixBuf, int offset, int count, int sampleRate) {
Sample *sample = channel.sample;
int lGain = 0, rGain = 0, samIdx = 0, samFra = 0, step = 0;
int loopLen = 0, loopEnd = 0, outIdx = 0, outEnd = 0, y = 0, m = 0, c = 0;
diff --git a/audio/mods/module_mod_xm_s3m.h b/audio/mods/module_mod_xm_s3m.h
index 64473d17ed..9924f4d8c1 100644
--- a/audio/mods/module_mod_xm_s3m.h
+++ b/audio/mods/module_mod_xm_s3m.h
@@ -84,7 +84,7 @@ struct Pattern {
int numChannels, numRows;
Note *notes;
- Note getNote(int row, int chan) {
+ Note getNote(int row, int chan) const {
Note res;
if (row >= 0 && chan >= 0 && row < numRows && chan < numChannels)
res = notes[row * numChannels + chan];
Commit: 1a5459b25ef2f8a4f6435435683249d3a2b40e7f
https://github.com/scummvm/scummvm/commit/1a5459b25ef2f8a4f6435435683249d3a2b40e7f
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-02-20T14:48:17+09:00
Commit Message:
AUDIO: Support mod files which loop
Changed paths:
audio/mods/mod_xm_s3m.cpp
audio/mods/mod_xm_s3m.h
diff --git a/audio/mods/mod_xm_s3m.cpp b/audio/mods/mod_xm_s3m.cpp
index 4a038e99f4..3c9ee31b1a 100644
--- a/audio/mods/mod_xm_s3m.cpp
+++ b/audio/mods/mod_xm_s3m.cpp
@@ -100,6 +100,8 @@ private:
int8 **_playCount;
Channel *_channels;
int _dataLeft;
+ int _initialDataLength;
+ bool _finished;
// mix buffer to keep a partially consumed decoded tick.
int *_mixBuffer;
@@ -194,8 +196,9 @@ ModXmS3mStream::ModXmS3mStream(Common::SeekableReadStream *stream, int rate, int
_interpolation = interpolation;
_rampBuf = new int[128];
_channels = new Channel[_module.numChannels];
- _dataLeft = calculateDuration() * 4; // stereo and uint16
+ _initialDataLength = _dataLeft = calculateDuration() * 4; // stereo and uint16
_mixBuffer = nullptr;
+ _finished = false;
}
ModXmS3mStream::~ModXmS3mStream() {
@@ -991,13 +994,18 @@ void ModXmS3mStream::updateRow() {
_nextRow = 0;
}
if (_breakPos >= 0) {
+ _finished = false;
if (_breakPos >= _module.sequenceLen) {
+ // Hit the end.
_breakPos = _nextRow = 0;
+ _finished = true;
}
while (_module.sequence[_breakPos] >= _module.numPatterns) {
_breakPos++;
if (_breakPos >= _module.sequenceLen) {
+ // Hit the end.
_breakPos = _nextRow = 0;
+ _finished = true;
}
}
_seqPos = _breakPos;
@@ -1141,6 +1149,7 @@ int ModXmS3mStream::calculateAmpl(const Envelope &envelope, int currentTick) {
int ModXmS3mStream::calculateDuration() {
int count = 0, duration = 0;
setSequencePos(0);
+ // Count the length of sequences until we hit a bit we've played before (or the end).
while (count < 1) {
duration += calculateTickLength();
count = tick();
@@ -1285,7 +1294,7 @@ int ModXmS3mStream::getAudio(int *mixBuf) {
int ModXmS3mStream::readBuffer(int16 *buffer, const int numSamples) {
int samplesRead = 0;
- while (samplesRead < numSamples && _dataLeft >= 0) {
+ while (samplesRead < numSamples && _dataLeft > 0) {
int *mixBuf = new int[calculateMixBufLength()];
int samples = getAudio(mixBuf);
if (samplesRead + samples > numSamples) {
@@ -1305,9 +1314,21 @@ int ModXmS3mStream::readBuffer(int16 *buffer, const int numSamples) {
*buffer++ = ampl;
}
samplesRead += samples;
+
+ _dataLeft -= samples * 2;
+
delete []mixBuf; // free
}
- _dataLeft -= samplesRead * 2;
+
+ if (_dataLeft <= 0 && !_finished) {
+ //
+ // The original data length calculation was used up but didn't hit
+ // the end, so this mod loops.
+ // From here can just reset data left to some sensible value, but
+ // it's actually infinite and we'll come back here.
+ //
+ _dataLeft = _initialDataLength;
+ }
return samplesRead;
}
@@ -1358,7 +1379,7 @@ AudioStream *makeModXmS3mStream(Common::SeekableReadStream *stream, DisposeAfter
return nullptr;
}
- return (AudioStream *)soundStream;
+ return soundStream;
}
} // End of namespace Audio
diff --git a/audio/mods/mod_xm_s3m.h b/audio/mods/mod_xm_s3m.h
index 904adae952..7b93594040 100644
--- a/audio/mods/mod_xm_s3m.h
+++ b/audio/mods/mod_xm_s3m.h
@@ -78,6 +78,8 @@ class AudioStream;
* to the 'stream' object is kept, so you can safely delete it after
* invoking this factory.
*
+ * This stream may be infinitely long if the mod contains a loop.
+ *
* @param stream the ReadStream from which to read the tracker sound data
* @param disposeAfterUse whether to delete the stream after use
* @param rate sample rate
More information about the Scummvm-git-logs
mailing list