diff --git a/src/engine/platform/c140.cpp b/src/engine/platform/c140.cpp index 30ec91f0d..9e144c663 100644 --- a/src/engine/platform/c140.cpp +++ b/src/engine/platform/c140.cpp @@ -245,10 +245,10 @@ void DivPlatformC140::tick(bool sysTick) { if (chan[i].sample>=0 && chan[i].samplesong.sampleLen && s->isLoopable()) { if (is219) { loop=MIN(start+(s->loopStart>>1),65535); - end=MIN(start+(s->loopEnd>>1)-1,65535); + end=MIN(start+(s->loopEnd>>1),65535); } else { - loop=MIN(start+s->loopStart,65535); - end=MIN(start+s->loopEnd-1,65535); + loop=MIN(start+s->loopStart+1,65535); + end=MIN(start+s->loopEnd+1,65535); } } else if (chan[i].noise && is219) { loop=0; @@ -575,7 +575,7 @@ void DivPlatformC140::renderSamples(int sysID) { } if (is219) { // C219 (8-bit) - unsigned int length=s->length8; + unsigned int length=s->length8+4; // fit sample size to single bank size if (length>131072) { length=131072; @@ -594,27 +594,39 @@ void DivPlatformC140::renderSamples(int sysID) { logW("out of C219 memory for sample %d!",i); } if (s->depth==DIV_SAMPLE_DEPTH_C219) { + unsigned char next=0; + unsigned int sPos=0; for (unsigned int i=0; i=s->lengthC219) { - sampleMem[(memPos+i)^1]=0; - } else { - sampleMem[(memPos+i)^1]=s->dataC219[i]; + if (sPoslengthC219) { + next=s->dataC219[sPos++]; + if (s->isLoopable()) { + if ((int)sPos>=s->loopEnd) { + sPos=s->loopStart; + } + } } + sampleMem[(memPos+i)^1]=next; } } else { + signed char next=0; + unsigned int sPos=0; for (unsigned int i=0; i=s->length8) { - sampleMem[(memPos+i)^1]=0; - } else { - sampleMem[(memPos+i)^1]=s->data8[i]; + if (sPoslength8) { + next=s->data8[sPos++]; + if (s->isLoopable()) { + if ((int)sPos>=s->loopEnd) { + sPos=s->loopStart; + } + } } + sampleMem[(memPos+i)^1]=next; } } sampleOff[i]=memPos>>1; sampleLoaded[i]=true; memPos+=length; } else { // C140 (16-bit) - unsigned int length=s->length16; + unsigned int length=s->length16+4; // fit sample size to single bank size if (length>(131072)) { length=131072; @@ -641,7 +653,20 @@ void DivPlatformC140::renderSamples(int sysID) { sampleMem[1+i+memPos]=c140Mu; } } else { - memcpy(sampleMem+memPos,s->data16,length); + short next=0; + unsigned int sPos=0; + for (unsigned int i=0; isamples) { + next=s->data16[sPos++]; + if (s->isLoopable()) { + if ((int)sPos>=s->loopEnd) { + sPos=s->loopStart; + } + } + } + sampleMem[memPos+i]=((unsigned short)next); + sampleMem[memPos+i+1]=((unsigned short)next)>>8; + } } sampleOff[i]=memPos>>1; sampleLoaded[i]=true; diff --git a/src/engine/platform/sound/c140_c219.c b/src/engine/platform/sound/c140_c219.c index 56d96ca19..84e590f14 100644 --- a/src/engine/platform/sound/c140_c219.c +++ b/src/engine/platform/sound/c140_c219.c @@ -104,7 +104,7 @@ void c140_voice_tick(struct c140_t *c140, const unsigned char v, const int cycle if (!voice->muted) { // fetch 12 bit sample - signed short s1 = c140->sample_mem[((unsigned int)(voice->bank) << 16) | voice->addr] & ~0xf; + signed short s1 = c140->sample_mem[((unsigned int)(voice->bank) << 16) | (voice->addr & 0xffff)] & ~0xf; signed short s2 = c140->sample_mem[((unsigned int)(voice->bank) << 16) | ((voice->addr + 1) & 0xffff)] & ~0xf; if (voice->compressed) { @@ -171,7 +171,7 @@ void c219_voice_tick(struct c219_t *c219, const unsigned char v, const int cycle else { // fetch 8 bit sample - signed short s1 = c219->sample_mem[((unsigned int)(c219->bank[(v >> 2) & 3]) << 17) | (voice->addr^1)]; + signed short s1 = c219->sample_mem[((unsigned int)(c219->bank[(v >> 2) & 3]) << 17) | ((voice->addr^1) & 0x1ffff)]; signed short s2 = c219->sample_mem[((unsigned int)(c219->bank[(v >> 2) & 3]) << 17) | (((voice->addr + 1) & 0x1ffff)^1)]; if (voice->compressed) {