LarkSlaveTableImpl.mesa
Last modified:
Stewart, December 22, 1983 3:08 pm
DIRECTORY
Commander,
IO,
Real,
RealFns,
Rope,
U255;
LarkSlaveTableImpl: PROGRAM IMPORTS Commander, IO, Real, RealFns, U255 = {
OPEN U255;
Main: Commander.CommandProc = TRUSTED {
ENABLE ABORTED => GOTO Quit;
out: IO.STREAM;
name: Rope.ROPE;
res: BOOL;
l: NAT;
rloss: REAL;
out ← cmd.out;
out.PutF["\nLarkSlaveTables running at %t\n", IO.time[]];
Constructs a 256 x 16 table
Address = U255
Value = silence value to be added to silence register
name ← "LarkSilence.table";
out.PutF["Writing %g ... ", IO.rope[name]];
res ← WriteBitsFile[name: name, data: MakeSilenceTable[], byteSwap: TRUE];
out.PutF[IF res THEN "OK.\n" ELSE "Failed!\n"];
Constructs a 2048 x 8 table
Address = right justified (positive) 12 bit two's complement
Value = right justified u-255
name ← "LarkMuLaw.table";
out.PutF["Writing %g ... ", IO.rope[name]];
res ← WriteBitsFile[name: name, data: MakeMuLawTable[], byteSwap: TRUE];
out.PutF[IF res THEN "OK.\n" ELSE "Failed!\n"];
Constructs a 256 x 8 bit table
Address = u-255 value
Value = u-255 value attenuated by slos
FOR i: NAT IN [0..4] DO
l ← i*5;
name ← IO.PutFR["LossTable%02d.table", IO.int[l]];
out.PutF["Writing %g ... ", IO.rope[name]];
res ← WriteBitsFile[name: name, data: MakeLossTable[dBToLoss[l]], byteSwap: TRUE];
out.PutF[IF res THEN "OK.\n" ELSE "Failed!\n"];
ENDLOOP;
Constructs a 256 x 8 bit table
Address = u-255 value
Value = u-255 value attenuated by loss
FOR i: NAT IN [0..8] DO
l ← i*25;
rloss ← l;
rloss ← rloss/10;
name ← IO.PutFR["LossTable%03d.table", IO.int[l]];
out.PutF["Writing %g ... ", IO.rope[name]];
res ← WriteBitsFile[name: name, data: MakeLossTable[dBToLoss[rloss]], byteSwap: TRUE];
out.PutF[IF res THEN "OK.\n" ELSE "Failed!\n"];
ENDLOOP;
Constructs a 256 x 16 bit table
Address = u-255 value
Value = right justified 12 bit two's complement
FOR i: NAT IN [0..2] DO
l ← i*3;
name ← IO.PutFR["LarkLinear%02d.table", IO.int[l]];
out.PutF["Writing %g ... ", IO.rope[name]];
res ← WriteBitsFile[name: name, data: MakeLinearTable[dBToLoss[l]], byteSwap: TRUE];
out.PutF[IF res THEN "OK.\n" ELSE "Failed!\n"];
ENDLOOP;
out.PutF["\nLarkSlaveTables finished at %t\n", IO.time[]];
out.Flush[];
EXITS
Quit => NULL;
};
Constructs a 256 x 16 bit table
Address = u-255 value
Value = right justified 12 bit two's complement
MakeLinearTable: PROC [loss: REAL] RETURNS [t: REF WTab] = {
x: REAL;
t ← NEW[WTab[256]];
FOR i: CARDINAL IN [0..256) DO
t[i] ← U255.Decode[LOOPHOLE[i]];
x ← t[i];
x ← x*loss;
t[i] ← Real.RoundI[x];
t[i] ← IntToRJInt[t[i]];
ENDLOOP;
};
Constructs a 256 x 16 table
The table is in two halves. The lower half is absolute value, the upper is square law.
Entries [0..128):
Address = U255
Value = silence value to be added to silence register
Absolute value of mu law encoded sample
Entries [128..256):
Address = U255
Value = silence value to be added to silence register
Square law
MakeSilenceTable: PROC RETURNS [t: REF WTab] = {
wi: INTEGER;
ary: ARRAY [0..128) OF REAL;
min: REAL ← Real.LargestNumber;
max: REAL ← 0;
limit: REAL ← 408;
i: NAT;
t ← NEW[WTab[256]];
convert to linear coded REAL
FOR i IN [0..128) DO
wi ← U255.Decode[i];
wi ← ABS[wi];
ary[i] ← wi;
ary[i] ← ary[i] * ary[i]; -- square
ENDLOOP;
find maximum
FOR i IN [0..128) DO
IF ary[i] > max THEN max ← ary[i];
ENDLOOP;
scale high end
FOR i IN [0..128) DO
ary[i] ← ary[i] * (limit / max);
ENDLOOP;
round up low end
FOR i IN [0..128) DO
ary[i] ← ary[i] + 1;
ENDLOOP;
fill in result table
FOR i: CARDINAL IN [0..128) DO
t[i] ← i;
ENDLOOP;
FOR i IN [0..128) DO
t[128 + i] ← Real.FixC[ary[i]];
ENDLOOP;
};
Constructs a 256 x 8 bit table
Address = u-255 value
Value = u-255 value attenuated by loss
MakeLossTable: PROC [loss: REAL] RETURNS [t: REF BTab] = {
int: INTEGER;
x: REAL;
t ← NEW[BTab[256]];
FOR i: CARDINAL IN [0..256) DO
int ← U255.Decode[LOOPHOLE[i]];
x ← int;
x ← x*loss;
int ← Real.RoundI[x];
t[i] ← U255.Encode[int];
ENDLOOP;
};
Constructs a 2048 x 8 table
Address = right justified (positive) 12 bit two's complement
Value = right justified u-255
MakeMuLawTable: PROC RETURNS [t: REF BTab] = {
t ← NEW[BTab[2048]];
FOR i: CARDINAL IN [0..2048) DO
t[i] ← U255.Encode[Shift[i, 4]];
ENDLOOP;
};
dBToLoss: PROC [dBloss: REAL] RETURNS [loss:REAL] = {
RETURN [RealFns.Power[base: 10.0, exponent: -dBloss/20.0]];
};
Init: PROC = {Commander.Register["LarkTables", Main, "Construct tables for slave CPU"]; };
Main program
Init[];
}.
December 22, 1983 3:08 pm, Stewart, Cedar 5