Skip to content

Commit

Permalink
added pcma decode and encode buffer len checker
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm committed Nov 25, 2024
1 parent 707d96e commit 698b13c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/media_codecs/src/pcma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ impl Default for PcmaDecoder {

impl AudioDecoder for PcmaDecoder {
fn decode(&mut self, in_buf: &[u8], out_buf: &mut [i16]) -> Option<usize> {
if in_buf.len() != 160 {
return None;
}
decode_pcma(in_buf, &mut self.tmp_buf[0..in_buf.len()]);
// upsample to 48k
self.resample.resample(&self.tmp_buf[..in_buf.len()], out_buf)
Expand All @@ -38,6 +41,9 @@ impl Default for PcmaEncoder {

impl AudioEncodder for PcmaEncoder {
fn encode(&mut self, in_buf: &[i16], out_buf: &mut [u8]) -> Option<usize> {
if in_buf.len() != 960 {
return None;
}
// downsample to 8k
let out_samples = self.resample.resample(in_buf, &mut self.tmp_buf)?;
encode_pcma(&self.tmp_buf[..out_samples], &mut out_buf[..out_samples]);
Expand Down

0 comments on commit 698b13c

Please sign in to comment.