aboutsummaryrefslogtreecommitdiff
path: root/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/OboeTester/app/src/main/cpp/NativeAudioContext.h')
-rw-r--r--apps/OboeTester/app/src/main/cpp/NativeAudioContext.h72
1 files changed, 53 insertions, 19 deletions
diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
index 9ffd36e4..94ae680d 100644
--- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
+++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
@@ -32,6 +32,7 @@
#include "flowunits/ImpulseOscillator.h"
#include "flowgraph/ManyToMultiConverter.h"
#include "flowgraph/MonoToMultiConverter.h"
+#include "flowgraph/RampLinear.h"
#include "flowgraph/SinkFloat.h"
#include "flowgraph/SinkI16.h"
#include "flowgraph/SinkI24.h"
@@ -45,12 +46,12 @@
#include "FullDuplexAnalyzer.h"
#include "FullDuplexEcho.h"
-#include "FullDuplexStream.h"
#include "analyzer/GlitchAnalyzer.h"
#include "analyzer/DataPathAnalyzer.h"
#include "InputStreamCallbackAnalyzer.h"
#include "MultiChannelRecording.h"
#include "OboeStreamCallbackProxy.h"
+#include "OboeTools.h"
#include "PlayRecordingCallback.h"
#include "SawPingGenerator.h"
@@ -66,9 +67,6 @@
#define AMPLITUDE_SAW_PING 0.8
#define AMPLITUDE_IMPULSE 0.7
-#define NANOS_PER_MICROSECOND ((int64_t) 1000)
-#define NANOS_PER_MILLISECOND (1000 * NANOS_PER_MICROSECOND)
-#define NANOS_PER_SECOND (1000 * NANOS_PER_MILLISECOND)
#define SECONDS_TO_RECORD 10
@@ -123,6 +121,7 @@ public:
jint inputPreset,
jint usage,
jint contentType,
+ jint bufferCapacityInFrames,
jint deviceId,
jint sessionId,
jboolean channelConversionAllowed,
@@ -131,32 +130,48 @@ public:
jboolean isMMap,
jboolean isInput);
+ oboe::Result release();
+
virtual void close(int32_t streamIndex);
- virtual void configureForStart() {}
+ virtual void configureAfterOpen() {}
oboe::Result start();
oboe::Result pause();
+ oboe::Result flush();
+
oboe::Result stopAllStreams();
virtual oboe::Result stop() {
return stopAllStreams();
}
- double getCpuLoad() {
+ float getCpuLoad() {
return oboeCallbackProxy.getCpuLoad();
}
+ float getAndResetMaxCpuLoad() {
+ return oboeCallbackProxy.getAndResetMaxCpuLoad();
+ }
+
+ uint32_t getAndResetCpuMask() {
+ return oboeCallbackProxy.getAndResetCpuMask();
+ }
+
std::string getCallbackTimeString() {
return oboeCallbackProxy.getCallbackTimeString();
}
- void setWorkload(double workload) {
+ void setWorkload(int32_t workload) {
oboeCallbackProxy.setWorkload(workload);
}
+ void setHearWorkload(bool enabled) {
+ oboeCallbackProxy.setHearWorkload(enabled);
+ }
+
virtual oboe::Result startPlayback() {
return oboe::Result::OK;
}
@@ -270,6 +285,8 @@ public:
virtual void setSignalType(int signalType) {}
+ virtual void setAmplitude(float amplitude) {}
+
virtual int32_t saveWaveFile(const char *filename);
virtual void setMinimumFramesBeforeRead(int32_t numFrames) {}
@@ -279,6 +296,10 @@ public:
double getTimestampLatency(int32_t streamIndex);
+ void setCpuAffinityMask(uint32_t mask) {
+ oboeCallbackProxy.setCpuAffinityMask(mask);
+ }
+
protected:
std::shared_ptr<oboe::AudioStream> getInputStream();
std::shared_ptr<oboe::AudioStream> getOutputStream();
@@ -324,7 +345,7 @@ public:
ActivityTestInput() {}
virtual ~ActivityTestInput() = default;
- void configureForStart() override;
+ void configureAfterOpen() override;
double getPeakLevel(int index) override {
return mInputAnalyzer.getPeakLevel(index);
@@ -345,7 +366,7 @@ protected:
oboe::Result startStreams() override {
mInputAnalyzer.reset();
- mInputAnalyzer.setup(getInputStream()->getFramesPerBurst(),
+ mInputAnalyzer.setup(std::max(getInputStream()->getFramesPerBurst(), callbackSize),
getInputStream()->getChannelCount(),
getInputStream()->getFormat());
return getInputStream()->requestStart();
@@ -394,11 +415,9 @@ public:
void close(int32_t streamIndex) override;
- oboe::Result startStreams() override {
- return getOutputStream()->start();
- }
+ oboe::Result startStreams() override;
- void configureForStart() override;
+ void configureAfterOpen() override;
virtual void configureStreamGateway();
@@ -419,6 +438,13 @@ public:
mSignalType = (SignalType) signalType;
}
+ void setAmplitude(float amplitude) override {
+ mAmplitude = amplitude;
+ if (mVolumeRamp) {
+ mVolumeRamp->setTarget(mAmplitude);
+ }
+ }
+
protected:
SignalType mSignalType = SignalType::Sine;
@@ -432,6 +458,10 @@ protected:
ExponentialShape mExponentialShape;
class WhiteNoise mWhiteNoise;
+ static constexpr int kRampMSec = 10; // for volume control
+ float mAmplitude = 1.0f;
+ std::shared_ptr<RampLinear> mVolumeRamp;
+
std::unique_ptr<ManyToMultiConverter> manyToMulti;
std::unique_ptr<MonoToMultiConverter> monoToMulti;
std::shared_ptr<oboe::flowgraph::SinkFloat> mSinkFloat;
@@ -449,7 +479,7 @@ public:
ActivityTapToTone() {}
virtual ~ActivityTapToTone() = default;
- void configureForStart() override;
+ void configureAfterOpen() override;
virtual void trigger() override {
sawPingGenerator.trigger();
@@ -505,6 +535,10 @@ public:
}
}
+ double getPeakLevel(int index) override {
+ return mFullDuplexEcho->getPeakLevel(index);
+ }
+
FullDuplexAnalyzer *getFullDuplexAnalyzer() override {
return (FullDuplexAnalyzer *) mFullDuplexEcho.get();
}
@@ -643,7 +677,8 @@ public:
void configureBuilder(bool isInput, oboe::AudioStreamBuilder &builder) override;
- void configureForStart() override {
+ void configureAfterOpen() override {
+ // set buffer size
std::shared_ptr<oboe::AudioStream> outputStream = getOutputStream();
int32_t capacityInFrames = outputStream->getBufferCapacityInFrames();
int32_t burstInFrames = outputStream->getFramesPerBurst();
@@ -697,7 +732,7 @@ public:
return oboe::Result::ErrorNull;
}
- void configureForStart() override;
+ void configureAfterOpen() override;
private:
std::unique_ptr<SineOscillator> sineOscillator;
@@ -706,7 +741,8 @@ private:
};
/**
- * Switch between various
+ * Global context for native tests.
+ * Switch between various ActivityContexts.
*/
class NativeAudioContext {
public:
@@ -764,7 +800,6 @@ public:
ActivityDataPath mActivityDataPath;
ActivityTestDisconnect mActivityTestDisconnect;
-
private:
// WARNING - must match definitions in TestAudioActivity.java
@@ -783,7 +818,6 @@ private:
ActivityType mActivityType = ActivityType::Undefined;
ActivityContext *currentActivity = &mActivityTestOutput;
-
};
#endif //NATIVEOBOE_NATIVEAUDIOCONTEXT_H