| ... | ... |
@@ -18,7 +18,7 @@ |
| 18 | 18 |
#include "common.h" |
| 19 | 19 |
|
| 20 | 20 |
NDSSoundRegister::NDSSoundRegister() : volumeMul(0), volumeDiv(0), panning(0), waveDuty(0), repeatMode(0), format(0), enable(false), |
| 21 |
- source(nullptr), timer(0), psgX(0), psgLast(0), psgLastCount(0), samplePosition(0), sampleIncrease(0), loopStart(0), length(0) |
|
| 21 |
+ source(nullptr), timer(0), psgX(0), psgLast(0), psgLastCount(0), samplePosition(0), sampleIncrease(0), loopStart(0), length(0), totalLength(0) |
|
| 22 | 22 |
{
|
| 23 | 23 |
} |
| 24 | 24 |
|
| ... | ... |
@@ -418,6 +418,7 @@ void Channel::Update() |
| 418 | 418 |
this->reg.source = this->tempReg.SOURCE; |
| 419 | 419 |
this->reg.loopStart = this->tempReg.REPEAT_POINT; |
| 420 | 420 |
this->reg.length = this->tempReg.LENGTH; |
| 421 |
+ this->reg.totalLength = this->reg.loopStart + this->reg.length; |
|
| 421 | 422 |
this->ampl = AMPL_THRESHOLD; |
| 422 | 423 |
this->state = CS_ATTACK; |
| 423 | 424 |
// Fall down |
| ... | ... |
@@ -587,7 +588,7 @@ int32_t Channel::Interpolate() |
| 587 | 588 |
uint32_t loc = static_cast<uint32_t>(this->reg.samplePosition); |
| 588 | 589 |
const auto &data = &this->reg.source->data[loc]; |
| 589 | 590 |
int32_t a = data[0], b; |
| 590 |
- if (loc + 1 < this->reg.loopStart + this->reg.length) |
|
| 591 |
+ if (loc + 1 < this->reg.totalLength) |
|
| 591 | 592 |
b = data[1]; |
| 592 | 593 |
else |
| 593 | 594 |
{
|
| ... | ... |
@@ -603,7 +604,7 @@ int32_t Channel::Interpolate() |
| 603 | 604 |
if (this->ply->interpolation == INTERPOLATION_BSPLINE || this->ply->interpolation == INTERPOLATION_HERMITE || this->ply->interpolation == INTERPOLATION_OPTIMAL) |
| 604 | 605 |
{
|
| 605 | 606 |
int32_t c, z; |
| 606 |
- if (loc + 2 < this->reg.loopStart + this->reg.length) |
|
| 607 |
+ if (loc + 2 < this->reg.totalLength) |
|
| 607 | 608 |
c = data[2]; |
| 608 | 609 |
else |
| 609 | 610 |
{
|
| ... | ... |
@@ -619,7 +620,7 @@ int32_t Channel::Interpolate() |
| 619 | 620 |
z = data[-1]; |
| 620 | 621 |
else |
| 621 | 622 |
{
|
| 622 |
- if (loc + 1 < this->reg.loopStart + this->reg.length) |
|
| 623 |
+ if (loc + 1 < this->reg.totalLength) |
|
| 623 | 624 |
{
|
| 624 | 625 |
int32_t ap1 = data[1]; |
| 625 | 626 |
z = 2 * a - ap1; |
| ... | ... |
@@ -639,7 +640,7 @@ int32_t Channel::Interpolate() |
| 639 | 640 |
c3 = 0.5 * (a - b) + 1 / 6.0 * (c - z); |
| 640 | 641 |
return static_cast<int32_t>(((c3 * ratio + c2) * ratio + c1) * ratio + c0); |
| 641 | 642 |
} |
| 642 |
- if (this->ply->interpolation == INTERPOLATION_HERMITE) |
|
| 643 |
+ else if (this->ply->interpolation == INTERPOLATION_HERMITE) |
|
| 643 | 644 |
{
|
| 644 | 645 |
c0 = a; |
| 645 | 646 |
c1 = 0.5 * (b - z); |
| ... | ... |
@@ -717,11 +718,11 @@ int32_t Channel::GenerateSample() |
| 717 | 718 |
void Channel::IncrementSample() |
| 718 | 719 |
{
|
| 719 | 720 |
this->reg.samplePosition += this->reg.sampleIncrease; |
| 720 |
- if (this->reg.format != 3 && this->reg.samplePosition >= (this->reg.loopStart + this->reg.length)) |
|
| 721 |
+ if (this->reg.format != 3 && this->reg.samplePosition >= this->reg.totalLength) |
|
| 721 | 722 |
{
|
| 722 | 723 |
if (this->reg.repeatMode == 1) |
| 723 | 724 |
{
|
| 724 |
- while (this->reg.samplePosition >= (this->reg.loopStart + this->reg.length)) |
|
| 725 |
+ while (this->reg.samplePosition >= this->reg.totalLength) |
|
| 725 | 726 |
this->reg.samplePosition -= this->reg.length; |
| 726 | 727 |
} |
| 727 | 728 |
else |
| ... | ... |
@@ -9,7 +9,7 @@ |
| 9 | 9 |
|
| 10 | 10 |
#include "INFOEntry.h" |
| 11 | 11 |
|
| 12 |
-INFOEntrySEQ::INFOEntrySEQ() : fileID(0), bank(0) |
|
| 12 |
+INFOEntrySEQ::INFOEntrySEQ() : fileID(0), bank(0), vol(0) |
|
| 13 | 13 |
{
|
| 14 | 14 |
} |
| 15 | 15 |
|
| ... | ... |
@@ -18,7 +18,9 @@ void INFOEntrySEQ::Read(PseudoFile &file) |
| 18 | 18 |
this->fileID = file.ReadLE<uint16_t>(); |
| 19 | 19 |
file.ReadLE<uint16_t>(); // unknown |
| 20 | 20 |
this->bank = file.ReadLE<uint16_t>(); |
| 21 |
- file.ReadLE<uint8_t>(); // vol |
|
| 21 |
+ this->vol = file.ReadLE<uint8_t>(); |
|
| 22 |
+ if (!this->vol) |
|
| 23 |
+ this->vol = 0x7F; // Prevents nothing for volume |
|
| 22 | 24 |
file.ReadLE<uint8_t>(); // cpr |
| 23 | 25 |
file.ReadLE<uint8_t>(); // ppr |
| 24 | 26 |
file.ReadLE<uint8_t>(); // ply |
| ... | ... |
@@ -118,9 +118,10 @@ bool XSFPlayer_NCSF::Load() |
| 118 | 118 |
file.data = &this->sdatData; |
| 119 | 119 |
this->sdat.reset(new SDAT(file, this->sseq)); |
| 120 | 120 |
auto *sseqToPlay = this->sdat->sseq.get(); |
| 121 |
+ this->sseqVol = sseqToPlay->info.vol; |
|
| 121 | 122 |
this->player.sampleRate = this->sampleRate; |
| 122 | 123 |
this->player.Setup(sseqToPlay); |
| 123 |
- //this->player.masterVol = sseq->info.vol; |
|
| 124 |
+ //this->player.masterVol = sseqToPlay->info.vol; |
|
| 124 | 125 |
this->player.Timer(); |
| 125 | 126 |
this->secondsPerSample = 1.0 / this->sampleRate; |
| 126 | 127 |
this->secondsIntoPlayback = 0; |
| ... | ... |
@@ -178,6 +179,9 @@ void XSFPlayer_NCSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, |
| 178 | 179 |
leftChannel = muldiv7(leftChannel, 127 - this->player.masterVol); |
| 179 | 180 |
rightChannel = muldiv7(rightChannel, 127 - this->player.masterVol); |
| 180 | 181 |
|
| 182 |
+ leftChannel = muldiv7(leftChannel, this->sseqVol); |
|
| 183 |
+ rightChannel = muldiv7(rightChannel, this->sseqVol); |
|
| 184 |
+ |
|
| 181 | 185 |
clamp(leftChannel, -0x8000, 0x7FFF); |
| 182 | 186 |
clamp(rightChannel, -0x8000, 0x7FFF); |
| 183 | 187 |
|