Use byte buffer for audio to minimize buffer copy's

This commit is contained in:
Iwan Timmer
2014-01-07 20:43:14 +01:00
parent 815e56d7d8
commit 85ffdc2426
5 changed files with 43 additions and 85 deletions
+8 -5
View File
@@ -37,8 +37,8 @@ int nv_opus_get_channel_count(void) {
}
// This number assumes 2 channels at 48 KHz
int nv_opus_get_max_out_shorts(void) {
return 512*nv_opus_get_channel_count();
int nv_opus_get_max_out_bytes(void) {
return 1024*nv_opus_get_channel_count();
}
// The Opus stream is 48 KHz
@@ -46,17 +46,20 @@ int nv_opus_get_sample_rate(void) {
return 48000;
}
// outpcmdata must be 5760*2 shorts in length
// outpcmdata must be 11520*2 bytes in length
// packets must be decoded in order
// a packet loss must call this function with NULL indata and 0 inlen
// returns the number of decoded samples
int nv_opus_decode(unsigned char* indata, int inlen, short* outpcmdata) {
int nv_opus_decode(unsigned char* indata, int inlen, unsigned char* outpcmdata) {
int err;
// Decoding to 16-bit PCM with FEC off
// Maximum length assuming 48KHz sample rate
err = opus_decode(decoder, indata, inlen,
outpcmdata, 512, 0);
(opus_int16*) outpcmdata, 512, 0);
if (err>0)
err = err * 2;
return err;
}