program CreateTwiddleTables; { The format of the twiddle factor tables ('TWID' resources') generated by this program: } { A sequence of long words, the hi word is COS, the lo word is SIN. There are two tables } { generated, one scaled by 2^15, the other scaled by 2^16. Both are maxN entries in length } { allowing Fourier/Hartley transforms 4*maxN in length } const maxN = 1024; maxNless1 = 1023; type lArr = array[0..0] of longint; lArrPtr = ^lArr; var cs15H, cs16H: handle; cs15P, cs16P: lArrPtr; i, j: integer; resFileRef: integer; procedure fillTable (cs15, cs16: lArrPtr); const TwoPi = 6.283185307179586; TwoHi15 = 32768; TwoHi16 = 65536; var TwoPiOverN: extended; i, ci, si: integer; tempL: longInt; begin TwoPiOverN := TwoPi / (maxN * 4); for i := 0 to maxNless1 do begin ci := round(TwoHi15 * cos(i * TwoPiOverN)); si := round(TwoHi15 * sin(i * TwoPiOverN)); tempL := BSL(ci, 16); tempL := tempL + si; cs15^[i] := tempL; end; for i := 0 to maxNless1 do begin ci := round(TwoHi16 * cos(i * TwoPiOverN)); si := round(TwoHi16 * sin(i * TwoPiOverN)); tempL := BSL(ci, 16); tempL := tempL + si; cs16^[i] := tempL; end; end; begin cs15H := NewHandle(longint(maxN) * sizeOf(longInt)); { allocate memory } cs16H := NewHandle(longint(maxN) * sizeOf(longInt)); cs15P := lArrPtr(cs15H^); cs16P := lArrPtr(cs16H^); CreateResFile('Twiddles.rsrc'); ResFileRef := OpenResFile('Twiddles.rsrc'); fillTable(cs15P, cs16P); {¥ AddResource(cs15H, 'TWID', 128, 'CosSin Lookup * 2^15');¥} {¥ AddResource(cs16H, 'TWID', 129, 'CosSin Lookup * 2^16');¥} AddResource(cs15H, 'TWID', 129, 'CosSin Lookup * 2^15'); CloseResFile(resFileRef); end.