Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Almost) Add support for G.729 Annex B #153

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
G.729B: Tally up the return value of decode()/encode() in a variable
Once G.729B support is added, the number of audio samples decoded on
output will no longer be linearly correlated to the number of bytes fed
on input (or vice-versa for encoding).  We will therefore need to tally
up that number in a variable, which will act as a return value, as well
as an index for the destination buffer.
  • Loading branch information
fbriere committed Feb 13, 2022
commit ef40c6d3b1755dbdac8d8313e85058a644908506
9 changes: 6 additions & 3 deletions src/audio/audio_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,19 @@ uint16 t_g729a_audio_decoder::decode(uint8 *payload, uint16 payload_size,
assert((payload_size % 10) == 0);
assert(pcm_buf_size >= payload_size*8);

uint16 result_size = 0;

for (uint16 done = 0; done < payload_size; done += 10)
{
#ifdef HAVE_BCG729_ANNEX_B
bcg729Decoder(_context, &payload[done], 0, false, false, false, &pcm_buf[done * 8]);
bcg729Decoder(_context, &payload[done], 0, false, false, false, &pcm_buf[result_size]);
#else
bcg729Decoder(_context, &payload[done], false, &pcm_buf[done * 8]);
bcg729Decoder(_context, &payload[done], false, &pcm_buf[result_size]);
#endif
result_size += 80;
}

return payload_size * 8;
return result_size;
}

bool t_g729a_audio_decoder::valid_payload_size(uint16 payload_size, uint16 sample_buf_size) const
Expand Down
9 changes: 6 additions & 3 deletions src/audio/audio_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,21 @@ uint16 t_g729a_audio_encoder::encode(int16 *sample_buf, uint16 nsamples,

silence = false;

uint16 result_size = 0;

for (uint16 done = 0; done < nsamples; done += 80)
{
#ifdef HAVE_BCG729_ANNEX_B
uint8 frame_size = 10;
bcg729Encoder(_context, &sample_buf[done], &payload[done / 8], &frame_size);
bcg729Encoder(_context, &sample_buf[done], &payload[result_size], &frame_size);
assert(frame_size == 10);
#else
bcg729Encoder(_context, &sample_buf[done], &payload[done / 8]);
bcg729Encoder(_context, &sample_buf[done], &payload[result_size]);
#endif
result_size += 10;
}

return nsamples / 8;
return result_size;
}

#endif