OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 23 * DAMAGE. |
23 */ | 24 */ |
24 | 25 |
25 #ifndef AudioResamplerKernel_h | 26 #ifndef AudioResamplerKernel_h |
26 #define AudioResamplerKernel_h | 27 #define AudioResamplerKernel_h |
27 | 28 |
28 #include "platform/PlatformExport.h" | 29 #include "platform/PlatformExport.h" |
29 #include "platform/audio/AudioArray.h" | 30 #include "platform/audio/AudioArray.h" |
30 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 class AudioResampler; | 35 class AudioResampler; |
35 | 36 |
36 // AudioResamplerKernel does resampling on a single mono channel. | 37 // AudioResamplerKernel does resampling on a single mono channel. |
37 // It uses a simple linear interpolation for good performance. | 38 // It uses a simple linear interpolation for good performance. |
38 | 39 |
39 class PLATFORM_EXPORT AudioResamplerKernel { | 40 class PLATFORM_EXPORT AudioResamplerKernel { |
40 USING_FAST_MALLOC(AudioResamplerKernel); | 41 USING_FAST_MALLOC(AudioResamplerKernel); |
41 WTF_MAKE_NONCOPYABLE(AudioResamplerKernel); | 42 WTF_MAKE_NONCOPYABLE(AudioResamplerKernel); |
42 | 43 |
43 public: | 44 public: |
44 AudioResamplerKernel(AudioResampler*); | 45 AudioResamplerKernel(AudioResampler*); |
45 | 46 |
46 // getSourcePointer() should be called each time before process() is called. | 47 // getSourcePointer() should be called each time before process() is called. |
47 // Given a number of frames to process (for subsequent call to process()), it
returns a pointer and numberOfSourceFramesNeeded | 48 // Given a number of frames to process (for subsequent call to process()), it |
48 // where sample data should be copied. This sample data provides the input to
the resampler when process() is called. | 49 // returns a pointer and numberOfSourceFramesNeeded where sample data should |
49 // framesToProcess must be less than or equal to MaxFramesToProcess. | 50 // be copied. This sample data provides the input to the resampler when |
| 51 // process() is called. framesToProcess must be less than or equal to |
| 52 // MaxFramesToProcess. |
50 float* getSourcePointer(size_t framesToProcess, | 53 float* getSourcePointer(size_t framesToProcess, |
51 size_t* numberOfSourceFramesNeeded); | 54 size_t* numberOfSourceFramesNeeded); |
52 | 55 |
53 // process() resamples framesToProcess frames from the source into destination
. | 56 // process() resamples framesToProcess frames from the source into |
54 // Each call to process() must be preceded by a call to getSourcePointer() so
that source input may be supplied. | 57 // destination. Each call to process() must be preceded by a call to |
55 // framesToProcess must be less than or equal to MaxFramesToProcess. | 58 // getSourcePointer() so that source input may be supplied. framesToProcess |
| 59 // must be less than or equal to MaxFramesToProcess. |
56 void process(float* destination, size_t framesToProcess); | 60 void process(float* destination, size_t framesToProcess); |
57 | 61 |
58 // Resets the processing state. | 62 // Resets the processing state. |
59 void reset(); | 63 void reset(); |
60 | 64 |
61 static const size_t MaxFramesToProcess; | 65 static const size_t MaxFramesToProcess; |
62 | 66 |
63 private: | 67 private: |
64 double rate() const; | 68 double rate() const; |
65 | 69 |
66 AudioResampler* m_resampler; | 70 AudioResampler* m_resampler; |
67 AudioFloatArray m_sourceBuffer; | 71 AudioFloatArray m_sourceBuffer; |
68 | 72 |
69 // This is a (floating point) read index on the input stream. | 73 // This is a (floating point) read index on the input stream. |
70 double m_virtualReadIndex; | 74 double m_virtualReadIndex; |
71 | 75 |
72 // We need to have continuity from one call of process() to the next. | 76 // We need to have continuity from one call of process() to the next. |
73 // m_lastValues stores the last two sample values from the last call to proces
s(). | 77 // m_lastValues stores the last two sample values from the last call to |
74 // m_fillIndex represents how many buffered samples we have which can be as ma
ny as 2. | 78 // process(). m_fillIndex represents how many buffered samples we have which |
75 // For the first call to process() (or after reset()) there will be no buffere
d samples. | 79 // can be as many as 2. For the first call to process() (or after reset()) |
| 80 // there will be no buffered samples. |
76 float m_lastValues[2]; | 81 float m_lastValues[2]; |
77 unsigned m_fillIndex; | 82 unsigned m_fillIndex; |
78 }; | 83 }; |
79 | 84 |
80 } // namespace blink | 85 } // namespace blink |
81 | 86 |
82 #endif // AudioResamplerKernel_h | 87 #endif // AudioResamplerKernel_h |
OLD | NEW |