Rework Python binding

This commit is contained in:
Josh Wu
2024-12-11 17:50:20 +08:00
committed by Antoine SOULIER
parent bb85f7dde4
commit 9c59375ae0
5 changed files with 363 additions and 191 deletions

View File

@@ -53,7 +53,7 @@ if header[0] != 0xcc1c:
samplerate = header[2] * 100
nchannels = header[4]
frame_duration = header[5] / 100
frame_duration = header[5] * 10
stream_length = header[7]
# --- Setup output ---
@@ -80,7 +80,7 @@ encoded_length = stream_length + dec.get_delay_samples()
for i in range(0, encoded_length, frame_length):
lc3_frame_size = struct.unpack('=H', f_lc3.read(2))[0]
pcm = dec.decode(f_lc3.read(lc3_frame_size), bitdepth=bitdepth)
pcm = dec.decode(f_lc3.read(lc3_frame_size), bit_depth=bitdepth)
pcm = pcm[max(encoded_length - stream_length - i, 0) * pcm_size:
min(encoded_length - i, frame_length) * pcm_size]

View File

@@ -57,7 +57,7 @@ stream_length = wavfile.getnframes()
# --- Setup encoder ---
enc = lc3.Encoder(
args.frame_duration, samplerate, nchannels, libpath=args.libpath)
int(args.frame_duration)*1000, samplerate, nchannels, libpath=args.libpath)
frame_size = enc.get_frame_bytes(args.bitrate)
frame_length = enc.get_frame_samples()
bitrate = enc.resolve_bitrate(frame_size)
@@ -77,7 +77,7 @@ for i in range(0, stream_length, frame_length):
f_lc3.write(struct.pack('=H', frame_size))
pcm = wavfile.readframes(frame_length)
f_lc3.write(enc.encode(pcm, frame_size, bitdepth=bitdepth))
f_lc3.write(enc.encode(pcm, frame_size, bit_depth=bitdepth))
# --- Cleanup ---