working first block

This commit is contained in:
Joppe Blondel
2026-10-04 17:10:21 +02:00
parent 5348660aa7
commit 79d427668a
3 changed files with 243 additions and 32 deletions
+8 -1
View File
@@ -20,6 +20,11 @@ class FSKWriter:
self.phase = 0.0
self.samples = bytearray()
self.samples.extend(b'\0'*int(1.0*self.sample_rate))
def finalize(self):
self.samples.extend(b'\0'*int(1.0*self.sample_rate))
def _tone(self, frequency: float, sample_count: int) -> None:
phase_step = 2.0 * math.pi * frequency / self.sample_rate
scale = int(32767 * self.amplitude)
@@ -41,7 +46,7 @@ class FSKWriter:
for _ in range(8):
self.bit(1)
self.bit(0)
self.byte(0x0f)
self.byte(0xf0)
def bit(self, value: int) -> None:
if value:
@@ -66,6 +71,7 @@ class FSKWriter:
self.byte(l&0xff)
self.bytes(data)
self.byte(self.chsum(data))
self.samples.extend(b'\0'*int(0.3*self.sample_rate))
def chsum(self, data: bytes) -> int:
cs = 0
@@ -93,6 +99,7 @@ def main() -> None:
tones.block(0, args.input.name.encode())
tones.finalize()
with wave.open(str(output_path), "wb") as wav:
wav.setnchannels(1)
wav.setsampwidth(2)