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