Oboe
A library for creating real-time audio apps on Android
Loading...
Searching...
No Matches
StabilizedCallback.h
1/*
2 * Copyright 2018 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 OBOE_STABILIZEDCALLBACK_H
18#define OBOE_STABILIZEDCALLBACK_H
19
20#include <cstdint>
21#include "oboe/AudioStream.h"
22
23namespace oboe {
24
26
27public:
29
30 DataCallbackResult
32
33 void onErrorBeforeClose(AudioStream *oboeStream, Result error) override {
34 return mCallback->onErrorBeforeClose(oboeStream, error);
35 }
36
37 void onErrorAfterClose(AudioStream *oboeStream, Result error) override {
38
39 // Reset all fields now that the stream has been closed
40 mFrameCount = 0;
41 mEpochTimeNanos = 0;
42 mOpsPerNano = 1;
43 return mCallback->onErrorAfterClose(oboeStream, error);
44 }
45
46private:
47
48 AudioStreamCallback *mCallback = nullptr;
49 int64_t mFrameCount = 0;
50 int64_t mEpochTimeNanos = 0;
51 double mOpsPerNano = 1;
52
53 void generateLoad(int64_t durationNanos);
54};
55
60#if defined(__i386__) || defined(__x86_64__)
61#define cpu_relax() asm volatile("rep; nop" ::: "memory");
62
63#elif defined(__arm__) || defined(__mips__) || defined(__riscv)
64 #define cpu_relax() asm volatile("":::"memory")
65
66#elif defined(__aarch64__)
67#define cpu_relax() asm volatile("yield" ::: "memory")
68
69#else
70#error "cpu_relax is not defined for this architecture"
71#endif
72
73}
74
75#endif //OBOE_STABILIZEDCALLBACK_H
Definition AudioStreamCallback.h:187
virtual void onErrorBeforeClose(AudioStream *, Result)
Definition AudioStreamCallback.h:152
virtual void onErrorAfterClose(AudioStream *, Result)
Definition AudioStreamCallback.h:168
Definition AudioStream.h:42
Definition ResultWithValue.h:47
Definition StabilizedCallback.h:25
void onErrorBeforeClose(AudioStream *oboeStream, Result error) override
Definition StabilizedCallback.h:33
DataCallbackResult onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames) override
void onErrorAfterClose(AudioStream *oboeStream, Result error) override
Definition StabilizedCallback.h:37