Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_UTIL_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_UTIL_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_UTIL_H_ | 6 #define MEDIA_AUDIO_AUDIO_UTIL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "media/base/media_api.h" | |
| 11 | 12 |
| 12 namespace media { | 13 namespace media { |
| 13 | 14 |
| 14 // For all audio functions 3 audio formats are supported: | 15 // For all audio functions 3 audio formats are supported: |
| 15 // 8 bits unsigned 0 to 255. | 16 // 8 bits unsigned 0 to 255. |
| 16 // 16 bit signed (little endian). | 17 // 16 bit signed (little endian). |
| 17 // 32 bit signed (little endian) | 18 // 32 bit signed (little endian) |
| 18 | 19 |
| 19 // AdjustVolume() does a software volume adjustment of a sample buffer. | 20 // AdjustVolume() does a software volume adjustment of a sample buffer. |
| 20 // The samples are multiplied by the volume, which should range from | 21 // The samples are multiplied by the volume, which should range from |
| 21 // 0.0 (mute) to 1.0 (full volume). | 22 // 0.0 (mute) to 1.0 (full volume). |
| 22 // Using software allows each audio and video to have its own volume without | 23 // Using software allows each audio and video to have its own volume without |
| 23 // affecting the master volume. | 24 // affecting the master volume. |
| 24 // In the future the function may be used to adjust the sample format to | 25 // In the future the function may be used to adjust the sample format to |
| 25 // simplify hardware requirements and to support a wider variety of input | 26 // simplify hardware requirements and to support a wider variety of input |
| 26 // formats. | 27 // formats. |
| 27 // The buffer is modified in-place to avoid memory management, as this | 28 // The buffer is modified in-place to avoid memory management, as this |
| 28 // function may be called in performance critical code. | 29 // function may be called in performance critical code. |
| 29 bool AdjustVolume(void* buf, | 30 MEDIA_API bool AdjustVolume(void* buf, |
| 30 size_t buflen, | 31 size_t buflen, |
| 31 int channels, | 32 int channels, |
| 32 int bytes_per_sample, | 33 int bytes_per_sample, |
| 33 float volume); | 34 float volume); |
| 34 | 35 |
| 35 // FoldChannels() does a software multichannel folding down to stereo. | 36 // FoldChannels() does a software multichannel folding down to stereo. |
| 36 // Channel order is assumed to be 5.1 Dolby standard which is | 37 // Channel order is assumed to be 5.1 Dolby standard which is |
| 37 // front left, front right, center, surround left, surround right. | 38 // front left, front right, center, surround left, surround right. |
| 38 // The subwoofer is ignored. | 39 // The subwoofer is ignored. |
| 39 // 6.1 adds a rear center speaker, and 7.1 has 2 rear speakers. These | 40 // 6.1 adds a rear center speaker, and 7.1 has 2 rear speakers. These |
| 40 // channels are rare and ignored. | 41 // channels are rare and ignored. |
| 41 // After summing the channels, volume is adjusted and the samples are | 42 // After summing the channels, volume is adjusted and the samples are |
| 42 // clipped to the maximum value. | 43 // clipped to the maximum value. |
| 43 // Volume should normally range from 0.0 (mute) to 1.0 (full volume), but | 44 // Volume should normally range from 0.0 (mute) to 1.0 (full volume), but |
| 44 // since clamping is performed a value of more than 1 is allowed to increase | 45 // since clamping is performed a value of more than 1 is allowed to increase |
| 45 // volume. | 46 // volume. |
| 46 // The buffer is modified in-place to avoid memory management, as this | 47 // The buffer is modified in-place to avoid memory management, as this |
| 47 // function may be called in performance critical code. | 48 // function may be called in performance critical code. |
| 48 bool FoldChannels(void* buf, | 49 MEDIA_API bool FoldChannels(void* buf, |
| 49 size_t buflen, | 50 size_t buflen, |
| 50 int channels, | 51 int channels, |
| 51 int bytes_per_sample, | 52 int bytes_per_sample, |
| 52 float volume); | 53 float volume); |
| 53 | 54 |
| 54 // DeinterleaveAudioChannel() takes interleaved audio buffer |source| | 55 // DeinterleaveAudioChannel() takes interleaved audio buffer |source| |
| 55 // of the given |sample_fmt| and |number_of_channels| and extracts | 56 // of the given |sample_fmt| and |number_of_channels| and extracts |
| 56 // |number_of_frames| data for the given |channel_index| and | 57 // |number_of_frames| data for the given |channel_index| and |
| 57 // puts it in the floating point |destination|. | 58 // puts it in the floating point |destination|. |
| 58 // It returns |true| on success, or |false| if the |sample_fmt| is | 59 // It returns |true| on success, or |false| if the |sample_fmt| is |
| 59 // not recognized. | 60 // not recognized. |
| 60 bool DeinterleaveAudioChannel(void* source, | 61 bool DeinterleaveAudioChannel(void* source, |
| 61 float* destination, | 62 float* destination, |
| 62 int channels, | 63 int channels, |
| 63 int channel_index, | 64 int channel_index, |
| 64 int bytes_per_sample, | 65 int bytes_per_sample, |
| 65 size_t number_of_frames); | 66 size_t number_of_frames); |
| 66 | 67 |
| 67 // InterleaveFloatToInt16 scales, clips, and interleaves the planar | 68 // InterleaveFloatToInt16 scales, clips, and interleaves the planar |
| 68 // floating-point audio contained in |source| to the int16 |destination|. | 69 // floating-point audio contained in |source| to the int16 |destination|. |
| 69 // The floating-point data is in a canonical range of -1.0 -> +1.0. | 70 // The floating-point data is in a canonical range of -1.0 -> +1.0. |
| 70 // The size of the |source| vector determines the number of channels. | 71 // The size of the |source| vector determines the number of channels. |
| 71 // The |destination| buffer is assumed to be large enough to hold the | 72 // The |destination| buffer is assumed to be large enough to hold the |
| 72 // result. Thus it must be at least size: number_of_frames * source.size() | 73 // result. Thus it must be at least size: number_of_frames * source.size() |
| 73 void InterleaveFloatToInt16(const std::vector<float*>& source, | 74 MEDIA_API void InterleaveFloatToInt16(const std::vector<float*>& source, |
| 74 int16* destination, | 75 int16* destination, |
| 75 size_t number_of_frames); | 76 size_t number_of_frames); |
| 76 | 77 |
| 77 // Reorder PCM from AAC layout to Core Audio 5.1 layout. | 78 // Reorder PCM from AAC layout to Core Audio 5.1 layout. |
| 78 // TODO(fbarchard): Switch layout when ffmpeg is updated. | 79 // TODO(fbarchard): Switch layout when ffmpeg is updated. |
| 79 template<class Format> | 80 template<class Format> |
| 80 void SwizzleCoreAudioLayout5_1(Format* b, uint32 filled) { | 81 void SwizzleCoreAudioLayout5_1(Format* b, uint32 filled) { |
|
scherkus (not reviewing)
2011/07/29 17:22:57
hmm I'll move this function into a better place in
| |
| 81 static const int kNumSurroundChannels = 6; | 82 static const int kNumSurroundChannels = 6; |
| 82 Format aac[kNumSurroundChannels]; | 83 Format aac[kNumSurroundChannels]; |
| 83 for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { | 84 for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { |
| 84 memcpy(aac, b, sizeof(aac)); | 85 memcpy(aac, b, sizeof(aac)); |
| 85 b[0] = aac[1]; // L | 86 b[0] = aac[1]; // L |
| 86 b[1] = aac[2]; // R | 87 b[1] = aac[2]; // R |
| 87 b[2] = aac[0]; // C | 88 b[2] = aac[0]; // C |
| 88 b[3] = aac[5]; // LFE | 89 b[3] = aac[5]; // LFE |
| 89 b[4] = aac[3]; // Ls | 90 b[4] = aac[3]; // Ls |
| 90 b[5] = aac[4]; // Rs | 91 b[5] = aac[4]; // Rs |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 // Returns the default audio hardware sample-rate. | 95 // Returns the default audio hardware sample-rate. |
| 95 double GetAudioHardwareSampleRate(); | 96 MEDIA_API double GetAudioHardwareSampleRate(); |
| 96 | 97 |
| 97 } // namespace media | 98 } // namespace media |
| 98 | 99 |
| 99 #endif // MEDIA_AUDIO_AUDIO_UTIL_H_ | 100 #endif // MEDIA_AUDIO_AUDIO_UTIL_H_ |
| OLD | NEW |