|
From: Jerome F. <kin...@us...> - 2009-07-26 21:02:09
|
Update of /cvsroot/munt/mt32emu/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv6669/src Modified Files: partial.cpp partial.h Log Message: - Unified ring modulation calculation for ring-modulation-only and ring-modulation-and-master mix types. Index: partial.h =================================================================== RCS file: /cvsroot/munt/mt32emu/src/partial.h,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** partial.h 24 May 2009 14:09:58 -0000 1.28 --- partial.h 26 Jul 2009 21:01:53 -0000 1.29 *************** *** 89,92 **** --- 89,93 ---- Bit32s pastDesOsc; + Bit32s calcRingMod(Bit16s sample1, Bit16s sample2); Bit16s *mixBuffers(Bit16s *buf1, Bit16s *buf2, int len); Bit16s *mixBuffersRingMix(Bit16s *buf1, Bit16s *buf2, int len); Index: partial.cpp =================================================================== RCS file: /cvsroot/munt/mt32emu/src/partial.cpp,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** partial.cpp 28 May 2009 23:21:37 -0000 1.68 --- partial.cpp 26 Jul 2009 21:01:53 -0000 1.69 *************** *** 321,324 **** --- 321,349 ---- } + Bit32s Partial::calcRingMod(Bit16s sample1, Bit16s sample2) { + static const Bit32s CUTOFF = 2048; + Bit32s a[3], b[3], c[2], d[2]; + a[0] = (Bit32s)sample1; + b[0] = (Bit32s)sample2; + + a[1] = pastCarrier + ((CUTOFF * (a[0] - pastCarrier)) >> 12); + a[2] = a[1] + ((CUTOFF * (0 - a[1])) >> 12); + pastCarrier = a[2]; + + b[1] = pastOsc + ((CUTOFF * (b[0] - pastOsc)) >> 12); + b[2] = b[1] + ((CUTOFF * (0 - b[1])) >> 12); + pastOsc = b[2]; + + c[0] = a[1] ^ b[1]; + c[1] = a[2] * b[2]; + + d[0] = pastDesCarrier + ((CUTOFF * (c[0] - pastDesCarrier)) >> 12); + d[1] = d[0] + ((CUTOFF * (c[1] - d[0])) >> 12); + + pastDesCarrier = d[1]; + + return d[0] >> 5; + } + Bit16s *Partial::mixBuffers(Bit16s * buf1, Bit16s *buf2, int len) { if (buf1 == NULL) *************** *** 335,339 **** } ! Bit16s *Partial::mixBuffersRingMix(Bit16s * buf1, Bit16s *buf2, int len) { if (buf1 == NULL) return NULL; --- 360,364 ---- } ! Bit16s *Partial::mixBuffersRingMix(Bit16s *buf1, Bit16s *buf2, int len) { if (buf1 == NULL) return NULL; *************** *** 351,381 **** Bit16s *outBuf = buf1; - #define CUTOFF 2048 while (len--) { ! int a[3], b[3], c[2], d[2], result; ! a[0] = ((Bit32s)*buf1); ! b[0] = ((Bit32s)*buf2); ! ! a[1] = pastCarrier + ((CUTOFF * (a[0] - pastCarrier)) >> 12); ! a[2] = a[1] + ((CUTOFF * (0 - a[1])) >> 12); ! pastCarrier = a[2]; ! ! b[1] = pastOsc + ((CUTOFF * (b[0] - pastOsc)) >> 12); ! b[2] = b[1] + ((CUTOFF * (0 - b[1])) >> 12); ! pastOsc = b[2]; ! ! c[0] = a[1] ^ b[1]; ! c[1] = (a[2] * b[2]); ! ! d[0] = pastDesCarrier + ((CUTOFF * (c[0] - pastDesCarrier)) >> 12); ! d[1] = d[0] + ((CUTOFF * (c[1] - d[0])) >> 12); ! ! pastDesCarrier = d[1]; ! ! result = ((d[0] >> 5) + a[0]); ! if (result>32767) result = 32767; ! if (result<-32768) result = -32768; *buf1 = (Bit16s)(result); --- 376,385 ---- Bit16s *outBuf = buf1; while (len--) { ! Bit32s result = calcRingMod(*buf1, *buf2) + *buf1; ! if (result > 32767) result = 32767; ! if (result < -32768) result = -32768; *buf1 = (Bit16s)(result); *************** *** 386,390 **** } ! Bit16s *Partial::mixBuffersRing(Bit16s * buf1, Bit16s *buf2, int len) { if (buf1 == NULL) { return NULL; --- 390,394 ---- } ! Bit16s *Partial::mixBuffersRing(Bit16s *buf1, Bit16s *buf2, int len) { if (buf1 == NULL) { return NULL; *************** *** 396,427 **** Bit16s *outBuf = buf1; while (len--) { ! int a[3], b[3], c[2], d[2], result; ! ! a[0] = ((Bit32s)*buf1); ! b[0] = ((Bit32s)*buf2); ! ! ! a[1] = pastCarrier + ((CUTOFF * (a[0] - pastCarrier)) >> 12); ! a[2] = a[1] + ((CUTOFF * (0 - a[1])) >> 12); ! pastCarrier = a[2]; ! ! ! b[1] = pastOsc + ((CUTOFF * (b[0] - pastOsc)) >> 12); ! b[2] = b[1] + ((CUTOFF * (0 - b[1])) >> 12); ! pastOsc = b[2]; ! ! c[0] = a[1] ^ b[1]; ! c[1] = (a[2] * b[2]); ! ! d[0] = pastDesCarrier + ((CUTOFF * (c[0] - pastDesCarrier)) >> 12); ! d[1] = d[0] + ((CUTOFF * (c[1] - d[0])) >> 12); ! ! pastDesCarrier = d[1]; ! ! result = d[0] >> 5; ! if (result>32767) result = 32767; ! if (result<-32768) result = -32768; *buf1 = (Bit16s)(result); --- 400,408 ---- Bit16s *outBuf = buf1; while (len--) { ! Bit32s result = calcRingMod(*buf1, *buf2); ! if (result > 32767) result = 32767; ! if (result < -32768) result = -32768; *buf1 = (Bit16s)(result); |