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 #include <cstdlib>
18
19 #include "BlipAudioSource.h"
20
BlipAudioSource()21 BlipAudioSource::BlipAudioSource()
22 : mNumPendingPulseFrames(0),
23 mRequestCount(0),
24 mAcknowledgeCount(0)
25 {
26 float* waveTbl = new float[DEFAULT_WAVETABLE_LENGTH];
27 WaveTableSource::genSinWave(waveTbl, DEFAULT_WAVETABLE_LENGTH);
28
29 WaveTableSource::setWaveTable(waveTbl, DEFAULT_WAVETABLE_LENGTH);
30 }
31
trigger()32 void BlipAudioSource::trigger() {
33 mRequestCount++;
34 }
35
pull(float * buffer,int numFrames,int numChans)36 int BlipAudioSource::pull(float* buffer, int numFrames, int numChans) {
37 if (mRequestCount.load() > mAcknowledgeCount.load()) {
38 mAcknowledgeCount++;
39 mNumPendingPulseFrames = NUM_PULSE_FRAMES;
40 }
41
42 if (mNumPendingPulseFrames <= 0) {
43 memset(buffer, 0, numFrames * numChans * sizeof(float));
44 } else {
45 WaveTableSource::pull(buffer, numFrames, numChans);
46 mNumPendingPulseFrames -= numFrames;
47 }
48 return numFrames;
49 }
50
51 //
52 // JNI
53 //
54 #include <jni.h>
55
56 extern "C" {
57 JNIEXPORT jlong JNICALL
Java_com_android_cts_verifier_audio_sources_BlipAudioSourceProvider_allocNativeSource(JNIEnv * env,jobject thiz)58 Java_com_android_cts_verifier_audio_sources_BlipAudioSourceProvider_allocNativeSource(
59 JNIEnv *env, jobject thiz) {
60 return (jlong)new BlipAudioSource;
61 }
62
63 } // extern "C"
64