DIRECTORY Commander, FS, IO, Real, RealFns, Rope, U255; LarkSineTableImpl: PROGRAM IMPORTS Commander, FS, IO, Real, RealFns, U255 = { OPEN U255; Main: Commander.CommandProc = TRUSTED { ENABLE ABORTED => GOTO Quit; out: IO.STREAM; name: Rope.ROPE; label: Rope.ROPE; res: BOOL; l: NAT; loss: REAL; out _ cmd.out; out.PutF["\nLarkSineTables running at %t\n", IO.time[]]; FOR i: NAT IN [0..7] DO l _ i*3; loss _ l; loss _ loss - 3.16; -- codec clipping level is at 3.16 dB name _ IO.PutFR["SineTable%02d.dsm", IO.int[l]]; label _ IO.PutFR["STab%02d", IO.int[l]]; out.PutF["Writing %g ... ", IO.rope[name]]; res _ WriteDSMFile[label: label, name: name, data: MakeSineTable[dBToLoss[l]]]; out.PutF[IF res THEN "OK.\n" ELSE "Failed!\n"]; ENDLOOP; out.PutF["\nLarkSineTables finished at %t\n", IO.time[]]; out.Flush[]; EXITS Quit => NULL; }; Pi: REAL = 3.1415926535; TwoPi: REAL = 2.0 * Pi; MakeSineTable: PROC [loss: REAL] RETURNS [t: REF BTab] = { int: INTEGER; x: REAL; t _ NEW[BTab[256]]; FOR i: CARDINAL IN [0..256) DO x _ i; x _ x/256.0; -- fraction of circle x _ x * TwoPi; -- phase in radians x _ RealFns.Sin[x]; -- IN [-1..1] x _ x*loss; -- attenuate x _ x*32767; -- scale to left justified two's complement int _ Real.FixI[x]; -- Fix t[i] _ U255.Encode[int]; ENDLOOP; }; WriteDSMFile: PROC [label: Rope.ROPE, name: Rope.ROPE, data: REF BTab] RETURNS [BOOL] = { f: IO.STREAM; IF data.length MOD 2 # 0 THEN GOTO Fail; f _ FS.StreamOpen[fileName: name, accessOptions: $create ! FS.Error => TRUSTED {GOTO Fail}]; f.PutF["; %g\n; L. Stewart %t\n\n", IO.rope[name], IO.time[]]; f.PutF["\nC_CODE SEGMENT\n\n"]; f.PutF["_%g\tLABEL\tNEAR\n", IO.rope[label]]; FOR i: CARDINAL IN [0..data.length/2) DO f.PutF["\tDW\t0%02x%02xH\n", IO.card[data[i+i+1]], IO.card[data[i+i]]]; ENDLOOP; f.PutF["\n\nPUBLIC _%g\n\nC_CODE ENDS\n\tEND\n", IO.rope[label]]; f.Close[]; RETURN [TRUE]; EXITS Fail => RETURN [FALSE]; }; dBToLoss: PROC [dBloss: REAL] RETURNS [loss:REAL] = { RETURN [RealFns.Power[base: 10.0, exponent: -dBloss/20.0]]; }; Init: PROC = { Commander.Register["LarkSineTables", Main, "Make Lark Sinewave tables"]; }; Init[]; }. ÂLarkSineTableImpl.mesa Last modified: Stewart, December 22, 1983 3:11 pm Constructs a 256 x 8 bit table Address = phase fraction [0..255] Value = u-255 value = sine(phase) attenuated by loss Main program Stewart, October 27, 1982 11:05 pm Stewart, March 18, 1983 8:26 pm, Cedar 3.5 Stewart, June 6, 1983 12:36 pm, more sine tables Stewart, September 29, 1983 9:52 pm, added 3.16 dB correction! Stewart, December 22, 1983 3:11 pm, Cedar 5 ʧ˜Jšœ™Jšœ™Jšœ#™#J˜šÏk ˜ J˜ Jšœ˜Jšœ˜J˜J˜J˜J˜J˜—Jš œœœ œœ˜MJšœ˜ J˜šœœ˜'Jšœœœ˜J˜Jšœœœ˜Jšœ œ˜Jšœ œ˜Jšœœ˜ Jšœœ˜Jšœœ˜ J˜J˜Jšœ-œ ˜8J˜šœœœ˜J˜J˜ JšœÏc%˜9Jšœœœ ˜0Jšœœœ ˜(Jšœœ ˜+J˜OJšœ œœ œ˜/Jšœ˜J˜—Jšœ.œ ˜9J˜ Jš˜Jšœœ˜ J˜J˜—Jšœœ˜Jšœœ ˜J˜Jšœ™Jšœ!™!Jšœ4™4š Ïn œœœœœ ˜:Jšœœ˜ Jšœœ˜Jšœœ ˜šœœœ ˜J˜Jšœž˜$Jšœž˜#Jšœž ˜"Jšœ ž ˜Jšœž+˜9Jšœž˜J˜Jšœ˜—J˜J˜—šŸ œœœ œœœœ˜YJšœœœ˜ Jšœ œœœ˜(š œœ5œ œœ˜\Jšœ$œ œ ˜>J˜!—šœœ˜-šœœœ˜(Jšœœœ˜GJšœ˜—Jšœ2œ˜B—J˜ Jšœœ˜Jš˜Jšœœœ˜J˜J˜—š œ œ œœœ˜5Jšœ5˜;J˜J˜—šŸœœP˜ZJ˜—Jšœ ™ J˜J˜J˜Jšœ#™#Jšœ+™+Jšœ1™1Jšœ?™?šœ,™,J˜——…—` É