Merge branch 'master' into duplicate_channel_struct
This commit is contained in:
commit
1ae1f32574
63 changed files with 1357 additions and 629 deletions
|
|
@ -21,6 +21,8 @@
|
|||
*/
|
||||
|
||||
#include "brrUtils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NEXT_SAMPLE buf[j]-(buf[j]>>3)
|
||||
|
||||
|
|
@ -56,384 +58,257 @@
|
|||
last2=last1; \
|
||||
last1=nextDec; \
|
||||
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart) {
|
||||
void brrEncodeBlock(const short* buf, unsigned char* out, unsigned char range, unsigned char filter, short* last1, short* last2, int* errorSum) {
|
||||
// encode one block using BRR
|
||||
unsigned char nibble=0;
|
||||
int preOut=0;
|
||||
int pred=0;
|
||||
int nextDec=0;
|
||||
int nextError=0;
|
||||
*errorSum=0;
|
||||
for (int j=0; j<16; j++) {
|
||||
short s=NEXT_SAMPLE;
|
||||
switch (filter) {
|
||||
case 0: // no filter
|
||||
pred=s;
|
||||
break;
|
||||
case 1: // simple
|
||||
pred=s-(((int)(*last1*2)*15)>>4);
|
||||
break;
|
||||
case 2: // complex
|
||||
pred=s+(((int)(*last2*2)*15)>>4)-(((int)(*last1*2)*61)>>5);
|
||||
break;
|
||||
case 3:
|
||||
pred=s+(((int)(*last2*2)*13)>>4)-(((int)(*last1*2)*115)>>6);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pred<-32768) pred=-32768;
|
||||
if (pred>32767) pred=32767;
|
||||
|
||||
preOut=pred>>range;
|
||||
if (range) {
|
||||
if (pred&(1<<(range>>1))) preOut++;
|
||||
if (filter==0 && range>=12) if (preOut<-7) preOut=-7;
|
||||
}
|
||||
if (preOut>7) preOut=7;
|
||||
if (preOut<-8) preOut=-8;
|
||||
|
||||
nibble=preOut&15;
|
||||
if (j&1) {
|
||||
out[j>>1]|=nibble;
|
||||
} else {
|
||||
out[j>>1]=nibble<<4;
|
||||
}
|
||||
|
||||
// roll last1/last2
|
||||
nextDec=nibble;
|
||||
if (nextDec&8) nextDec|=0xfffffff0;
|
||||
|
||||
if (range>=13) { /* invalid shift */
|
||||
nextDec=(nextDec<0)?0xfffff800:0;
|
||||
} else {
|
||||
nextDec<<=range; /* range */
|
||||
nextDec>>=1;
|
||||
}
|
||||
|
||||
switch (filter) { /* filter */
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
nextDec+=(*last1)+((-(*last1))>>4);
|
||||
break;
|
||||
case 2:
|
||||
nextDec+=(*last1)*2+((-(*last1)*3)>>5)-(*last2)+((*last2)>>4);
|
||||
break;
|
||||
case 3:
|
||||
nextDec+=(*last1)*2+((-(*last1)*13)>>6)-(*last2)+(((*last2)*3)>>4);
|
||||
break;
|
||||
}
|
||||
|
||||
nextDec&=0x7fff;
|
||||
if (nextDec&0x4000) nextDec|=0xffff8000;
|
||||
|
||||
nextError=s-(nextDec<<1);
|
||||
if (nextError<0) nextError=-nextError;
|
||||
*errorSum+=nextError;
|
||||
|
||||
*last2=*last1;
|
||||
*last1=nextDec;
|
||||
}
|
||||
}
|
||||
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigned char emphasis) {
|
||||
if (len==0) return 0;
|
||||
|
||||
// encoding process:
|
||||
// 1. read next group of 16 samples
|
||||
// 2. is this the first block?
|
||||
// - if yes, don't filter. output and then go to 1
|
||||
// 3. is this the loop block?
|
||||
// - if yes, don't filter. output and then go to 1
|
||||
// 4. try encoding using 4 filters
|
||||
// - perform linear prediction
|
||||
// - calculate range
|
||||
// - decode and apply correction to achieve low error
|
||||
// 4. try encoding using 3 filters and 12 ranges (besides no filter)
|
||||
// 5. which one of these yields the least amount of error?
|
||||
// 6. output the one which does
|
||||
// 7. is this the last block?
|
||||
// - if yes, mark end and finish
|
||||
// 8. go to 1
|
||||
// 7. do we still have more to encode?
|
||||
// - if so, go to 1
|
||||
// 8. is loop point set?
|
||||
// - if not, end process here
|
||||
// 9. is transition between last block and loop block smooth?
|
||||
// - if not, encode the loop block again and output it
|
||||
long total=0;
|
||||
unsigned char next0[8];
|
||||
unsigned char next1[8];
|
||||
unsigned char next2[8];
|
||||
unsigned char next3[8];
|
||||
unsigned char filter=0;
|
||||
unsigned char range0=0;
|
||||
unsigned char range1=0;
|
||||
unsigned char range2=0;
|
||||
unsigned char range3=0;
|
||||
unsigned char o=0;
|
||||
int pred1[16];
|
||||
int pred2[16];
|
||||
int pred3[16];
|
||||
short o1=0;
|
||||
short o2=0;
|
||||
short o0=0;
|
||||
short o1f1=0;
|
||||
short o1f2=0;
|
||||
short o1f3=0;
|
||||
//short o2f1=0;
|
||||
short o2f2=0;
|
||||
short o2f3=0;
|
||||
unsigned char range=0;
|
||||
|
||||
int last1=0;
|
||||
int last2=0;
|
||||
int nextDec=0;
|
||||
int maxError[4];
|
||||
int avgError[4];
|
||||
short x0=0;
|
||||
short x1=0;
|
||||
short x2=0;
|
||||
int emphOut=0;
|
||||
|
||||
short in[17];
|
||||
|
||||
short last1[4][13];
|
||||
short last2[4][13];
|
||||
int avgError[4][13];
|
||||
unsigned char possibleOut[4][13][8];
|
||||
|
||||
memset(in,0,16*sizeof(short));
|
||||
memset(last1,0,4*13*sizeof(short));
|
||||
memset(last2,0,4*13*sizeof(short));
|
||||
memset(avgError,0,4*13*sizeof(int));
|
||||
memset(possibleOut,0,4*13*8);
|
||||
|
||||
len&=~15;
|
||||
loopStart&=~15;
|
||||
for (long i=0; i<len; i+=16) {
|
||||
range0=0;
|
||||
// encode with no filter
|
||||
for (int j=0; j<16; j++) {
|
||||
short s=NEXT_SAMPLE;
|
||||
if (s<0) s=-s;
|
||||
while (range0<12 && s>((8<<range0)-1)) range0++;
|
||||
}
|
||||
for (int j=0; j<16; j++) {
|
||||
short s=NEXT_SAMPLE;
|
||||
o0=s>>range0;
|
||||
if (range0) if (s&(1<<(range1>>1))) o0++;
|
||||
if (o0>7) o0=7;
|
||||
if (o0<-8) o0=-8;
|
||||
if (range0>=12) if (o0<-7) o0=-7;
|
||||
o=o0&15;
|
||||
if (j&1) {
|
||||
next0[j>>1]|=o;
|
||||
} else {
|
||||
next0[j>>1]=o<<4;
|
||||
}
|
||||
}
|
||||
|
||||
// encode with filter
|
||||
if (i /*&& i!=loopStart*/) {
|
||||
// 1: x = o0 - o1 * 15/16
|
||||
// 2: x = o0 + o2 * 15/16 - o1 * 61/32
|
||||
// 3: x = o0 + o2 * 13/16 - o1 * 115/64
|
||||
range1=0;
|
||||
range2=0;
|
||||
range3=0;
|
||||
//o2f1=o2;
|
||||
o2f2=o2;
|
||||
o2f3=o2;
|
||||
o1f1=o1;
|
||||
o1f2=o1;
|
||||
o1f3=o1;
|
||||
// first pass
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
|
||||
pred1[j]=s-(((int)o1*15)>>4);
|
||||
if (pred1[j]<-32768) pred1[j]=-32768;
|
||||
if (pred1[j]>32767) pred1[j]=32767;
|
||||
|
||||
pred2[j]=s+(((int)o2*15)>>4)-(((int)o1*61)>>5);
|
||||
if (pred2[j]<-32768) pred2[j]=-32768;
|
||||
if (pred2[j]>32767) pred2[j]=32767;
|
||||
|
||||
pred3[j]=s+(((int)o2*13)>>4)-(((int)o1*115)>>6);
|
||||
if (pred3[j]<-32768) pred3[j]=-32768;
|
||||
if (pred3[j]>32767) pred3[j]=32767;
|
||||
|
||||
o2=o1;
|
||||
o1=s;
|
||||
}
|
||||
// calculate range of values
|
||||
for (int j=0; j<16; j++) {
|
||||
short s=pred1[j];
|
||||
if (s<0) s=-s;
|
||||
while (range1<12 && s>((8<<range1)-1)) range1++;
|
||||
|
||||
s=pred2[j];
|
||||
if (s<0) s=-s;
|
||||
while (range2<12 && s>((8<<range2)-1)) range2++;
|
||||
|
||||
s=pred3[j];
|
||||
if (s<0) s=-s;
|
||||
while (range3<12 && s>((8<<range3)-1)) range3++;
|
||||
}
|
||||
// second pass
|
||||
int prevLast1=last1;
|
||||
int prevLast2=last2;
|
||||
filter=1;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
|
||||
pred1[j]=s-(((int)o1f1*15)>>4);
|
||||
if (pred1[j]<-32768) pred1[j]=-32768;
|
||||
if (pred1[j]>32767) pred1[j]=32767;
|
||||
|
||||
o0=pred1[j]>>range1;
|
||||
if (range1) if (pred1[j]&(1<<(range1>>1))) o0++;
|
||||
if (o0>7) o0=7;
|
||||
if (o0<-8) o0=-8;
|
||||
o=o0&15;
|
||||
if (j&1) {
|
||||
next1[j>>1]|=o;
|
||||
if (i+17>len) {
|
||||
long p=i;
|
||||
for (int j=0; j<17; j++) {
|
||||
if (p>=len) {
|
||||
if (loopStart<0 || loopStart>=len) {
|
||||
in[j]=0;
|
||||
} else {
|
||||
p=loopStart;
|
||||
in[j]=buf[p++];
|
||||
}
|
||||
} else {
|
||||
next1[j>>1]=o<<4;
|
||||
}
|
||||
|
||||
nextDec=o;
|
||||
DO_ONE_DEC(range1);
|
||||
//o2f1=last2<<1;
|
||||
o1f1=last1<<1;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
filter=2;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
pred2[j]=s+(((int)o2f2*15)>>4)-(((int)o1f2*61)>>5);
|
||||
if (pred2[j]<-32768) pred2[j]=-32768;
|
||||
if (pred2[j]>32767) pred2[j]=32767;
|
||||
|
||||
o0=pred2[j]>>range2;
|
||||
if (range2) if (pred2[j]&(1<<(range2>>1))) o0++;
|
||||
if (o0>7) o0=7;
|
||||
if (o0<-8) o0=-8;
|
||||
o=o0&15;
|
||||
if (j&1) {
|
||||
next2[j>>1]|=o;
|
||||
} else {
|
||||
next2[j>>1]=o<<4;
|
||||
}
|
||||
|
||||
nextDec=o;
|
||||
DO_ONE_DEC(range2);
|
||||
o2f2=last2<<1;
|
||||
o1f2=last1<<1;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
filter=3;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
pred3[j]=s+(((int)o2f3*13)>>4)-(((int)o1f3*115)>>6);
|
||||
if (pred3[j]<-32768) pred3[j]=-32768;
|
||||
if (pred3[j]>32767) pred3[j]=32767;
|
||||
|
||||
o0=pred3[j]>>range3;
|
||||
if (range3) if (pred3[j]&(1<<(range3>>1))) o0++;
|
||||
if (o0>7) o0=7;
|
||||
if (o0<-8) o0=-8;
|
||||
o=o0&15;
|
||||
if (j&1) {
|
||||
next3[j>>1]|=o;
|
||||
} else {
|
||||
next3[j>>1]=o<<4;
|
||||
}
|
||||
|
||||
nextDec=o;
|
||||
DO_ONE_DEC(range3);
|
||||
o2f3=last2<<1;
|
||||
o1f3=last1<<1;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
|
||||
// find best filter
|
||||
int error=0;
|
||||
|
||||
maxError[0]=0;
|
||||
maxError[1]=0;
|
||||
maxError[2]=0;
|
||||
maxError[3]=0;
|
||||
avgError[0]=0;
|
||||
avgError[1]=0;
|
||||
avgError[2]=0;
|
||||
avgError[3]=0;
|
||||
|
||||
// test filter 0
|
||||
filter=0;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
if (j&1) {
|
||||
nextDec=next0[j>>1]&15;
|
||||
} else {
|
||||
nextDec=next0[j>>1]>>4;
|
||||
}
|
||||
DO_ONE_DEC(range0);
|
||||
error=s-(nextDec<<1);
|
||||
if (error<0) error=-error;
|
||||
avgError[0]+=error;
|
||||
if (error>maxError[0]) maxError[0]=error;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
|
||||
// test filter 1
|
||||
filter=1;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
if (j&1) {
|
||||
nextDec=next1[j>>1]&15;
|
||||
} else {
|
||||
nextDec=next1[j>>1]>>4;
|
||||
}
|
||||
DO_ONE_DEC(range1);
|
||||
error=s-(nextDec<<1);
|
||||
if (error<0) error=-error;
|
||||
avgError[1]+=error;
|
||||
if (error>maxError[1]) maxError[1]=error;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
|
||||
// test filter 2
|
||||
filter=2;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
if (j&1) {
|
||||
nextDec=next2[j>>1]&15;
|
||||
} else {
|
||||
nextDec=next2[j>>1]>>4;
|
||||
}
|
||||
DO_ONE_DEC(range2);
|
||||
error=s-(nextDec<<1);
|
||||
if (error<0) error=-error;
|
||||
avgError[2]+=error;
|
||||
if (error>maxError[2]) maxError[2]=error;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
|
||||
// test filter 3
|
||||
filter=3;
|
||||
for (int j=0; j<16; j++) {
|
||||
int s=NEXT_SAMPLE;
|
||||
if (j&1) {
|
||||
nextDec=next3[j>>1]&15;
|
||||
} else {
|
||||
nextDec=next3[j>>1]>>4;
|
||||
}
|
||||
DO_ONE_DEC(range3);
|
||||
error=s-(nextDec<<1);
|
||||
if (error<0) error=-error;
|
||||
avgError[3]+=error;
|
||||
if (error>maxError[3]) maxError[3]=error;
|
||||
}
|
||||
last1=prevLast1;
|
||||
last2=prevLast2;
|
||||
|
||||
// pick best filter
|
||||
int candError=0x7fffffff;
|
||||
for (int j=0; j<4; j++) {
|
||||
if (avgError[j]<candError) {
|
||||
candError=avgError[j];
|
||||
filter=j;
|
||||
in[j]=buf[p++];
|
||||
}
|
||||
}
|
||||
//printf("block %ld: %8d %8d %8d %8d -> %d\n",i>>4,avgError[0],avgError[1],avgError[2],avgError[3],filter);
|
||||
} else {
|
||||
// don't filter on the first or loop block
|
||||
memcpy(in,&buf[i],17*sizeof(short));
|
||||
}
|
||||
|
||||
// emphasis
|
||||
if (emphasis) {
|
||||
for (int j=0; j<17; j++) {
|
||||
x0=x1;
|
||||
x1=x2;
|
||||
x2=in[j];
|
||||
|
||||
if (j==0) continue;
|
||||
emphOut=((x1<<11)-x0*370-in[j]*374)/1305;
|
||||
if (emphOut<-32768) emphOut=-32768;
|
||||
if (emphOut>32767) emphOut=32767;
|
||||
in[j-1]=emphOut;
|
||||
}
|
||||
}
|
||||
|
||||
// encode
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
brrEncodeBlock(in,possibleOut[j][k],k,j,&last1[j][k],&last2[j][k],&avgError[j][k]);
|
||||
}
|
||||
}
|
||||
|
||||
// find best filter/range
|
||||
int candError=0x7fffffff;
|
||||
if (i==0) {
|
||||
filter=0;
|
||||
for (int k=0; k<13; k++) {
|
||||
if (avgError[0][k]<candError) {
|
||||
candError=avgError[0][k];
|
||||
range=k;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
if (avgError[j][k]<candError) {
|
||||
candError=avgError[j][k];
|
||||
filter=j;
|
||||
range=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (filter) {
|
||||
case 0:
|
||||
for (int j=0; j<8; j++) {
|
||||
nextDec=next0[j]>>4;
|
||||
DO_ONE_DEC(range0);
|
||||
nextDec=next0[j]&15;
|
||||
DO_ONE_DEC(range0);
|
||||
}
|
||||
o2=last2<<1;
|
||||
o1=last1<<1;
|
||||
|
||||
out[0]=(range0<<4)|(filter<<2)|((i+16>=len)?((loopStart>=0)?3:1):0);
|
||||
out[1]=next0[0];
|
||||
out[2]=next0[1];
|
||||
out[3]=next0[2];
|
||||
out[4]=next0[3];
|
||||
out[5]=next0[4];
|
||||
out[6]=next0[5];
|
||||
out[7]=next0[6];
|
||||
out[8]=next0[7];
|
||||
break;
|
||||
case 1:
|
||||
for (int j=0; j<8; j++) {
|
||||
nextDec=next1[j]>>4;
|
||||
DO_ONE_DEC(range1);
|
||||
nextDec=next1[j]&15;
|
||||
DO_ONE_DEC(range1);
|
||||
}
|
||||
o2=last2<<1;
|
||||
o1=last1<<1;
|
||||
out[0]=(range1<<4)|(filter<<2)|((i+16>=len)?((loopStart>=0)?3:1):0);
|
||||
out[1]=next1[0];
|
||||
out[2]=next1[1];
|
||||
out[3]=next1[2];
|
||||
out[4]=next1[3];
|
||||
out[5]=next1[4];
|
||||
out[6]=next1[5];
|
||||
out[7]=next1[6];
|
||||
out[8]=next1[7];
|
||||
break;
|
||||
case 2:
|
||||
for (int j=0; j<8; j++) {
|
||||
nextDec=next2[j]>>4;
|
||||
DO_ONE_DEC(range2);
|
||||
nextDec=next2[j]&15;
|
||||
DO_ONE_DEC(range2);
|
||||
}
|
||||
o2=last2<<1;
|
||||
o1=last1<<1;
|
||||
out[0]=(range2<<4)|(filter<<2)|((i+16>=len)?((loopStart>=0)?3:1):0);
|
||||
out[1]=next2[0];
|
||||
out[2]=next2[1];
|
||||
out[3]=next2[2];
|
||||
out[4]=next2[3];
|
||||
out[5]=next2[4];
|
||||
out[6]=next2[5];
|
||||
out[7]=next2[6];
|
||||
out[8]=next2[7];
|
||||
break;
|
||||
case 3:
|
||||
for (int j=0; j<8; j++) {
|
||||
nextDec=next3[j]>>4;
|
||||
DO_ONE_DEC(range3);
|
||||
nextDec=next3[j]&15;
|
||||
DO_ONE_DEC(range3);
|
||||
}
|
||||
o2=last2<<1;
|
||||
o1=last1<<1;
|
||||
out[0]=(range3<<4)|(filter<<2)|((i+16>=len)?((loopStart>=0)?3:1):0);
|
||||
out[1]=next3[0];
|
||||
out[2]=next3[1];
|
||||
out[3]=next3[2];
|
||||
out[4]=next3[3];
|
||||
out[5]=next3[4];
|
||||
out[6]=next3[5];
|
||||
out[7]=next3[6];
|
||||
out[8]=next3[7];
|
||||
break;
|
||||
// write
|
||||
out[0]=(range<<4)|(filter<<2)|((i+16>=len && loopStart<0)?1:0);
|
||||
for (int j=0; j<8; j++) {
|
||||
out[j+1]=possibleOut[filter][range][j];
|
||||
}
|
||||
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
last1[j][k]=last1[filter][range];
|
||||
last2[j][k]=last2[filter][range];
|
||||
}
|
||||
}
|
||||
out+=9;
|
||||
total+=9;
|
||||
}
|
||||
// encode loop block
|
||||
if (loopStart>=0) {
|
||||
long p=loopStart;
|
||||
for (int i=0; i<17; i++) {
|
||||
if (p>=len) {
|
||||
p=loopStart;
|
||||
}
|
||||
in[i]=buf[p++];
|
||||
}
|
||||
|
||||
if (emphasis) {
|
||||
for (int j=0; j<17; j++) {
|
||||
x0=x1;
|
||||
x1=x2;
|
||||
x2=in[j];
|
||||
|
||||
if (j==0) continue;
|
||||
emphOut=((x1<<11)-x0*370-in[j]*374)/1305;
|
||||
if (emphOut<-32768) emphOut=-32768;
|
||||
if (emphOut>32767) emphOut=32767;
|
||||
in[j-1]=emphOut;
|
||||
}
|
||||
}
|
||||
|
||||
// encode (filter 0/1 only)
|
||||
for (int j=0; j<2; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
brrEncodeBlock(in,possibleOut[j][k],k,j,&last1[j][k],&last2[j][k],&avgError[j][k]);
|
||||
}
|
||||
}
|
||||
|
||||
// find best filter/range
|
||||
int candError=0x7fffffff;
|
||||
for (int j=0; j<2; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
if (avgError[j][k]<candError) {
|
||||
candError=avgError[j][k];
|
||||
filter=j;
|
||||
range=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write
|
||||
out[0]=(range<<4)|(filter<<2)|3;
|
||||
for (int j=0; j<8; j++) {
|
||||
out[j+1]=possibleOut[filter][range][j];
|
||||
}
|
||||
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
last1[j][k]=last1[filter][range];
|
||||
last2[j][k]=last2[filter][range];
|
||||
}
|
||||
}
|
||||
buf+=16;
|
||||
out+=9;
|
||||
total+=9;
|
||||
}
|
||||
|
|
@ -474,9 +349,11 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart) {
|
|||
*out=next<<1; \
|
||||
out++;
|
||||
|
||||
long brrDecode(unsigned char* buf, short* out, long len) {
|
||||
long brrDecode(unsigned char* buf, short* out, long len, unsigned char emphasis) {
|
||||
if (len==0) return 0;
|
||||
|
||||
short* outOrig=out;
|
||||
|
||||
long total=0;
|
||||
|
||||
int last1=0;
|
||||
|
|
@ -503,5 +380,20 @@ long brrDecode(unsigned char* buf, short* out, long len) {
|
|||
buf+=9;
|
||||
}
|
||||
|
||||
if (emphasis) {
|
||||
short x0=0;
|
||||
short x1=0;
|
||||
short x2=0;
|
||||
for (long i=0; i<=total; i++) {
|
||||
x0=x1;
|
||||
x1=x2;
|
||||
x2=(i>=total)?0:outOrig[i];
|
||||
|
||||
if (i==0) continue;
|
||||
|
||||
outOrig[i-1]=(x0*370+x1*1305+x2*374)>>11;
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,21 +30,23 @@ extern "C" {
|
|||
/**
|
||||
* read len samples from buf, encode in BRR and output to out.
|
||||
* @param buf input data.
|
||||
* @param out output buffer. shall be at least 9*(len/16) shorts in size.
|
||||
* @param out output buffer. shall be at least 9*((15+len)/16) shorts in size (9 more if loopStart is not -1!)
|
||||
* @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 -1 for no loop). this is used to ensure the respective block has no filter in order to loop properly.
|
||||
* @param emphasis apply filter to compensate for Gaussian interpolation high frequency loss.
|
||||
* @return number of written samples.
|
||||
*/
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart);
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigned char emphasis);
|
||||
|
||||
/**
|
||||
* read len bytes from buf, decode BRR and output to out.
|
||||
* @param buf input data.
|
||||
* @param out output buffer. shall be at least 16*(len/9) shorts in size.
|
||||
* @param len input length (shall be a multiple of 9).
|
||||
* @param emphasis apply filter to simulate Gaussian interpolation high frequency loss.
|
||||
* @return number of written bytes.
|
||||
*/
|
||||
long brrDecode(unsigned char* buf, short* out, long len);
|
||||
long brrDecode(unsigned char* buf, short* out, long len, unsigned char emphasis);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
36
src/engine/defines.h
Normal file
36
src/engine/defines.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef _DEFINES_H
|
||||
#define _DEFINES_H
|
||||
|
||||
// global
|
||||
#define DIV_MAX_CHIPS 32
|
||||
#define DIV_MAX_CHANS 128
|
||||
#define DIV_MAX_PATTERNS 256
|
||||
|
||||
// in-pattern
|
||||
#define DIV_MAX_ROWS 256
|
||||
#define DIV_MAX_COLS 32
|
||||
#define DIV_MAX_EFFECTS 8
|
||||
|
||||
// sample related
|
||||
#define DIV_MAX_SAMPLE_TYPE 4
|
||||
|
||||
#endif
|
||||
|
|
@ -884,10 +884,10 @@ void DivEngine::runExportThread() {
|
|||
break;
|
||||
}
|
||||
case DIV_EXPORT_MODE_MANY_SYS: {
|
||||
SNDFILE* sf[32];
|
||||
SF_INFO si[32];
|
||||
String fname[32];
|
||||
SFWrapper sfWrap[32];
|
||||
SNDFILE* sf[DIV_MAX_CHIPS];
|
||||
SF_INFO si[DIV_MAX_CHIPS];
|
||||
String fname[DIV_MAX_CHIPS];
|
||||
SFWrapper sfWrap[DIV_MAX_CHIPS];
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
sf[i]=NULL;
|
||||
si[i].samplerate=got.rate;
|
||||
|
|
@ -915,7 +915,7 @@ void DivEngine::runExportThread() {
|
|||
float* outBuf[2];
|
||||
outBuf[0]=new float[EXPORT_BUFSIZE];
|
||||
outBuf[1]=new float[EXPORT_BUFSIZE];
|
||||
short* sysBuf[32];
|
||||
short* sysBuf[DIV_MAX_CHIPS];
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
sysBuf[i]=new short[EXPORT_BUFSIZE*2];
|
||||
}
|
||||
|
|
@ -1399,7 +1399,7 @@ void DivEngine::initSongWithDesc(const char* description, bool inBase64) {
|
|||
c.loadFromMemory(description);
|
||||
}
|
||||
int index=0;
|
||||
for (; index<32; index++) {
|
||||
for (; index<DIV_MAX_CHIPS; index++) {
|
||||
song.system[index]=systemFromFileFur(c.getInt(fmt::sprintf("id%d",index),0));
|
||||
if (song.system[index]==DIV_SYSTEM_NULL) {
|
||||
break;
|
||||
|
|
@ -1456,7 +1456,7 @@ void DivEngine::swapChannels(int src, int dest) {
|
|||
return;
|
||||
}
|
||||
|
||||
for (int i=0; i<256; i++) {
|
||||
for (int i=0; i<DIV_MAX_PATTERNS; i++) {
|
||||
curOrders->ord[dest][i]^=curOrders->ord[src][i];
|
||||
curOrders->ord[src][i]^=curOrders->ord[dest][i];
|
||||
curOrders->ord[dest][i]^=curOrders->ord[src][i];
|
||||
|
|
@ -1487,7 +1487,7 @@ void DivEngine::swapChannels(int src, int dest) {
|
|||
|
||||
void DivEngine::stompChannel(int ch) {
|
||||
logV("stomping channel %d",ch);
|
||||
for (int i=0; i<256; i++) {
|
||||
for (int i=0; i<DIV_MAX_PATTERNS; i++) {
|
||||
curOrders->ord[ch][i]=0;
|
||||
}
|
||||
curPat[ch].wipePatterns();
|
||||
|
|
@ -1649,8 +1649,8 @@ void DivEngine::changeSystem(int index, DivSystem which, bool preserveOrder) {
|
|||
}
|
||||
|
||||
bool DivEngine::addSystem(DivSystem which) {
|
||||
if (song.systemLen>32) {
|
||||
lastError="max number of systems is 32";
|
||||
if (song.systemLen>DIV_MAX_CHIPS) {
|
||||
lastError=fmt::sprintf("max number of systems is %d",DIV_MAX_CHIPS);
|
||||
return false;
|
||||
}
|
||||
if (chans+getChannelCount(which)>DIV_MAX_CHANS) {
|
||||
|
|
@ -1786,7 +1786,7 @@ bool DivEngine::swapSystem(int src, int dest, bool preserveOrder) {
|
|||
|
||||
for (size_t i=0; i<song.subsong.size(); i++) {
|
||||
DivOrders prevOrders=song.subsong[i]->orders;
|
||||
DivPattern* prevPat[DIV_MAX_CHANS][256];
|
||||
DivPattern* prevPat[DIV_MAX_CHANS][DIV_MAX_PATTERNS];
|
||||
unsigned char prevEffectCols[DIV_MAX_CHANS];
|
||||
String prevChanName[DIV_MAX_CHANS];
|
||||
String prevChanShortName[DIV_MAX_CHANS];
|
||||
|
|
@ -1794,7 +1794,7 @@ bool DivEngine::swapSystem(int src, int dest, bool preserveOrder) {
|
|||
unsigned char prevChanCollapse[DIV_MAX_CHANS];
|
||||
|
||||
for (int j=0; j<tchans; j++) {
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
prevPat[j][k]=song.subsong[i]->pat[j].data[k];
|
||||
}
|
||||
prevEffectCols[j]=song.subsong[i]->pat[j].effectCols;
|
||||
|
|
@ -1806,7 +1806,7 @@ bool DivEngine::swapSystem(int src, int dest, bool preserveOrder) {
|
|||
}
|
||||
|
||||
for (int j=0; j<tchans; j++) {
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
song.subsong[i]->orders.ord[j][k]=prevOrders.ord[swappedChannels[j]][k];
|
||||
song.subsong[i]->pat[j].data[k]=prevPat[swappedChannels[j]][k];
|
||||
}
|
||||
|
|
@ -2768,7 +2768,7 @@ void DivEngine::delInstrument(int index) {
|
|||
song.insLen=song.ins.size();
|
||||
for (int i=0; i<chans; i++) {
|
||||
for (size_t j=0; j<song.subsong.size(); j++) {
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
if (song.subsong[j]->pat[i].data[k]==NULL) continue;
|
||||
for (int l=0; l<song.subsong[j]->patLen; l++) {
|
||||
if (song.subsong[j]->pat[i].data[k]->data[l][2]>index) {
|
||||
|
|
@ -3468,7 +3468,7 @@ void DivEngine::delSample(int index) {
|
|||
|
||||
void DivEngine::addOrder(bool duplicate, bool where) {
|
||||
unsigned char order[DIV_MAX_CHANS];
|
||||
if (curSubSong->ordersLen>=0xff) return;
|
||||
if (curSubSong->ordersLen>=(DIV_MAX_PATTERNS-1)) return;
|
||||
memset(order,0,DIV_MAX_CHANS);
|
||||
BUSY_BEGIN_SOFT;
|
||||
if (duplicate) {
|
||||
|
|
@ -3476,14 +3476,14 @@ void DivEngine::addOrder(bool duplicate, bool where) {
|
|||
order[i]=curOrders->ord[i][curOrder];
|
||||
}
|
||||
} else {
|
||||
bool used[256];
|
||||
bool used[DIV_MAX_PATTERNS];
|
||||
for (int i=0; i<chans; i++) {
|
||||
memset(used,0,sizeof(bool)*256);
|
||||
memset(used,0,sizeof(bool)*DIV_MAX_PATTERNS);
|
||||
for (int j=0; j<curSubSong->ordersLen; j++) {
|
||||
used[curOrders->ord[i][j]]=true;
|
||||
}
|
||||
order[i]=0xff;
|
||||
for (int j=0; j<256; j++) {
|
||||
order[i]=(DIV_MAX_PATTERNS-1);
|
||||
for (int j=0; j<DIV_MAX_PATTERNS; j++) {
|
||||
if (!used[j]) {
|
||||
order[i]=j;
|
||||
break;
|
||||
|
|
@ -3518,7 +3518,7 @@ void DivEngine::addOrder(bool duplicate, bool where) {
|
|||
|
||||
void DivEngine::deepCloneOrder(bool where) {
|
||||
unsigned char order[DIV_MAX_CHANS];
|
||||
if (curSubSong->ordersLen>=0xff) return;
|
||||
if (curSubSong->ordersLen>=(DIV_MAX_PATTERNS-1)) return;
|
||||
warnings="";
|
||||
BUSY_BEGIN_SOFT;
|
||||
for (int i=0; i<chans; i++) {
|
||||
|
|
@ -3526,14 +3526,14 @@ void DivEngine::deepCloneOrder(bool where) {
|
|||
logD("channel %d",i);
|
||||
order[i]=curOrders->ord[i][curOrder];
|
||||
// find free slot
|
||||
for (int j=0; j<256; j++) {
|
||||
for (int j=0; j<DIV_MAX_PATTERNS; j++) {
|
||||
logD("finding free slot in %d...",j);
|
||||
if (curPat[i].data[j]==NULL) {
|
||||
int origOrd=order[i];
|
||||
order[i]=j;
|
||||
DivPattern* oldPat=curPat[i].getPattern(origOrd,false);
|
||||
DivPattern* pat=curPat[i].getPattern(j,true);
|
||||
memcpy(pat->data,oldPat->data,256*32*sizeof(short));
|
||||
memcpy(pat->data,oldPat->data,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short));
|
||||
logD("found at %d",j);
|
||||
didNotFind=false;
|
||||
break;
|
||||
|
|
@ -3629,7 +3629,7 @@ void DivEngine::moveOrderDown() {
|
|||
void DivEngine::exchangeIns(int one, int two) {
|
||||
for (int i=0; i<chans; i++) {
|
||||
for (size_t j=0; j<song.subsong.size(); j++) {
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
if (song.subsong[j]->pat[i].data[k]==NULL) continue;
|
||||
for (int l=0; l<song.subsong[j]->patLen; l++) {
|
||||
if (song.subsong[j]->pat[i].data[k]->data[l][2]==one) {
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@
|
|||
#define BUSY_BEGIN_SOFT softLocked=true; isBusy.lock();
|
||||
#define BUSY_END isBusy.unlock(); softLocked=false;
|
||||
|
||||
#define DIV_VERSION "dev128"
|
||||
#define DIV_ENGINE_VERSION 128
|
||||
#define DIV_VERSION "dev129"
|
||||
#define DIV_ENGINE_VERSION 129
|
||||
// for imports
|
||||
#define DIV_VERSION_MOD 0xff01
|
||||
#define DIV_VERSION_FC 0xff02
|
||||
|
|
@ -318,7 +318,7 @@ enum DivChanTypes {
|
|||
extern const char* cmdName[];
|
||||
|
||||
class DivEngine {
|
||||
DivDispatchContainer disCont[32];
|
||||
DivDispatchContainer disCont[DIV_MAX_CHIPS];
|
||||
TAAudio* output;
|
||||
TAAudioDesc want, got;
|
||||
String exportPath;
|
||||
|
|
|
|||
|
|
@ -1581,7 +1581,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
unsigned int wavePtr[256];
|
||||
unsigned int samplePtr[256];
|
||||
unsigned int subSongPtr[256];
|
||||
unsigned int sysFlagsPtr[32];
|
||||
unsigned int sysFlagsPtr[DIV_MAX_CHIPS];
|
||||
std::vector<int> patPtr;
|
||||
int numberOfSubSongs=0;
|
||||
char magic[5];
|
||||
|
|
@ -1760,7 +1760,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
delete[] file;
|
||||
return false;
|
||||
}
|
||||
if (subSong->patLen>256) {
|
||||
if (subSong->patLen>DIV_MAX_ROWS) {
|
||||
logE("pattern length is too large!");
|
||||
lastError="pattern length is too large!";
|
||||
delete[] file;
|
||||
|
|
@ -1772,7 +1772,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
delete[] file;
|
||||
return false;
|
||||
}
|
||||
if (subSong->ordersLen>256) {
|
||||
if (subSong->ordersLen>DIV_MAX_PATTERNS) {
|
||||
logE("song is too long!");
|
||||
lastError="song is too long!";
|
||||
delete[] file;
|
||||
|
|
@ -1804,7 +1804,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
}
|
||||
|
||||
logD("systems:");
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
unsigned char sysID=reader.readC();
|
||||
ds.system[i]=systemFromFileFur(sysID);
|
||||
logD("- %d: %.2x (%s)",i,sysID,getSystemName(ds.system[i]));
|
||||
|
|
@ -1826,7 +1826,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
}
|
||||
|
||||
// system volume
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
ds.systemVol[i]=reader.readC();
|
||||
if (ds.version<59 && ds.system[i]==DIV_SYSTEM_NES) {
|
||||
ds.systemVol[i]/=4;
|
||||
|
|
@ -1834,15 +1834,15 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
}
|
||||
|
||||
// system panning
|
||||
for (int i=0; i<32; i++) ds.systemPan[i]=reader.readC();
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) ds.systemPan[i]=reader.readC();
|
||||
|
||||
// system props
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
sysFlagsPtr[i]=reader.readI();
|
||||
}
|
||||
|
||||
// handle compound systems
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
if (ds.system[i]==DIV_SYSTEM_GENESIS ||
|
||||
ds.system[i]==DIV_SYSTEM_GENESIS_EXT ||
|
||||
ds.system[i]==DIV_SYSTEM_ARCADE) {
|
||||
|
|
@ -1851,7 +1851,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
ds.systemVol[j]=ds.systemVol[j-1];
|
||||
ds.systemPan[j]=ds.systemPan[j-1];
|
||||
}
|
||||
if (++ds.systemLen>32) ds.systemLen=32;
|
||||
if (++ds.systemLen>DIV_MAX_CHIPS) ds.systemLen=DIV_MAX_CHIPS;
|
||||
|
||||
if (ds.system[i]==DIV_SYSTEM_GENESIS) {
|
||||
ds.system[i]=DIV_SYSTEM_YM2612;
|
||||
|
|
@ -2000,7 +2000,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
|
||||
for (int i=0; i<tchans; i++) {
|
||||
subSong->pat[i].effectCols=reader.readC();
|
||||
if (subSong->pat[i].effectCols<1 || subSong->pat[i].effectCols>8) {
|
||||
if (subSong->pat[i].effectCols<1 || subSong->pat[i].effectCols>DIV_MAX_EFFECTS) {
|
||||
logE("channel %d has zero or too many effect columns! (%d)",i,subSong->pat[i].effectCols);
|
||||
lastError=fmt::sprintf("channel %d has too many effect columns! (%d)",i,subSong->pat[i].effectCols);
|
||||
delete[] file;
|
||||
|
|
@ -2198,7 +2198,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
// read system flags
|
||||
if (ds.version>=119) {
|
||||
logD("reading chip flags...");
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
if (sysFlagsPtr[i]==0) continue;
|
||||
|
||||
if (!reader.seek(sysFlagsPtr[i],SEEK_SET)) {
|
||||
|
|
@ -2416,7 +2416,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
delete[] file;
|
||||
return false;
|
||||
}
|
||||
if (index<0 || index>255) {
|
||||
if (index<0 || index>(DIV_MAX_PATTERNS-1)) {
|
||||
logE("pattern index out of range!",i);
|
||||
lastError="pattern index out of range!";
|
||||
ds.unload();
|
||||
|
|
@ -4175,14 +4175,14 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
|||
|
||||
// fail if values are out of range
|
||||
/*
|
||||
if (subSong->ordersLen>256) {
|
||||
logE("maximum song length is 256!");
|
||||
lastError="maximum song length is 256";
|
||||
if (subSong->ordersLen>DIV_MAX_PATTERNS) {
|
||||
logE("maximum song length is %d!",DIV_MAX_PATTERNS);
|
||||
lastError=fmt::sprintf("maximum song length is %d",DIV_MAX_PATTERNS);
|
||||
return NULL;
|
||||
}
|
||||
if (subSong->patLen>256) {
|
||||
logE("maximum pattern length is 256!");
|
||||
lastError="maximum pattern length is 256";
|
||||
if (subSong->patLen>DIV_MAX_ROWS) {
|
||||
logE("maximum pattern length is %d!",DIV_MAX_ROWS);
|
||||
lastError=fmt::sprintf("maximum pattern length is %d",DIV_MAX_ROWS);
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
|
@ -4236,18 +4236,18 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
|||
for (int i=0; i<chans; i++) {
|
||||
for (size_t j=0; j<song.subsong.size(); j++) {
|
||||
DivSubSong* subs=song.subsong[j];
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
if (subs->pat[i].data[k]==NULL) continue;
|
||||
patsToWrite.push_back(PatToWrite(j,i,k));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bool alreadyAdded[256];
|
||||
bool alreadyAdded[DIV_MAX_PATTERNS];
|
||||
for (int i=0; i<chans; i++) {
|
||||
for (size_t j=0; j<song.subsong.size(); j++) {
|
||||
DivSubSong* subs=song.subsong[j];
|
||||
memset(alreadyAdded,0,256*sizeof(bool));
|
||||
memset(alreadyAdded,0,DIV_MAX_PATTERNS*sizeof(bool));
|
||||
for (int k=0; k<subs->ordersLen; k++) {
|
||||
if (alreadyAdded[subs->orders.ord[i][k]]) continue;
|
||||
patsToWrite.push_back(PatToWrite(j,i,subs->orders.ord[i][k]));
|
||||
|
|
@ -4276,7 +4276,7 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
|||
w->writeS(song.sampleLen);
|
||||
w->writeI(patsToWrite.size());
|
||||
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
if (i>=song.systemLen) {
|
||||
w->writeC(0);
|
||||
} else {
|
||||
|
|
@ -4284,17 +4284,17 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
|||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
w->writeC(song.systemVol[i]);
|
||||
}
|
||||
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
w->writeC(song.systemPan[i]);
|
||||
}
|
||||
|
||||
// chip flags (we'll seek here later)
|
||||
sysFlagsPtrSeek=w->tell();
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
w->writeI(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@
|
|||
#define _ORDERS_H
|
||||
|
||||
struct DivOrders {
|
||||
unsigned char ord[DIV_MAX_CHANS][256];
|
||||
unsigned char ord[DIV_MAX_CHANS][DIV_MAX_PATTERNS];
|
||||
|
||||
DivOrders() {
|
||||
memset(ord,0,DIV_MAX_CHANS*256);
|
||||
memset(ord,0,DIV_MAX_CHANS*DIV_MAX_PATTERNS);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@
|
|||
static DivPattern emptyPat;
|
||||
|
||||
DivPattern::DivPattern() {
|
||||
memset(data,-1,256*32*sizeof(short));
|
||||
for (int i=0; i<256; i++) {
|
||||
memset(data,-1,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short));
|
||||
for (int i=0; i<DIV_MAX_ROWS; i++) {
|
||||
data[i][0]=0;
|
||||
data[i][1]=0;
|
||||
}
|
||||
|
|
@ -43,13 +43,13 @@ DivPattern* DivChannelData::getPattern(int index, bool create) {
|
|||
|
||||
std::vector<std::pair<int,int>> DivChannelData::optimize() {
|
||||
std::vector<std::pair<int,int>> ret;
|
||||
for (int i=0; i<256; i++) {
|
||||
for (int i=0; i<DIV_MAX_PATTERNS; i++) {
|
||||
if (data[i]!=NULL) {
|
||||
// compare
|
||||
for (int j=0; j<256; j++) {
|
||||
for (int j=0; j<DIV_MAX_PATTERNS; j++) {
|
||||
if (j==i) continue;
|
||||
if (data[j]==NULL) continue;
|
||||
if (memcmp(data[i]->data,data[j]->data,256*32*sizeof(short))==0) {
|
||||
if (memcmp(data[i]->data,data[j]->data,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short))==0) {
|
||||
delete data[j];
|
||||
data[j]=NULL;
|
||||
logV("%d == %d",i,j);
|
||||
|
|
@ -63,15 +63,15 @@ std::vector<std::pair<int,int>> DivChannelData::optimize() {
|
|||
|
||||
std::vector<std::pair<int,int>> DivChannelData::rearrange() {
|
||||
std::vector<std::pair<int,int>> ret;
|
||||
for (int i=0; i<256; i++) {
|
||||
for (int i=0; i<DIV_MAX_PATTERNS; i++) {
|
||||
if (data[i]==NULL) {
|
||||
for (int j=i; j<256; j++) {
|
||||
for (int j=i; j<DIV_MAX_PATTERNS; j++) {
|
||||
if (data[j]!=NULL) {
|
||||
data[i]=data[j];
|
||||
data[j]=NULL;
|
||||
logV("%d -> %d",j,i);
|
||||
ret.push_back(std::pair<int,int>(j,i));
|
||||
if (++i>=256) break;
|
||||
if (++i>=DIV_MAX_PATTERNS) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ std::vector<std::pair<int,int>> DivChannelData::rearrange() {
|
|||
}
|
||||
|
||||
void DivChannelData::wipePatterns() {
|
||||
for (int i=0; i<256; i++) {
|
||||
for (int i=0; i<DIV_MAX_PATTERNS; i++) {
|
||||
if (data[i]!=NULL) {
|
||||
delete data[i];
|
||||
data[i]=NULL;
|
||||
|
|
@ -95,5 +95,5 @@ void DivPattern::copyOn(DivPattern* dest) {
|
|||
|
||||
DivChannelData::DivChannelData():
|
||||
effectCols(1) {
|
||||
memset(data,0,256*sizeof(void*));
|
||||
memset(data,0,DIV_MAX_PATTERNS*sizeof(void*));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
struct DivPattern {
|
||||
String name;
|
||||
short data[256][32];
|
||||
short data[DIV_MAX_ROWS][DIV_MAX_COLS];
|
||||
|
||||
/**
|
||||
* copy this pattern to another.
|
||||
|
|
@ -42,7 +42,7 @@ struct DivChannelData {
|
|||
// 3: volume
|
||||
// 4-5+: effect/effect value
|
||||
// do NOT access directly unless you know what you're doing!
|
||||
DivPattern* data[256];
|
||||
DivPattern* data[DIV_MAX_PATTERNS];
|
||||
|
||||
/**
|
||||
* get a pattern from this channel, or the empty pattern if not initialized.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include "sound/c64_fp/siddefs-fp.h"
|
||||
#include <math.h>
|
||||
|
||||
#define rWrite(a,v) if (!skipRegisterWrites) {if (isFP) {sid_fp.write(a,v);} else {sid.write(a,v);}; regPool[(a)&0x1f]=v; if (dumpWrites) {addWrite(a,v);} }
|
||||
#define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} }
|
||||
|
||||
#define CHIP_FREQBASE 524288
|
||||
|
||||
|
|
@ -66,6 +66,16 @@ const char** DivPlatformC64::getRegisterSheet() {
|
|||
void DivPlatformC64::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||
int dcOff=isFP?0:sid.get_dc(0);
|
||||
for (size_t i=start; i<start+len; i++) {
|
||||
if (!writes.empty()) {
|
||||
QueuedWrite w=writes.front();
|
||||
if (isFP) {
|
||||
sid_fp.write(w.addr,w.val);
|
||||
} else {
|
||||
sid.write(w.addr,w.val);
|
||||
};
|
||||
regPool[w.addr&0x1f]=w.val;
|
||||
writes.pop();
|
||||
}
|
||||
if (isFP) {
|
||||
sid_fp.clock(4,&bufL[i]);
|
||||
if (++writeOscBuf>=4) {
|
||||
|
|
@ -483,6 +493,7 @@ float DivPlatformC64::getPostAmp() {
|
|||
}
|
||||
|
||||
void DivPlatformC64::reset() {
|
||||
while (!writes.empty()) writes.pop();
|
||||
for (int i=0; i<3; i++) {
|
||||
chan[i]=DivPlatformC64::Channel();
|
||||
chan[i].std.setEngine(parent);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define _C64_H
|
||||
|
||||
#include "../dispatch.h"
|
||||
#include <queue>
|
||||
#include "../macroInt.h"
|
||||
#include "sound/c64/sid.h"
|
||||
#include "sound/c64_fp/SID.h"
|
||||
|
|
@ -61,6 +62,12 @@ class DivPlatformC64: public DivDispatch {
|
|||
Channel chan[3];
|
||||
DivDispatchOscBuffer* oscBuf[3];
|
||||
bool isMuted[3];
|
||||
struct QueuedWrite {
|
||||
unsigned char addr;
|
||||
unsigned char val;
|
||||
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {}
|
||||
};
|
||||
std::queue<QueuedWrite> writes;
|
||||
|
||||
unsigned char filtControl, filtRes, vol;
|
||||
unsigned char writeOscBuf;
|
||||
|
|
|
|||
|
|
@ -484,9 +484,6 @@ void DivPlatformNamcoWSG::reset() {
|
|||
namco->set_voices(chans);
|
||||
namco->set_stereo((devType==2 || devType==30));
|
||||
namco->device_start(NULL);
|
||||
lastPan=0xff;
|
||||
cycles=0;
|
||||
curChan=-1;
|
||||
}
|
||||
|
||||
bool DivPlatformNamcoWSG::isStereo() {
|
||||
|
|
|
|||
|
|
@ -53,9 +53,7 @@ class DivPlatformNamcoWSG: public DivDispatch {
|
|||
QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v) {}
|
||||
};
|
||||
std::queue<QueuedWrite> writes;
|
||||
unsigned char lastPan;
|
||||
|
||||
int cycles, curChan, delay;
|
||||
namco_audio_device* namco;
|
||||
int devType, chans;
|
||||
unsigned char regPool[512];
|
||||
|
|
|
|||
|
|
@ -783,7 +783,7 @@ void DivPlatformQSound::renderSamples(int sysID) {
|
|||
for (int i=0; i<length; i++) {
|
||||
sampleMem[(memPos+i)]=s->dataQSoundA[i];
|
||||
}
|
||||
sampleLoaded[i]=true;
|
||||
sampleLoadedBS[i]=true;
|
||||
}
|
||||
offBS[i]=memPos;
|
||||
memPos+=length+16;
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ double DivPlatformSMS::NOTE_SN(int ch, int note) {
|
|||
if (parent->song.linearPitch==2 || !easyNoise) {
|
||||
return NOTE_PERIODIC(note);
|
||||
}
|
||||
int easyStartingPeriod=16;
|
||||
int easyThreshold=round(12.0*log((chipClock/(easyStartingPeriod*CHIP_DIVIDER))/(0.0625*parent->song.tuning))/log(2.0))-3;
|
||||
if (note>easyThreshold) {
|
||||
return MAX(0,easyStartingPeriod-(note-easyThreshold));
|
||||
}
|
||||
|
|
@ -132,19 +134,23 @@ double DivPlatformSMS::NOTE_SN(int ch, int note) {
|
|||
}
|
||||
|
||||
int DivPlatformSMS::snCalcFreq(int ch) {
|
||||
if (parent->song.linearPitch==2 && easyNoise && chan[ch].baseFreq+chan[ch].pitch+chan[ch].pitch2>(easyThreshold<<7)) {
|
||||
int ret=(((easyStartingPeriod<<7)+0x40)-(chan[ch].baseFreq+chan[ch].pitch+chan[ch].pitch2-(easyThreshold<<7)))>>7;
|
||||
double CHIP_DIVIDER=toneDivider;
|
||||
if (ch==3) CHIP_DIVIDER=noiseDivider;
|
||||
int easyStartingPeriod=16;
|
||||
int easyThreshold=round(128.0*12.0*log((chipClock/(easyStartingPeriod*CHIP_DIVIDER))/(0.0625*parent->song.tuning))/log(2.0))-384+64;
|
||||
if (parent->song.linearPitch==2 && easyNoise && chan[ch].baseFreq+chan[ch].pitch+chan[ch].pitch2>(easyThreshold)) {
|
||||
int ret=(((easyStartingPeriod<<7))-(chan[ch].baseFreq+chan[ch].pitch+chan[ch].pitch2-(easyThreshold)))>>7;
|
||||
if (ret<0) ret=0;
|
||||
return ret;
|
||||
}
|
||||
return parent->calcFreq(chan[ch].baseFreq,chan[ch].pitch,true,0,chan[ch].pitch2,chipClock,ch==3?noiseDivider:toneDivider);
|
||||
return parent->calcFreq(chan[ch].baseFreq,chan[ch].pitch,true,0,chan[ch].pitch2,chipClock,CHIP_DIVIDER);
|
||||
}
|
||||
|
||||
void DivPlatformSMS::tick(bool sysTick) {
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i].std.next();
|
||||
if (chan[i].std.vol.had) {
|
||||
chan[i].outVol=VOL_SCALE_LOG_BROKEN(chan[i].std.vol.val,chan[i].vol,15);
|
||||
chan[i].outVol=VOL_SCALE_LOG(chan[i].std.vol.val,chan[i].vol,15);
|
||||
if (chan[i].outVol<0) chan[i].outVol=0;
|
||||
// old formula
|
||||
// ((chan[i].vol&15)*MIN(15,chan[i].std.vol.val))>>4;
|
||||
|
|
@ -152,10 +158,9 @@ void DivPlatformSMS::tick(bool sysTick) {
|
|||
}
|
||||
if (chan[i].std.arp.had) {
|
||||
if (!chan[i].inPorta) {
|
||||
// TODO: check whether this weird octave boundary thing applies to other systems as well
|
||||
// TODO: add compatibility flag. this is horrible.
|
||||
int areYouSerious=parent->calcArp(chan[i].note,chan[i].std.arp.val);
|
||||
while (areYouSerious>0x60) areYouSerious-=12;
|
||||
if (!easyNoise) while (areYouSerious>0x60) areYouSerious-=12;
|
||||
chan[i].baseFreq=NOTE_SN(i,areYouSerious);
|
||||
chan[i].actualNote=areYouSerious;
|
||||
chan[i].freqChanged=true;
|
||||
|
|
@ -422,7 +427,7 @@ void DivPlatformSMS::reset() {
|
|||
YMPSG_Init(&sn_nuked,isRealSN,12,isRealSN?13:15,isRealSN?16383:32767);
|
||||
snNoiseMode=3;
|
||||
rWrite(0,0xe7);
|
||||
updateSNMode=false;
|
||||
updateSNMode=true;
|
||||
oldValue=0xff;
|
||||
lastPan=0xff;
|
||||
if (stereo) {
|
||||
|
|
@ -464,40 +469,27 @@ void DivPlatformSMS::setFlags(const DivConfig& flags) {
|
|||
switch (flags.getInt("clockSel",0)) {
|
||||
case 1:
|
||||
chipClock=COLOR_PAL*4.0/5.0;
|
||||
easyThreshold=84;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
case 2:
|
||||
chipClock=4000000;
|
||||
easyThreshold=86;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
case 3:
|
||||
chipClock=COLOR_NTSC/2.0;
|
||||
easyThreshold=72;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
case 4:
|
||||
chipClock=3000000;
|
||||
easyThreshold=81;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
case 5:
|
||||
chipClock=2000000;
|
||||
easyThreshold=74;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
case 6:
|
||||
chipClock=COLOR_NTSC/8.0;
|
||||
easyThreshold=48;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
default:
|
||||
chipClock=COLOR_NTSC;
|
||||
easyThreshold=84;
|
||||
easyStartingPeriod=13;
|
||||
break;
|
||||
}
|
||||
CHECK_CUSTOM_CLOCK;
|
||||
resetPhase=!flags.getBool("noPhaseReset",false);
|
||||
easyNoise=!flags.getBool("noEasyNoise",false);
|
||||
divider=16;
|
||||
|
|
@ -568,7 +560,7 @@ void DivPlatformSMS::setFlags(const DivConfig& flags) {
|
|||
stereo=false;
|
||||
break;
|
||||
}
|
||||
CHECK_CUSTOM_CLOCK;
|
||||
|
||||
rate=chipClock/divider;
|
||||
for (int i=0; i<4; i++) {
|
||||
oscBuf[i]->rate=rate;
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ class DivPlatformSMS: public DivDispatch {
|
|||
int divider=16;
|
||||
double toneDivider=64.0;
|
||||
double noiseDivider=64.0;
|
||||
int easyThreshold;
|
||||
int easyStartingPeriod;
|
||||
bool updateSNMode;
|
||||
bool resetPhase;
|
||||
bool isRealSN;
|
||||
|
|
|
|||
|
|
@ -214,13 +214,13 @@ void DivPlatformSNES::tick(bool sysTick) {
|
|||
loop=start;
|
||||
} else if (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
|
||||
start=sampleOff[chan[i].sample];
|
||||
end=MIN(start+MAX(s->lengthBRR,1),getSampleMemCapacity());
|
||||
end=MIN(start+MAX(s->lengthBRR+((s->loop && s->depth!=DIV_SAMPLE_DEPTH_BRR)?9:0),1),getSampleMemCapacity());
|
||||
loop=MAX(start,end-1);
|
||||
if (chan[i].audPos>0) {
|
||||
start=start+MIN(chan[i].audPos,s->lengthBRR-1)/16*9;
|
||||
}
|
||||
if (s->loopStart>=0) {
|
||||
loop=start+s->loopStart/16*9;
|
||||
loop=((s->depth!=DIV_SAMPLE_DEPTH_BRR)?9:0)+start+((s->loopStart/16)*9);
|
||||
}
|
||||
} else {
|
||||
start=0;
|
||||
|
|
@ -817,7 +817,7 @@ void DivPlatformSNES::renderSamples(int sysID) {
|
|||
continue;
|
||||
}
|
||||
|
||||
int length=s->lengthBRR;
|
||||
int length=s->lengthBRR+((s->loop && s->depth!=DIV_SAMPLE_DEPTH_BRR)?9:0);
|
||||
int actualLength=MIN((int)(getSampleMemCapacity()-memPos)/9*9,length);
|
||||
if (actualLength>0) {
|
||||
sampleOff[i]=memPos;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ void DivPlatformVIC20::calcAndWriteOutVol(int ch, int env) {
|
|||
}
|
||||
|
||||
void DivPlatformVIC20::writeOutVol(int ch) {
|
||||
if (!isMuted[ch]) {
|
||||
if (!isMuted[ch] && chan[ch].active) {
|
||||
rWrite(14,chan[ch].outVol);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1581,7 +1581,11 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
if (disCont[i].lastAvail>0) {
|
||||
disCont[i].flush(disCont[i].lastAvail);
|
||||
}
|
||||
disCont[i].runtotal=blip_clocks_needed(disCont[i].bb[0],size-disCont[i].lastAvail);
|
||||
if (size<disCont[i].lastAvail) {
|
||||
disCont[i].runtotal=0;
|
||||
} else {
|
||||
disCont[i].runtotal=blip_clocks_needed(disCont[i].bb[0],size-disCont[i].lastAvail);
|
||||
}
|
||||
if (disCont[i].runtotal>disCont[i].bbInLen) {
|
||||
logV("growing dispatch %d bbIn to %d",i,disCont[i].runtotal+256);
|
||||
delete[] disCont[i].bbIn[0];
|
||||
|
|
|
|||
|
|
@ -52,14 +52,14 @@ void DivSample::putSampleData(SafeWriter* w) {
|
|||
w->writeI(centerRate);
|
||||
w->writeC(depth);
|
||||
w->writeC(loopMode);
|
||||
w->writeC(brrEmphasis);
|
||||
w->writeC(0); // reserved
|
||||
w->writeC(0);
|
||||
w->writeI(loop?loopStart:-1);
|
||||
w->writeI(loop?loopEnd:-1);
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
for (int i=0; i<DIV_MAX_SAMPLE_TYPE; i++) {
|
||||
unsigned int out=0;
|
||||
for (int j=0; j<32; j++) {
|
||||
for (int j=0; j<DIV_MAX_CHIPS; j++) {
|
||||
if (renderOn[i][j]) out|=1<<j;
|
||||
}
|
||||
w->writeI(out);
|
||||
|
|
@ -125,17 +125,21 @@ DivDataErrors DivSample::readSampleData(SafeReader& reader, short version) {
|
|||
reader.readC();
|
||||
}
|
||||
|
||||
if (version>=129) {
|
||||
brrEmphasis=reader.readC();
|
||||
} else {
|
||||
reader.readC();
|
||||
}
|
||||
// reserved
|
||||
reader.readC();
|
||||
reader.readC();
|
||||
|
||||
loopStart=reader.readI();
|
||||
loopEnd=reader.readI();
|
||||
loop=(loopStart>=0)&&(loopEnd>=0);
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
for (int i=0; i<DIV_MAX_SAMPLE_TYPE; i++) {
|
||||
unsigned int outMask=(unsigned int)reader.readI();
|
||||
for (int j=0; j<32; j++) {
|
||||
for (int j=0; j<DIV_MAX_CHIPS; j++) {
|
||||
renderOn[i][j]=outMask&(1<<j);
|
||||
}
|
||||
}
|
||||
|
|
@ -490,8 +494,8 @@ bool DivSample::initInternal(DivSampleDepth d, int count) {
|
|||
case DIV_SAMPLE_DEPTH_BRR: // BRR
|
||||
if (dataBRR!=NULL) delete[] dataBRR;
|
||||
lengthBRR=9*((count+15)/16);
|
||||
dataBRR=new unsigned char[lengthBRR];
|
||||
memset(dataBRR,0,lengthBRR);
|
||||
dataBRR=new unsigned char[lengthBRR+9];
|
||||
memset(dataBRR,0,lengthBRR+9);
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_VOX: // VOX
|
||||
if (dataVOX!=NULL) delete[] dataVOX;
|
||||
|
|
@ -1041,7 +1045,7 @@ void DivSample::render(unsigned int formatMask) {
|
|||
}
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_BRR: // BRR
|
||||
brrDecode(dataBRR,data16,lengthBRR);
|
||||
brrDecode(dataBRR,data16,lengthBRR,brrEmphasis);
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_VOX: // VOX
|
||||
oki_decode(dataVOX,data16,samples);
|
||||
|
|
@ -1100,7 +1104,7 @@ void DivSample::render(unsigned int formatMask) {
|
|||
}
|
||||
if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_BRR)) { // BRR
|
||||
if (!initInternal(DIV_SAMPLE_DEPTH_BRR,samples)) return;
|
||||
brrEncode(data16,dataBRR,(samples+15)&(~15),loop?loopStart:-1);
|
||||
brrEncode(data16,dataBRR,samples,loop?loopStart:-1,brrEmphasis);
|
||||
}
|
||||
if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_VOX)) { // VOX
|
||||
if (!initInternal(DIV_SAMPLE_DEPTH_VOX,samples)) return;
|
||||
|
|
@ -1174,9 +1178,9 @@ DivSampleHistory* DivSample::prepareUndo(bool data, bool doNotPush) {
|
|||
duplicate=new unsigned char[getCurBufLen()];
|
||||
memcpy(duplicate,getCurBuf(),getCurBufLen());
|
||||
}
|
||||
h=new DivSampleHistory(duplicate,getCurBufLen(),samples,depth,rate,centerRate,loopStart,loopEnd,loop,loopMode);
|
||||
h=new DivSampleHistory(duplicate,getCurBufLen(),samples,depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,loopMode);
|
||||
} else {
|
||||
h=new DivSampleHistory(depth,rate,centerRate,loopStart,loopEnd,loop,loopMode);
|
||||
h=new DivSampleHistory(depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,loopMode);
|
||||
}
|
||||
if (!doNotPush) {
|
||||
while (!redoHist.empty()) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define _SAMPLE_H
|
||||
|
||||
#include "../ta-utils.h"
|
||||
#include "defines.h"
|
||||
#include "safeWriter.h"
|
||||
#include "dataErrors.h"
|
||||
#include <deque>
|
||||
|
|
@ -60,10 +61,10 @@ struct DivSampleHistory {
|
|||
unsigned int length, samples;
|
||||
DivSampleDepth depth;
|
||||
int rate, centerRate, loopStart, loopEnd;
|
||||
bool loop;
|
||||
bool loop, brrEmphasis;
|
||||
DivSampleLoopMode loopMode;
|
||||
bool hasSample;
|
||||
DivSampleHistory(void* d, unsigned int l, unsigned int s, DivSampleDepth de, int r, int cr, int ls, int le, bool lp, DivSampleLoopMode lm):
|
||||
DivSampleHistory(void* d, unsigned int l, unsigned int s, DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, DivSampleLoopMode lm):
|
||||
data((unsigned char*)d),
|
||||
length(l),
|
||||
samples(s),
|
||||
|
|
@ -73,9 +74,10 @@ struct DivSampleHistory {
|
|||
loopStart(ls),
|
||||
loopEnd(le),
|
||||
loop(lp),
|
||||
brrEmphasis(be),
|
||||
loopMode(lm),
|
||||
hasSample(true) {}
|
||||
DivSampleHistory(DivSampleDepth de, int r, int cr, int ls, int le, bool lp, DivSampleLoopMode lm):
|
||||
DivSampleHistory(DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, DivSampleLoopMode lm):
|
||||
data(NULL),
|
||||
length(0),
|
||||
samples(0),
|
||||
|
|
@ -85,6 +87,7 @@ struct DivSampleHistory {
|
|||
loopStart(ls),
|
||||
loopEnd(le),
|
||||
loop(lp),
|
||||
brrEmphasis(be),
|
||||
loopMode(lm),
|
||||
hasSample(false) {}
|
||||
~DivSampleHistory();
|
||||
|
|
@ -106,14 +109,14 @@ struct DivSample {
|
|||
// - 10: VOX ADPCM
|
||||
// - 16: 16-bit PCM
|
||||
DivSampleDepth depth;
|
||||
bool loop;
|
||||
bool loop, brrEmphasis;
|
||||
// valid values are:
|
||||
// - 0: Forward loop
|
||||
// - 1: Backward loop
|
||||
// - 2: Pingpong loop
|
||||
DivSampleLoopMode loopMode;
|
||||
|
||||
bool renderOn[4][32];
|
||||
bool renderOn[DIV_MAX_SAMPLE_TYPE][DIV_MAX_CHIPS];
|
||||
|
||||
// these are the new data structures.
|
||||
signed char* data8; // 8
|
||||
|
|
@ -306,6 +309,7 @@ struct DivSample {
|
|||
loopOffP(0),
|
||||
depth(DIV_SAMPLE_DEPTH_16BIT),
|
||||
loop(false),
|
||||
brrEmphasis(true),
|
||||
loopMode(DIV_SAMPLE_LOOP_FORWARD),
|
||||
data8(NULL),
|
||||
data16(NULL),
|
||||
|
|
@ -328,11 +332,10 @@ struct DivSample {
|
|||
lengthBRR(0),
|
||||
lengthVOX(0),
|
||||
samples(0) {
|
||||
for (int i=0; i<32; i++) {
|
||||
renderOn[0][i]=true;
|
||||
renderOn[1][i]=true;
|
||||
renderOn[2][i]=true;
|
||||
renderOn[3][i]=true;
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
for (int j=0; j<DIV_MAX_SAMPLE_TYPE; j++) {
|
||||
renderOn[j][i]=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
~DivSample();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ void DivSubSong::clearData() {
|
|||
pat[i].wipePatterns();
|
||||
}
|
||||
|
||||
memset(orders.ord,0,DIV_MAX_CHANS*256);
|
||||
memset(orders.ord,0,DIV_MAX_CHANS*DIV_MAX_PATTERNS);
|
||||
ordersLen=1;
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ void DivSubSong::optimizePatterns() {
|
|||
logD("optimizing channel %d...",i);
|
||||
std::vector<std::pair<int,int>> clearOuts=pat[i].optimize();
|
||||
for (auto& j: clearOuts) {
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
if (orders.ord[i][k]==j.first) {
|
||||
orders.ord[i][k]=j.second;
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ void DivSubSong::rearrangePatterns() {
|
|||
logD("re-arranging channel %d...",i);
|
||||
std::vector<std::pair<int,int>> clearOuts=pat[i].rearrange();
|
||||
for (auto& j: clearOuts) {
|
||||
for (int k=0; k<256; k++) {
|
||||
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
|
||||
if (orders.ord[i][k]==j.first) {
|
||||
orders.ord[i][k]=j.second;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@
|
|||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#define DIV_MAX_CHANS 128
|
||||
|
||||
#include "defines.h"
|
||||
#include "../ta-utils.h"
|
||||
#include "config.h"
|
||||
#include "orders.h"
|
||||
|
|
@ -230,11 +229,11 @@ struct DivSong {
|
|||
bool isDMF;
|
||||
|
||||
// system
|
||||
DivSystem system[32];
|
||||
DivSystem system[DIV_MAX_CHIPS];
|
||||
unsigned char systemLen;
|
||||
signed char systemVol[32];
|
||||
signed char systemPan[32];
|
||||
DivConfig systemFlags[32];
|
||||
signed char systemVol[DIV_MAX_CHIPS];
|
||||
signed char systemPan[DIV_MAX_CHIPS];
|
||||
DivConfig systemFlags[DIV_MAX_CHIPS];
|
||||
|
||||
// song information
|
||||
String name, author, systemName;
|
||||
|
|
@ -428,7 +427,7 @@ struct DivSong {
|
|||
snNoLowPeriods(false),
|
||||
disableSampleMacro(false),
|
||||
autoSystem(true) {
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
system[i]=DIV_SYSTEM_NULL;
|
||||
systemVol[i]=64;
|
||||
systemPan[i]=0;
|
||||
|
|
|
|||
|
|
@ -945,15 +945,15 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
|||
w->writeI(0); // will be written later
|
||||
w->writeI(version);
|
||||
|
||||
bool willExport[32];
|
||||
bool isSecond[32];
|
||||
int streamIDs[32];
|
||||
bool willExport[DIV_MAX_CHIPS];
|
||||
bool isSecond[DIV_MAX_CHIPS];
|
||||
int streamIDs[DIV_MAX_CHIPS];
|
||||
double loopTimer[DIV_MAX_CHANS];
|
||||
double loopFreq[DIV_MAX_CHANS];
|
||||
int loopSample[DIV_MAX_CHANS];
|
||||
bool sampleDir[DIV_MAX_CHANS];
|
||||
std::vector<unsigned int> chipVol;
|
||||
std::vector<DivDelayedWrite> delayedWrites[32];
|
||||
std::vector<DivDelayedWrite> delayedWrites[DIV_MAX_CHIPS];
|
||||
std::vector<std::pair<int,DivDelayedWrite>> sortedWrites;
|
||||
|
||||
for (int i=0; i<DIV_MAX_CHANS; i++) {
|
||||
|
|
|
|||
|
|
@ -58,11 +58,21 @@ DivDataErrors DivWavetable::readWaveData(SafeReader& reader, short version) {
|
|||
min=reader.readI();
|
||||
max=reader.readI();
|
||||
|
||||
if (len>256 || min!=0 || max>255) {
|
||||
logV("invalid len/min/max: %d %d %d",len,min,max);
|
||||
if (len>256) {
|
||||
logE("invalid len: %d",len);
|
||||
return DIV_DATA_INVALID_DATA;
|
||||
}
|
||||
|
||||
if (min!=0) {
|
||||
logW("invalid min %d",min);
|
||||
min=0;
|
||||
}
|
||||
|
||||
if (max>255) {
|
||||
logW("invalid max %d",max);
|
||||
max=255;
|
||||
}
|
||||
|
||||
for (int i=0; i<len; i++) {
|
||||
data[i]=reader.readI();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue