OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_export.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_EXPORT 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_EXPORT 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_EXPORT 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 // Returns the default audio hardware sample-rate. | 78 // Returns the default audio hardware sample-rate. |
78 double GetAudioHardwareSampleRate(); | 79 MEDIA_EXPORT double GetAudioHardwareSampleRate(); |
79 | 80 |
80 } // namespace media | 81 } // namespace media |
81 | 82 |
82 #endif // MEDIA_AUDIO_AUDIO_UTIL_H_ | 83 #endif // MEDIA_AUDIO_AUDIO_UTIL_H_ |
OLD | NEW |