1 /*
2  * Copyright 2021 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 MEGA_PLAYER_BLIPAUDIOSOURCE_H
18 #define MEGA_PLAYER_BLIPAUDIOSOURCE_H
19 
20 #include <atomic>
21 
22 #include "WaveTableSource.h"
23 
24 class BlipAudioSource: public WaveTableSource {
25 private:
26     // 1/16 second @48000 Hz
27     static const int NUM_PULSE_FRAMES = (int) (48000 * (1.0 / 16.0));
28 
29     int mNumPendingPulseFrames;
30 
31 public:
32     BlipAudioSource();
33 
34     /**
35      * Triggers a "blip" in the output
36      */
37     virtual void trigger();
38 
39     /**
40      * Fills the specified buffer with silence until triggered and then with
41      * a short sine tone.
42      * @return  The number of frames generated. Since we are generating a continuous periodic
43      * signal, this will always be <code>numFrames</code>.
44      */
45     virtual int pull(float* buffer, int numFrames, int numChans) override;
46 
47     std::atomic<int> mRequestCount; // external thread increments this to request a beep
48     std::atomic<int> mAcknowledgeCount; // audio thread sets this to acknowledge
49 };
50 
51 
52 #endif // MEGA_PLAYER_BLIPAUDIOSOURCE_H
53