1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef WAVETABLEOSCILLATOR_H_
18 #define WAVETABLEOSCILLATOR_H_
19 
20 #include "PeriodicAudioSource.h"
21 
22 namespace ndkaudio {
23 
24 /*
25  * The assumption here is that the provided wave table contains 1 cycle of the wave
26  * and that the first and last samples are the same.
27  */
28 class WaveTableOscillator : public PeriodicAudioSource {
29  public:
30     WaveTableOscillator(int numChannels, float* waveTable, int waveTableSize);
31 
32     void setWaveTable(float* waveTable, int waveTableSize);
33 
34     int getData(long time, float* outBuff, int numFrames, int outChans);
35 
36  private:
37     float* waveTable_;
38     int waveTableSize_;
39 
40     // 'nominal' frequency (i.e. how many times we step through the
41     // 1-cycle wave table in a second
42     float fN_;
43 
44     // current pointer into the wave table
45     float srcPhase_;
46 
47     // profiling
48     long prevFillTime_;
49 };
50 
51 } // namespace ndkaudio
52 
53 #endif /* WAVETABLEOSCILLATOR_H_ */
54