summaryrefslogtreecommitdiff
path: root/src/lib/decoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-10-20 21:29:20 +0100
committerCarl Hetherington <cth@carlh.net>2012-10-20 21:29:20 +0100
commit5911030f411e104778ad2c3faca8c8cb7bdbc387 (patch)
treebefe0ce3d1137497171b3c554f498354b9b6f798 /src/lib/decoder.cc
parentb6e73791a09cf0598024484f820385f4fec6190c (diff)
Extract audio more correctly and neatly; support 7.1 in DCP naming; fix up lack of update after changing audio stream.
Diffstat (limited to 'src/lib/decoder.cc')
-rw-r--r--src/lib/decoder.cc27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc
index 14401994f..d78089265 100644
--- a/src/lib/decoder.cc
+++ b/src/lib/decoder.cc
@@ -200,28 +200,37 @@ Decoder::emit_audio (uint8_t* data, int size)
switch (audio_sample_format()) {
case AV_SAMPLE_FMT_S16:
{
- uint8_t* p = data;
+ int16_t* p = (int16_t *) data;
int sample = 0;
int channel = 0;
for (int i = 0; i < total_samples; ++i) {
- /* unsigned sample */
- int const ou = p[0] | (p[1] << 8);
- /* signed sample */
- int const os = ou >= 0x8000 ? (- 0x10000 + ou) : ou;
- /* float sample */
- audio->data(channel)[sample] = float(os) / 0x8000;
+ audio->data(channel)[sample] = float(*p++) / (1 << 15);
++channel;
if (channel == _fs->audio_channels()) {
channel = 0;
++sample;
}
-
- p += 2;
}
}
break;
+ case AV_SAMPLE_FMT_S32:
+ {
+ int32_t* p = (int32_t *) data;
+ int sample = 0;
+ int channel = 0;
+ for (int i = 0; i < total_samples; ++i) {
+ audio->data(channel)[sample] = float(*p++) / (1 << 31);
+
+ ++channel;
+ if (channel == _fs->audio_channels()) {
+ channel = 0;
+ ++sample;
+ }
+ }
+ }
+
case AV_SAMPLE_FMT_FLTP:
{
float* p = reinterpret_cast<float*> (data);