summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c2enc/src/main.rs3
-rw-r--r--libcodec2/src/lib.rs16
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 _);