mirror of
https://github.com/jwetzell/bmip10-js.git
synced 2026-09-09 22:39:26 +00:00
encode/decode take 1 sample at a time now
This commit is contained in:
@@ -71,22 +71,11 @@ class Encoder {
|
|||||||
this.table = this.config.default_table;
|
this.table = this.config.default_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
encode(samples) {
|
encode(sample) {
|
||||||
const codeout = [];
|
const code_word = EncodeSample(this.config, this.table, sample);
|
||||||
for (let index = 0; index < samples.length; index++) {
|
const decoded = DecodeSample(this.config, this.table, code_word);
|
||||||
const sample = samples[index];
|
this.table = NextTable(this.config, decoded);
|
||||||
|
return code_word;
|
||||||
const code_word = EncodeSample(this.config, this.table, sample);
|
|
||||||
const decoded = DecodeSample(this.config, this.table, code_word);
|
|
||||||
this.table = NextTable(this.config, decoded);
|
|
||||||
// console.log(
|
|
||||||
// `Used table ${table_old} to encode sample ${sample} to codeword ${code_word}. Decoder will decode ${decoded} so ${
|
|
||||||
// table === table_old ? "sticking with" : "changing to"
|
|
||||||
// } table ${table}`
|
|
||||||
// );
|
|
||||||
codeout.push(code_word);
|
|
||||||
}
|
|
||||||
return codeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
@@ -100,24 +89,10 @@ class Decoder {
|
|||||||
this.table = this.config.default_table;
|
this.table = this.config.default_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
decode(samples) {
|
decode(code_word) {
|
||||||
const sampout = [];
|
const decoded = DecodeSample(this.config, this.table, code_word);
|
||||||
|
this.table = NextTable(this.config, decoded);
|
||||||
for (let index = 0; index < samples.length; index++) {
|
return decoded;
|
||||||
const code_word = samples[index];
|
|
||||||
const decoded = DecodeSample(this.config, this.table, code_word);
|
|
||||||
this.table = NextTable(this.config, decoded);
|
|
||||||
this.table_old = this.table;
|
|
||||||
console.log(
|
|
||||||
`Used table ${
|
|
||||||
this.table_old
|
|
||||||
} to decode codeword ${code_word} to sample ${decoded} so ${
|
|
||||||
this.table === this.table_old ? "sticking with" : "changing to"
|
|
||||||
} table ${this.table}`
|
|
||||||
);
|
|
||||||
sampout.push(decoded);
|
|
||||||
}
|
|
||||||
return sampout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
|
|||||||
Reference in New Issue
Block a user