From ac2f09d2191d21f83653369dfa6b48eb022bacec Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Wed, 26 Jun 2024 22:04:01 -0500 Subject: [PATCH] encode/decode take 1 sample at a time now --- index.js | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index 945eccc..e192d80 100644 --- a/index.js +++ b/index.js @@ -71,22 +71,11 @@ class Encoder { this.table = this.config.default_table; } - encode(samples) { - const codeout = []; - for (let index = 0; index < samples.length; index++) { - const sample = samples[index]; - - 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; + encode(sample) { + const code_word = EncodeSample(this.config, this.table, sample); + const decoded = DecodeSample(this.config, this.table, code_word); + this.table = NextTable(this.config, decoded); + return code_word; } reset() { @@ -100,24 +89,10 @@ class Decoder { this.table = this.config.default_table; } - decode(samples) { - const sampout = []; - - for (let index = 0; index < samples.length; index++) { - 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; + decode(code_word) { + const decoded = DecodeSample(this.config, this.table, code_word); + this.table = NextTable(this.config, decoded); + return decoded; } reset() {