-- Adaptive Predictive PCM
-- L. Stewart, last updated: August 28, 1979 8:51 PM
DIRECTORY
AdpcmDefs: FROM "AdpcmDefs",
AdpcmPrivateDefs: FROM "AdpcmPrivateDefs",
Mopcodes: FROM "Mopcodes" USING [zJRAM, zLIW];
Adpcm: PROGRAM
EXPORTS AdpcmDefs, AdpcmPrivateDefs =
BEGIN OPEN AdpcmDefs, AdpcmPrivateDefs;
mMode: CARDINAL ← 14;
qTabs: QuantizerTable;
bTabs: BreakpointTable;
pTab: PredictorTable;
uLocEnCode: CARDINAL = 560B;
uLocDeCode: CARDINAL = 561B;
BrkAry: BreakpointTable = [ 0, 1, 2, 3, 4, 6, 9, 13, 19, 27, 40, 55, 78, 108, 0, 0, 0, 0, 0, 0];
LevHiAry: ARRAY [0..NModes) OF QVal = [ 1, 2, 3, 4, 6, 8, 12, 18, 26, 36, 54, 74, 104, 145, 0, 0, 0, 0, 0, 0];
LevLoAry: ARRAY [0..NModes) OF QVal = [ 0, 1, 1, 2, 3, 4, 6, 9, 13, 18, 27, 37, 52, 73, 0, 0, 0, 0, 0, 0];
InitialAdpcmState: AdpcmState = AdpcmState[0, 0, 0, 0, 0];
InitAdpcm: PUBLIC PROCEDURE =
BEGIN
i: INTEGER;
-- fill in tables
FOR i IN [0..NModes) DO
bTabs[i] ← BrkAry[i];
qTabs[i] ← [LevLoAry[i], LevHiAry[i]];
ENDLOOP;
FOR i IN Ex200 DO
pTab[i] ← ((i*85)/100); -- second guess of good value
ENDLOOP;
END;
InitAdpcmState: PUBLIC PROCEDURE [statep: POINTER TO AdpcmState] =
BEGIN
statep↑ ← InitialAdpcmState;
END;
GetqTabs: PUBLIC PROCEDURE RETURNS [POINTER TO QuantizerTable] =
BEGIN
RETURN[@qTabs];
END;
GetbTabs: PUBLIC PROCEDURE RETURNS [POINTER TO BreakpointTable] =
BEGIN
RETURN[@bTabs];
END;
GetpTab: PUBLIC PROCEDURE RETURNS [POINTER TO PredictorTable] =
BEGIN
RETURN[@pTab];
END;
CompressBlock: PUBLIC PROCEDURE [pcmData: PcmHandle, cData: AdpcmHandle, count: INTEGER, initialState: AdpcmState] RETURNS [AdpcmState] =
BEGIN
pcmP: POINTER ← BASE[pcmData];
cP: POINTER ← BASE[cData];
privQC: QControl ←
[
BTabs: @bTabs,
QTabs: @qTabs,
PTab: @pTab,
state: initialState
];
WHILE count>=0 DO
[pcmP, cP, count] ← EnCode[pcmP, cP, count, @privQC];
ENDLOOP;
RETURN[privQC.state];
END;
EnCode: PROCEDURE [iPCMp: POINTER, iCp: POINTER, icount: INTEGER, iState: POINTER TO QControl] RETURNS [fPCMp: POINTER, fCp: POINTER, fcount: INTEGER] =
MACHINE CODE BEGIN
Mopcodes.zLIW, uLocEnCode/256, uLocEnCode MOD 256;
Mopcodes.zJRAM;
END;
DeCompressBlock: PUBLIC PROCEDURE [pcmData: PcmHandle, cData: AdpcmHandle, count: INTEGER, initialState: AdpcmState] RETURNS [AdpcmState] =
BEGIN
pcmP: POINTER ← BASE[pcmData];
cP: POINTER ← BASE[cData];
privQC: QControl ←
[
BTabs: @bTabs,
QTabs: @qTabs,
PTab: @pTab,
state: initialState
];
WHILE count>=0 DO
[pcmP, cP, count] ← DeCode[pcmP, cP, count, @privQC];
ENDLOOP;
RETURN[privQC.state];
END;
DeCode: PROCEDURE [iPCMp: POINTER, iCp: POINTER, icount: INTEGER, iState: POINTER TO QControl] RETURNS [fPCMp: POINTER, fCp: POINTER, fcount: INTEGER] =
MACHINE CODE BEGIN
Mopcodes.zLIW, uLocDeCode/256, uLocDeCode MOD 256;
Mopcodes.zJRAM;
END;
-- Main Line Code
InitAdpcm[];
END.