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 base { | 13 namespace base { |
13 class SharedMemory; | 14 class SharedMemory; |
14 } | 15 } |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 // For all audio functions 3 audio formats are supported: | 19 // For all audio functions 3 audio formats are supported: |
19 // 8 bits unsigned 0 to 255. | 20 // 8 bits unsigned 0 to 255. |
20 // 16 bit signed (little endian). | 21 // 16 bit signed (little endian). |
21 // 32 bit signed (little endian) | 22 // 32 bit signed (little endian) |
22 | 23 |
23 // AdjustVolume() does a software volume adjustment of a sample buffer. | 24 // AdjustVolume() does a software volume adjustment of a sample buffer. |
24 // The samples are multiplied by the volume, which should range from | 25 // The samples are multiplied by the volume, which should range from |
25 // 0.0 (mute) to 1.0 (full volume). | 26 // 0.0 (mute) to 1.0 (full volume). |
26 // Using software allows each audio and video to have its own volume without | 27 // Using software allows each audio and video to have its own volume without |
27 // affecting the master volume. | 28 // affecting the master volume. |
28 // In the future the function may be used to adjust the sample format to | 29 // In the future the function may be used to adjust the sample format to |
29 // simplify hardware requirements and to support a wider variety of input | 30 // simplify hardware requirements and to support a wider variety of input |
30 // formats. | 31 // formats. |
31 // The buffer is modified in-place to avoid memory management, as this | 32 // The buffer is modified in-place to avoid memory management, as this |
32 // function may be called in performance critical code. | 33 // function may be called in performance critical code. |
33 bool AdjustVolume(void* buf, | 34 MEDIA_EXPORT bool AdjustVolume(void* buf, |
34 size_t buflen, | 35 size_t buflen, |
35 int channels, | 36 int channels, |
36 int bytes_per_sample, | 37 int bytes_per_sample, |
37 float volume); | 38 float volume); |
38 | 39 |
39 // FoldChannels() does a software multichannel folding down to stereo. | 40 // FoldChannels() does a software multichannel folding down to stereo. |
40 // Channel order is assumed to be 5.1 Dolby standard which is | 41 // Channel order is assumed to be 5.1 Dolby standard which is |
41 // front left, front right, center, surround left, surround right. | 42 // front left, front right, center, surround left, surround right. |
42 // The subwoofer is ignored. | 43 // The subwoofer is ignored. |
43 // 6.1 adds a rear center speaker, and 7.1 has 2 rear speakers. These | 44 // 6.1 adds a rear center speaker, and 7.1 has 2 rear speakers. These |
44 // channels are rare and ignored. | 45 // channels are rare and ignored. |
45 // After summing the channels, volume is adjusted and the samples are | 46 // After summing the channels, volume is adjusted and the samples are |
46 // clipped to the maximum value. | 47 // clipped to the maximum value. |
47 // Volume should normally range from 0.0 (mute) to 1.0 (full volume), but | 48 // Volume should normally range from 0.0 (mute) to 1.0 (full volume), but |
48 // since clamping is performed a value of more than 1 is allowed to increase | 49 // since clamping is performed a value of more than 1 is allowed to increase |
49 // volume. | 50 // volume. |
50 // The buffer is modified in-place to avoid memory management, as this | 51 // The buffer is modified in-place to avoid memory management, as this |
51 // function may be called in performance critical code. | 52 // function may be called in performance critical code. |
52 bool FoldChannels(void* buf, | 53 MEDIA_EXPORT bool FoldChannels(void* buf, |
53 size_t buflen, | 54 size_t buflen, |
54 int channels, | 55 int channels, |
55 int bytes_per_sample, | 56 int bytes_per_sample, |
56 float volume); | 57 float volume); |
57 | 58 |
58 // DeinterleaveAudioChannel() takes interleaved audio buffer |source| | 59 // DeinterleaveAudioChannel() takes interleaved audio buffer |source| |
59 // of the given |sample_fmt| and |number_of_channels| and extracts | 60 // of the given |sample_fmt| and |number_of_channels| and extracts |
60 // |number_of_frames| data for the given |channel_index| and | 61 // |number_of_frames| data for the given |channel_index| and |
61 // puts it in the floating point |destination|. | 62 // puts it in the floating point |destination|. |
62 // It returns |true| on success, or |false| if the |sample_fmt| is | 63 // It returns |true| on success, or |false| if the |sample_fmt| is |
63 // not recognized. | 64 // not recognized. |
64 bool DeinterleaveAudioChannel(void* source, | 65 bool DeinterleaveAudioChannel(void* source, |
65 float* destination, | 66 float* destination, |
66 int channels, | 67 int channels, |
67 int channel_index, | 68 int channel_index, |
68 int bytes_per_sample, | 69 int bytes_per_sample, |
69 size_t number_of_frames); | 70 size_t number_of_frames); |
70 | 71 |
71 // InterleaveFloatToInt16 scales, clips, and interleaves the planar | 72 // InterleaveFloatToInt16 scales, clips, and interleaves the planar |
72 // floating-point audio contained in |source| to the int16 |destination|. | 73 // floating-point audio contained in |source| to the int16 |destination|. |
73 // The floating-point data is in a canonical range of -1.0 -> +1.0. | 74 // The floating-point data is in a canonical range of -1.0 -> +1.0. |
74 // The size of the |source| vector determines the number of channels. | 75 // The size of the |source| vector determines the number of channels. |
75 // The |destination| buffer is assumed to be large enough to hold the | 76 // The |destination| buffer is assumed to be large enough to hold the |
76 // result. Thus it must be at least size: number_of_frames * source.size() | 77 // result. Thus it must be at least size: number_of_frames * source.size() |
77 void InterleaveFloatToInt16(const std::vector<float*>& source, | 78 MEDIA_EXPORT void InterleaveFloatToInt16(const std::vector<float*>& source, |
78 int16* destination, | 79 int16* destination, |
79 size_t number_of_frames); | 80 size_t number_of_frames); |
80 | 81 |
81 // Returns the default audio hardware sample-rate. | 82 // Returns the default audio hardware sample-rate. |
82 double GetAudioHardwareSampleRate(); | 83 MEDIA_EXPORT double GetAudioHardwareSampleRate(); |
83 | 84 |
84 // Functions that handle data buffer passed between processes in the shared | 85 // Functions that handle data buffer passed between processes in the shared |
85 // memory. Called on both IPC sides. | 86 // memory. Called on both IPC sides. |
86 | 87 |
87 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size); | 88 MEDIA_EXPORT uint32 TotalSharedMemorySizeInBytes(uint32 packet_size); |
88 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size); | 89 MEDIA_EXPORT uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size); |
89 uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory, | 90 MEDIA_EXPORT uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory, |
90 uint32 shared_memory_size); | 91 uint32 shared_memory_size); |
91 void SetActualDataSizeInBytes(base::SharedMemory* shared_memory, | 92 MEDIA_EXPORT void SetActualDataSizeInBytes(base::SharedMemory* shared_memory, |
92 uint32 shared_memory_size, | 93 uint32 shared_memory_size, |
93 uint32 actual_data_size); | 94 uint32 actual_data_size); |
94 | 95 |
95 } // namespace media | 96 } // namespace media |
96 | 97 |
97 #endif // MEDIA_AUDIO_AUDIO_UTIL_H_ | 98 #endif // MEDIA_AUDIO_AUDIO_UTIL_H_ |
OLD | NEW |