Skip to content

Commit 20e0549

Browse files
committed
Added MFSKMode.fromLabel() for string serialization
1 parent 5e258ae commit 20e0549

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

  • AudioCoder/src/main/java/org/operatorfoundation/audiocoder/mfsk

AudioCoder/src/main/java/org/operatorfoundation/audiocoder/mfsk/MFSKMode.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sealed class MFSKMode(
5454
/**
5555
* MFSK-16: 16 tones, 15.625 baud, 250 Hz bandwidth.
5656
* The most common MFSK mode. Same baud rate as [MFSK8] but carries 4 bits per symbol
57-
* instead of 3. Primary target mode for Nahoft.
57+
* instead of 3.
5858
*/
5959
object MFSK16 : MFSKMode(
6060
toneCount = 16,
@@ -164,4 +164,27 @@ sealed class MFSKMode(
164164
// -------------------------------------------------------------------------
165165

166166
override fun toString(): String = label
167+
168+
// -------------------------------------------------------------------------
169+
// Serialization helpers
170+
// -------------------------------------------------------------------------
171+
172+
companion object
173+
{
174+
/**
175+
* Returns the [MFSKMode] corresponding to [label], or null if no match.
176+
*
177+
* [label] must match the format produced by [MFSKMode.label] — e.g. `"MFSK-16"`.
178+
* Use this to reconstruct a mode from an Intent extra or other string representation.
179+
*/
180+
fun fromLabel(label: String): MFSKMode? = when (label)
181+
{
182+
MFSK8.label -> MFSK8
183+
MFSK16.label -> MFSK16
184+
MFSK32.label -> MFSK32
185+
MFSK64.label -> MFSK64
186+
MFSK128.label -> MFSK128
187+
else -> null
188+
}
189+
}
167190
}

0 commit comments

Comments
 (0)