diff --git a/src/engine/brrUtils.c b/src/engine/brrUtils.c index 391fe4873..e44635712 100644 --- a/src/engine/brrUtils.c +++ b/src/engine/brrUtils.c @@ -56,15 +56,16 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart) { range=0; for (int j=0; j<16; j++) { - short s=buf[j]; + short s=buf[j]-(buf[j]>>13); if (s<0) s=-s; while (range<12 && s>((8<=len)?1:0); + next[0]=(range<<4)|(filter<<2)|((i+16>=len)?((loopStart>=0)?3:1):0); switch (filter) { case 0: for (int j=0; j<16; j++) { - o0=buf[j]>>range; + short s=buf[j]-(buf[j]>>13); + o0=s>>range; if (o0>7) o0=7; if (o0<-8) o0=-8; if (range>=12) if (o0<-7) o0=-7; diff --git a/src/engine/brrUtils.h b/src/engine/brrUtils.h index 4ada8b1e3..5cc898e1b 100644 --- a/src/engine/brrUtils.h +++ b/src/engine/brrUtils.h @@ -32,7 +32,7 @@ extern "C" { * @param buf input data. * @param out output buffer. shall be at least 9*(len/16) shorts in size. * @param len input length (should be a multiple of 16. if it isn't, the output will be padded). - * @param loopStart beginning of loop area (may be 0 for no loop). this is used to ensure the respective block has no filter in order to loop properly. + * @param loopStart beginning of loop area (may be -1 for no loop). this is used to ensure the respective block has no filter in order to loop properly. * @return number of written samples. */ long brrEncode(short* buf, unsigned char* out, long len, long loopStart); diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 1aee9eff4..6839a370c 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -911,8 +911,7 @@ void DivSample::render() { } if (depth!=DIV_SAMPLE_DEPTH_BRR) { // BRR if (!initInternal(DIV_SAMPLE_DEPTH_BRR,samples)) return; - // TODO: loop point - brrEncode(data16,dataBRR,(samples+15)&(~15),0); + brrEncode(data16,dataBRR,(samples+15)&(~15),loop?loopStart:-1); } if (depth!=DIV_SAMPLE_DEPTH_VOX) { // VOX if (!initInternal(DIV_SAMPLE_DEPTH_VOX,samples)) return;