diff options
author | Andreas Huber <andih@google.com> | 2010-01-29 13:23:55 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-01-29 14:13:30 -0800 |
commit | 00aa8ec727cd3027942e5c150523484d7e2e3c5d (patch) | |
tree | 0670a99ec671fd83e6e13711c2e03934158560aa /media/libstagefright/WAVExtractor.cpp | |
parent | 85fb658b4bcca319f022f34a1de78a9463c9df11 (diff) | |
download | frameworks_base-00aa8ec727cd3027942e5c150523484d7e2e3c5d.zip frameworks_base-00aa8ec727cd3027942e5c150523484d7e2e3c5d.tar.gz frameworks_base-00aa8ec727cd3027942e5c150523484d7e2e3c5d.tar.bz2 |
Support 24-bit LE PCM wave files in stagefright.
related-to-bug: 2300197
Diffstat (limited to 'media/libstagefright/WAVExtractor.cpp')
-rw-r--r-- | media/libstagefright/WAVExtractor.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/media/libstagefright/WAVExtractor.cpp b/media/libstagefright/WAVExtractor.cpp index da8fe79..7365dfa 100644 --- a/media/libstagefright/WAVExtractor.cpp +++ b/media/libstagefright/WAVExtractor.cpp @@ -178,7 +178,8 @@ status_t WAVExtractor::init() { mBitsPerSample = U16_LE_AT(&formatSpec[14]); - if (mBitsPerSample != 8 && mBitsPerSample != 16) { + if (mBitsPerSample != 8 && mBitsPerSample != 16 + && mBitsPerSample != 24) { return ERROR_UNSUPPORTED; } @@ -329,6 +330,24 @@ status_t WAVSource::read( buffer->release(); buffer = tmp; + } else if (mBitsPerSample == 24) { + // Convert 24-bit signed samples to 16-bit signed. + + const uint8_t *src = + (const uint8_t *)buffer->data() + buffer->range_offset(); + int16_t *dst = (int16_t *)src; + + size_t numSamples = buffer->range_length() / 3; + for (size_t i = 0; i < numSamples; ++i) { + int32_t x = (int32_t)(src[0] | src[1] << 8 | src[2] << 16); + x = (x << 8) >> 8; // sign extension + + x = x >> 8; + *dst++ = (int16_t)x; + src += 3; + } + + buffer->set_range(buffer->range_offset(), 2 * numSamples); } size_t bytesPerSample = mBitsPerSample >> 3; |