1
0
Fork 0

Added tests for decoder init and freq detection

master
James Taylor 2019-11-03 17:27:16 +00:00
parent afdb2e1a82
commit 3bbec517d1
3 changed files with 21 additions and 1 deletions

View File

@ -38,7 +38,6 @@ class SSTVDecoder(object):
"""Create an SSTV decoder for decoding audio data"""
def __init__(self, audio_file):
self.log_basic = True
self.mode = None
self._audio_file = audio_file

Binary file not shown.

View File

@ -26,3 +26,24 @@ class SSTVDecoderTestCase(unittest.TestCase):
bins = [1, 2, 2, 2, 1]
# Centre 2 surrounded by 2s should result in no change
self.assertEqual(barycentric_peak_interp(bins, 2), 2)
def test_decoder_init(self):
with open("./test/data/m1.ogg", 'rb') as fp:
with SSTVDecoder(fp) as decoder:
self.assertEqual(decoder._audio_file, fp)
self.assertEqual(decoder._sample_rate, 44100)
def test_decoder_freq_detect(self):
with open("./test/data/220hz_sine.ogg", 'rb') as fp:
with SSTVDecoder(fp) as decoder:
# Test using all samples in sound file
freq = round(decoder._peak_fft_freq(decoder._samples))
self.assertEqual(freq, 220, "Incorrect frequency determined by peak detector using all samples")
# Test using 1/4 of a second of samples
freq = round(decoder._peak_fft_freq(decoder._samples[:11025]))
self.assertEqual(freq, 220, "Incorrect frequency determined by peak detector using 1/4 second samples")
# Test using 2000 samples
freq = round(decoder._peak_fft_freq(decoder._samples[:1000]))
self.assertEqual(freq, 220, "Incorrect frequency determined by peak detector using 1000 samples")