summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c2enc/src/main.rs14
-rw-r--r--libcodec2/src/lib.rs10
2 files changed, 20 insertions, 4 deletions
diff --git a/c2enc/src/main.rs b/c2enc/src/main.rs
index df3891e..eb097bd 100644
--- a/c2enc/src/main.rs
+++ b/c2enc/src/main.rs
@@ -19,9 +19,17 @@ fn main() {
speech.push(i);
}
- let mut bits = Vec::new();
+ let mut allbits = Vec::new();
let c = libcodec2::Codec2::new();
- c.encode(&speech, &mut bits);
+ let nsam = c.samples_per_frame();
+ let nbits = c.bytes_per_frame();
+
+ for speech in speech.chunks(nsam) {
+ let mut bits = Vec::new();
+ bits.reserve(nbits);
+ c.encode(&speech, &mut bits);
+ allbits.push(bits);
+ }
- println!("{:?}", bits);
+ println!("{:?}", allbits);
}
diff --git a/libcodec2/src/lib.rs b/libcodec2/src/lib.rs
index 04c2717..5ce7850 100644
--- a/libcodec2/src/lib.rs
+++ b/libcodec2/src/lib.rs
@@ -20,8 +20,16 @@ impl Codec2 {
unsafe { ffi::codec2_destroy(self.0) }
}
+ pub fn samples_per_frame(&self) -> usize {
+ unsafe { ffi::codec2_samples_per_frame(self.0).try_into().unwrap() }
+ }
+
+ pub fn bytes_per_frame(&self) -> usize {
+ unsafe { ffi::codec2_bytes_per_frame(self.0).try_into().unwrap() }
+ }
+
/// Encode an array of speech samples into an array of bits
- pub fn encode(self, speech: &[i16], bits: &mut [u8]) {
+ pub fn encode(&self, speech: &[i16], bits: &mut [u8]) {
unsafe {
ffi::codec2_encode(self.0, bits.as_ptr() as *mut _, speech.as_ptr() as *mut _);
}