diff options
| author | Yuval Adam <_@yuv.al> | 2022-07-27 09:20:45 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2022-07-27 09:21:07 +0300 |
| commit | bb2356dae10db7a9d1e0a1171c81ddb5b6284d96 (patch) | |
| tree | 964ea620877bc54be355e2ac6f791b1f8e3689ef | |
| parent | 9d749ec3e82bfad1964ed0bf4f0e31d1b93b30fe (diff) | |
Fix remainder frame bug, drop it to match c2enc behavior
| -rw-r--r-- | c2enc/src/main.rs | 3 | ||||
| -rw-r--r-- | libcodec2/src/lib.rs | 16 |
2 files changed, 14 insertions, 5 deletions
diff --git a/c2enc/src/main.rs b/c2enc/src/main.rs index adbd787..9df5b6a 100644 --- a/c2enc/src/main.rs +++ b/c2enc/src/main.rs @@ -38,7 +38,8 @@ fn main() { let mut file = File::create(&args.out_path).unwrap(); - for samples in speech.chunks(nsam) { + for samples in speech.chunks_exact(nsam) { + // remainder frame will be dropped let mut bits = vec![0u8; nbits]; c.encode(&samples, &mut bits); file.write(&bits).unwrap(); diff --git a/libcodec2/src/lib.rs b/libcodec2/src/lib.rs index 9becb47..b909078 100644 --- a/libcodec2/src/lib.rs +++ b/libcodec2/src/lib.rs @@ -32,11 +32,19 @@ impl Codec2 { pub fn encode(&self, speech: &[i16], bits: &mut [u8]) { let nsamples = self.samples_per_frame(); let nbits = self.bytes_per_frame(); - if bits.len() != nsamples { - panic!("Samples buffer must be of length {}", nsamples); + if speech.len() != nsamples { + panic!( + "Samples buffer must be of length {}, got {}", + nsamples, + speech.len() + ); } - if speech.len() != nbits { - panic!("Speech buffer must be of length {}", nsamples); + if bits.len() != nbits { + panic!( + "Bits buffer must be of length {}, got {}", + nbits, + bits.len() + ); } unsafe { ffi::codec2_encode(self.0, bits.as_ptr() as *mut _, speech.as_ptr() as *mut _); |
