mirror of
https://github.com/opentx/opentx.git
synced 2025-07-22 15:55:26 +03:00
PEP8 radio/util/codecs.py
Fix white space
This commit is contained in:
parent
054952edcb
commit
be154140b3
1 changed files with 20 additions and 15 deletions
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
SIGN_BIT = (0x80) # Sign bit for a A-law byte.
|
SIGN_BIT = (0x80) # Sign bit for a A-law byte.
|
||||||
QUANT_MASK = (0xf) # Quantization field mask.
|
QUANT_MASK = (0xf) # Quantization field mask.
|
||||||
SEG_SHIFT = (4) # Left shift for segment number.
|
SEG_SHIFT = (4) # Left shift for segment number.
|
||||||
SEG_MASK = (0x70) # Segment field mask.
|
SEG_MASK = (0x70) # Segment field mask.
|
||||||
BIAS = (0x84) # Bias for linear code.
|
BIAS = (0x84) # Bias for linear code.
|
||||||
|
|
||||||
|
|
||||||
def alaw2linear(a_val):
|
def alaw2linear(a_val):
|
||||||
a_val ^= 0x55
|
a_val ^= 0x55
|
||||||
|
@ -16,13 +17,14 @@ def alaw2linear(a_val):
|
||||||
if (seg):
|
if (seg):
|
||||||
t = (t + t + 1 + 32) << (seg + 2)
|
t = (t + t + 1 + 32) << (seg + 2)
|
||||||
else:
|
else:
|
||||||
t = (t + t + 1 ) << 3
|
t = (t + t + 1) << 3
|
||||||
|
|
||||||
if a_val & SIGN_BIT:
|
if a_val & SIGN_BIT:
|
||||||
return t
|
return t
|
||||||
else:
|
else:
|
||||||
return -t
|
return -t
|
||||||
|
|
||||||
|
|
||||||
def ulaw2linear(u_val):
|
def ulaw2linear(u_val):
|
||||||
# Complement to obtain normal u-law value.
|
# Complement to obtain normal u-law value.
|
||||||
u_val = ~u_val
|
u_val = ~u_val
|
||||||
|
@ -37,17 +39,20 @@ def ulaw2linear(u_val):
|
||||||
else:
|
else:
|
||||||
return (t - BIAS)
|
return (t - BIAS)
|
||||||
|
|
||||||
|
|
||||||
def pcmTable(fn):
|
def pcmTable(fn):
|
||||||
result = []
|
result = []
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
result.append(fn(i))
|
result.append(fn(i))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def tableToString(name, table):
|
def tableToString(name, table):
|
||||||
result = 'const int16_t ' + name + '[256] = { '
|
result = 'const int16_t ' + name + '[256] = { '
|
||||||
result += ', '.join([str(i) for i in table])
|
result += ', '.join(str(i) for i in table)
|
||||||
result += ' };'
|
result += ' };'
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
print(tableToString('alawTable', pcmTable(alaw2linear)))
|
print(tableToString('alawTable', pcmTable(alaw2linear)))
|
||||||
print(tableToString('ulawTable', pcmTable(ulaw2linear)))
|
print(tableToString('ulawTable', pcmTable(ulaw2linear)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue