diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-19 20:55:27 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-19 22:27:04 +0000 |
commit | 656040027db4b75c429b06c3777ec7621ce110a1 (patch) | |
tree | e2c8f470102edb40bd66710ae1bb499232392027 /toxav/audio.c | |
parent | 1a4e56397b3d009b725cc7a2a0913168bbe698d3 (diff) |
Add some explanatory comments to the toxav audio code.
By @zoff99.
Diffstat (limited to 'toxav/audio.c')
-rw-r--r-- | toxav/audio.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/toxav/audio.c b/toxav/audio.c index b45157c7..f2453e8e 100644 --- a/toxav/audio.c +++ b/toxav/audio.c | |||
@@ -180,6 +180,15 @@ void ac_iterate(ACSession *ac) | |||
180 | continue; | 180 | continue; |
181 | } | 181 | } |
182 | 182 | ||
183 | /* | ||
184 | * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); | ||
185 | * where | ||
186 | * packet is the byte array containing the compressed data | ||
187 | * len is the exact number of bytes contained in the packet | ||
188 | * decoded is the decoded audio data in opus_int16 (or float for opus_decode_float()) | ||
189 | * max_size is the max duration of the frame in samples (per channel) that can fit | ||
190 | * into the decoded_frame array | ||
191 | */ | ||
183 | rc = opus_decode(ac->decoder, msg->data + 4, msg->len - 4, temp_audio_buffer, 5760, 0); | 192 | rc = opus_decode(ac->decoder, msg->data + 4, msg->len - 4, temp_audio_buffer, 5760, 0); |
184 | free(msg); | 193 | free(msg); |
185 | } | 194 | } |
@@ -356,6 +365,11 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success) | |||
356 | OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count) | 365 | OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count) |
357 | { | 366 | { |
358 | int status = OPUS_OK; | 367 | int status = OPUS_OK; |
368 | /* | ||
369 | * OPUS_APPLICATION_VOIP Process signal for improved speech intelligibility | ||
370 | * OPUS_APPLICATION_AUDIO Favor faithfulness to the original input | ||
371 | * OPUS_APPLICATION_RESTRICTED_LOWDELAY Configure the minimum possible coding delay | ||
372 | */ | ||
359 | OpusEncoder *rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_VOIP, &status); | 373 | OpusEncoder *rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_VOIP, &status); |
360 | 374 | ||
361 | if (status != OPUS_OK) { | 375 | if (status != OPUS_OK) { |
@@ -363,6 +377,16 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin | |||
363 | return NULL; | 377 | return NULL; |
364 | } | 378 | } |
365 | 379 | ||
380 | |||
381 | /* | ||
382 | * Rates from 500 to 512000 bits per second are meaningful as well as the special | ||
383 | * values OPUS_BITRATE_AUTO and OPUS_BITRATE_MAX. The value OPUS_BITRATE_MAX can | ||
384 | * be used to cause the codec to use as much rate as it can, which is useful for | ||
385 | * controlling the rate by adjusting the output buffer size. | ||
386 | * | ||
387 | * Parameters: | ||
388 | * [in] x opus_int32: bitrate in bits per second. | ||
389 | */ | ||
366 | status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bit_rate)); | 390 | status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bit_rate)); |
367 | 391 | ||
368 | if (status != OPUS_OK) { | 392 | if (status != OPUS_OK) { |
@@ -370,6 +394,14 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin | |||
370 | goto FAILURE; | 394 | goto FAILURE; |
371 | } | 395 | } |
372 | 396 | ||
397 | |||
398 | /* | ||
399 | * Configures the encoder's use of inband forward error correction. | ||
400 | * Note: | ||
401 | * This is only applicable to the LPC layer | ||
402 | * Parameters: | ||
403 | * [in] x int: FEC flag, 0 (disabled) is default | ||
404 | */ | ||
373 | /* Enable in-band forward error correction in codec */ | 405 | /* Enable in-band forward error correction in codec */ |
374 | status = opus_encoder_ctl(rc, OPUS_SET_INBAND_FEC(1)); | 406 | status = opus_encoder_ctl(rc, OPUS_SET_INBAND_FEC(1)); |
375 | 407 | ||
@@ -378,6 +410,15 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin | |||
378 | goto FAILURE; | 410 | goto FAILURE; |
379 | } | 411 | } |
380 | 412 | ||
413 | |||
414 | /* | ||
415 | * Configures the encoder's expected packet loss percentage. | ||
416 | * Higher values with trigger progressively more loss resistant behavior in | ||
417 | * the encoder at the expense of quality at a given bitrate in the lossless case, | ||
418 | * but greater quality under loss. | ||
419 | * Parameters: | ||
420 | * [in] x int: Loss percentage in the range 0-100, inclusive. | ||
421 | */ | ||
381 | /* Make codec resistant to up to 10% packet loss | 422 | /* Make codec resistant to up to 10% packet loss |
382 | * NOTE This could also be adjusted on the fly, rather than hard-coded, | 423 | * NOTE This could also be adjusted on the fly, rather than hard-coded, |
383 | * with feedback from the receiving client. | 424 | * with feedback from the receiving client. |
@@ -389,6 +430,16 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin | |||
389 | goto FAILURE; | 430 | goto FAILURE; |
390 | } | 431 | } |
391 | 432 | ||
433 | |||
434 | /* | ||
435 | * Configures the encoder's computational complexity. | ||
436 | * | ||
437 | * The supported range is 0-10 inclusive with 10 representing the highest complexity. | ||
438 | * The default value is 10. | ||
439 | * | ||
440 | * Parameters: | ||
441 | * [in] x int: 0-10, inclusive | ||
442 | */ | ||
392 | /* Set algorithm to the highest complexity, maximizing compression */ | 443 | /* Set algorithm to the highest complexity, maximizing compression */ |
393 | status = opus_encoder_ctl(rc, OPUS_SET_COMPLEXITY(AUDIO_OPUS_COMPLEXITY)); | 444 | status = opus_encoder_ctl(rc, OPUS_SET_COMPLEXITY(AUDIO_OPUS_COMPLEXITY)); |
394 | 445 | ||