File tree Expand file tree Collapse file tree
AudioCoder/src/main/java/org/operatorfoundation/audiocoder/mfsk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ object MFSKEncoder
146146 toneIndex = (toneIndex shl 1 ) or (if (bit) 1 else 0 )
147147 }
148148
149- symbols[symbolIndex] = toneIndex
149+ symbols[symbolIndex] = toneIndex xor (toneIndex shr 1 )
150150 }
151151
152152 return symbols
Original file line number Diff line number Diff line change @@ -189,8 +189,10 @@ class MFSKStation(
189189 val energies = DoubleArray (configuration.mode.toneCount) { i ->
190190 GoertzelFilter .energy(samples, toneFrequencies[i], configuration.sampleRate)
191191 }
192+
192193 // maxByOrNull is safe, toneCount is always >= 8 by MFSKMode's design.
193- val winnerToneIndex = energies.indices.maxByOrNull { energies[it] }!!
194+ val rawToneIndex = energies.indices.maxByOrNull { energies[it] }!!
195+ val winnerToneIndex = grayDecode(rawToneIndex)
194196
195197 // Extract bitsPerSymbol bits from the winner, MSB-first,
196198 // and feed each into the Varicode decoder.
@@ -303,4 +305,17 @@ class MFSKStation(
303305
304306 return buffer
305307 }
308+
309+ private fun grayDecode (gray : Int ): Int
310+ {
311+ var n = gray
312+ var mask = n shr 1
313+
314+ while (mask != 0 ) {
315+ n = n xor mask
316+ mask = mask shr 1
317+ }
318+
319+ return n
320+ }
306321}
You can’t perform that action at this time.
0 commit comments