[1e781ba] | 1 | import struct
|
---|
| 2 | import numpy
|
---|
| 3 |
|
---|
| 4 | class AmmosAudioDemodType():
|
---|
| 5 |
|
---|
| 6 | @classmethod
|
---|
| 7 | @property
|
---|
| 8 | def mapping(cls):
|
---|
| 9 | return {0: 'FM', 1: 'AM', 5: 'ISB', 6: 'CW',
|
---|
| 10 | 7: 'USB', 8: 'LSB', 256: 'DIGITAL',
|
---|
| 11 | 0xFFFFFFFF: 'UNKNOWN'}
|
---|
| 12 |
|
---|
| 13 | def __init__(self, demod_type):
|
---|
| 14 | self.demod_type = demod_type
|
---|
| 15 |
|
---|
| 16 | def __str__(self):
|
---|
| 17 | return AmmosAudioDemodType.mapping[self.demod_type]
|
---|
| 18 |
|
---|
| 19 | class AmmosAudioDataHeader():
|
---|
| 20 |
|
---|
| 21 | @classmethod
|
---|
| 22 | def from_bytes(cls, bytes):
|
---|
| 23 | elements = struct.unpack('<IIQIIIII', bytes)
|
---|
| 24 | sample_rate = elements[0]
|
---|
| 25 | status = elements[1]
|
---|
| 26 | frequency = elements[2]
|
---|
| 27 | demod_bandwidth = elements[3]
|
---|
| 28 | demod_type = elements[4]
|
---|
| 29 | sample_count = elements[5]
|
---|
| 30 | channel_count = elements[6]
|
---|
| 31 | sample_size = elements[7]
|
---|
| 32 | return AmmosAudioDataHeader(sample_rate, status, frequency, demod_bandwidth, demod_type,
|
---|
| 33 | sample_count, channel_count, sample_size)
|
---|
| 34 |
|
---|
| 35 | def __init__(self, sample_rate, status, frequency, demod_bandwidth, demod_type, sample_count, channel_count, sample_size):
|
---|
| 36 | self.sample_rate = sample_rate
|
---|
| 37 | self.status = status
|
---|
| 38 | self.frequency = frequency
|
---|
| 39 | self.demod_bandwidth = demod_bandwidth
|
---|
| 40 | self.demod_type = AmmosAudioDemodType(demod_type)
|
---|
| 41 | self.sample_count = sample_count
|
---|
| 42 | self.channel_count = channel_count
|
---|
| 43 | self.sample_size = sample_size
|
---|
| 44 |
|
---|
| 45 | def __str__(self):
|
---|
| 46 | return ("\nAmmosAudioDataHeader\n" +
|
---|
| 47 | "Sample rate:" + str(self.sample_rate) + "\n" +
|
---|
| 48 | "Status:" + str(self.status) + "\n" +
|
---|
| 49 | "Frequency:" + str(self.frequency) + "\n" +
|
---|
| 50 | "Demodulation bandwidth:" + str(self.demod_bandwidth) + "\n" +
|
---|
| 51 | "Demodulation type:" + str(self.demod_type) + "\n" +
|
---|
| 52 | "Sample count:" + str(self.sample_count) + "\n" +
|
---|
| 53 | "Channel count:" + str(self.channel_count) + "\n" +
|
---|
| 54 | "Sample size:" + str(self.sample_size) + "\n")
|
---|