Output some silence before signal (useful because some audio cards does output garbage at start of playback)

This commit is contained in:
Daniele Verducci 2025-02-14 10:21:50 +01:00
parent 69a2ba4c47
commit c3c55097ba
2 changed files with 16 additions and 2 deletions

View File

@ -34,7 +34,8 @@ DESCRIPTION = 'Decodes a file using the manchester encoding'
FRAME_DELIMITER = 126 # (01111110)
FRAME_DELIMITER_EVERY_BYTES = 64
PREAMBLE_DURATION = 512
# Clock signal duration peceding effective signal
PREAMBLE_DURATION = 1280
# Values nearest to zero than this are not considered: set to more than noise, less than signal
AUDIO_MIN_VOLUME = 12288
# The 0 value: values less than this are considered 0, more than this 1. This should be
@ -63,6 +64,8 @@ class Main:
self.decodeActualData()
except ValueError as e:
self._log.error("Ran out of input data before completing initialization!")
except struct.error as e:
self._log.error("Unsupported wav format: only mono PCM is supported")
self.audioSource.close()
self.outputSink.close()

View File

@ -34,7 +34,10 @@ DESCRIPTION = 'Encodes a file using the manchester encoding and outputs it as au
FRAME_DELIMITER = 126 # (01111110)
FRAME_DELIMITER_EVERY_BYTES = 64
PREAMBLE_DURATION = 512
# Seconds of preceding silence (useful because some audio cards does output garbage at start of playback)
PRECEDING_SILENCE_SECS = 2
# Clock signal duration peceding effective signal
PREAMBLE_DURATION = 1280
AUDIO_VOLUME = 16384 # 0 to 32767
AUDIO_BITRATE = 44100
@ -58,6 +61,9 @@ class Main:
self.audioSink.setsampwidth(2)
self.audioSink.setframerate(44100.0)
# Silence
self.outputSilence()
# Preamble
self.outputPreamble()
@ -109,6 +115,11 @@ class Main:
self.encodeBit(0)
consecutiveOnes = 0
def outputSilence(self):
# A second of silence preceeding signal
for x in range(AUDIO_BITRATE * PRECEDING_SILENCE_SECS):
self.audioSink.writeframesraw(struct.pack('<h', 0))
def outputPreamble(self):
# Outputs the preable: a sequence of 64 "1" and "0" used to facilitate the receiver
# syncronizing on our clock. The sequence starts with 1 and ends with 0