Adopt review suggestions

This commit is contained in:
Josh Wu
2024-12-17 14:58:04 +08:00
committed by Antoine SOULIER
parent 9c59375ae0
commit 0b28bf28ee
3 changed files with 10 additions and 10 deletions

View File

@@ -66,7 +66,7 @@ class _Base:
if self.frame_duration_us not in [2500, 5000, 7500, 10000]:
raise InvalidArgumentError(
"Invalid frame duration: %.1f ms" % self.frame_duration_us
f"Invalid frame duration: {self.frame_duration_us} us ({self.frame_duration_us / 1000:.1f} ms)"
)
allowed_samplerate = (
@@ -74,7 +74,7 @@ class _Base:
)
if self.sample_rate_hz not in allowed_samplerate:
raise InvalidArgumentError("Invalid sample rate: %d Hz" % sample_rate_hz)
raise InvalidArgumentError(f"Invalid sample rate: {sample_rate_hz} Hz")
if libpath is None:
mesonpy_lib = glob.glob(

View File

@@ -34,8 +34,8 @@ parser.add_argument(
type=argparse.FileType('wb'), default=sys.stdout.buffer)
parser.add_argument(
'--bitdepth',
help='Output bitdepth, default is 16 bits',
'--bit_depth',
help='Output bit depth, default is 16 bits',
type=int, choices=[16, 24], default=16)
parser.add_argument(
@@ -58,13 +58,13 @@ stream_length = header[7]
# --- Setup output ---
bitdepth = args.bitdepth
pcm_size = nchannels * (bitdepth // 8)
bit_depth = args.bit_depth
pcm_size = nchannels * (bit_depth // 8)
f_wav = args.wav_file
wavfile = wave.open(f_wav)
wavfile.setnchannels(nchannels)
wavfile.setsampwidth(bitdepth // 8)
wavfile.setsampwidth(bit_depth // 8)
wavfile.setframerate(samplerate)
wavfile.setnframes(stream_length)
@@ -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), bit_depth=bitdepth)
pcm = dec.decode(f_lc3.read(lc3_frame_size), bit_depth=bit_depth)
pcm = pcm[max(encoded_length - stream_length - i, 0) * pcm_size:
min(encoded_length - i, frame_length) * pcm_size]

View File

@@ -51,7 +51,7 @@ wavfile = wave.open(f_wav, 'rb')
samplerate = wavfile.getframerate()
nchannels = wavfile.getnchannels()
bitdepth = wavfile.getsampwidth() * 8
bit_depth = wavfile.getsampwidth() * 8
stream_length = wavfile.getnframes()
# --- Setup encoder ---
@@ -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, bit_depth=bitdepth))
f_lc3.write(enc.encode(pcm, frame_size, bit_depth=bit_depth))
# --- Cleanup ---