Skip to content

Commit

Permalink
Merge pull request #46 from google/apiindex-rename
Browse files Browse the repository at this point in the history
Rename ApiIndex to AudioApi, move into Definitions.h
  • Loading branch information
dturner authored Jan 18, 2018
2 parents 09c96e9 + 87f80e8 commit b79b1d7
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 88 deletions.
9 changes: 4 additions & 5 deletions include/oboe/AudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class AudioStream : public AudioStreamBase {
virtual StreamState getState() = 0;

/**
* Wait until the current state no longer matches the input state.
* The current state is passed to avoid race conditions caused by the state
* Wait until the stream's current state no longer matches the input state.
* The input state is passed to avoid race conditions caused by the state
* changing between calls.
*
* Note that generally applications do not need to call this. It is considered
Expand All @@ -95,13 +95,12 @@ class AudioStream : public AudioStreamBase {
* }
* </code></pre>
*
* @param stream A handle provided by OboeStreamBuilder_openStream()
* @param currentState The state we want to avoid.
* @param inputState The state we want to avoid.
* @param nextState Pointer to a variable that will be set to the new state.
* @param timeoutNanoseconds The maximum time to wait in nanoseconds.
* @return Result::OK or a Result::Error.
*/
virtual Result waitForStateChange(StreamState currentState,
virtual Result waitForStateChange(StreamState inputState,
StreamState *nextState,
int64_t timeoutNanoseconds) = 0;

Expand Down
24 changes: 3 additions & 21 deletions include/oboe/AudioStreamBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ class AudioStreamBuilder : public AudioStreamBase {

AudioStreamBuilder() : AudioStreamBase() {}

enum class AudioApi {
/**
* Try to use AAudio. If not available then use OpenSL ES.
*/
Unspecified,

/**
* Use OpenSL ES.
*/
OpenSLES,

/**
* Try to use AAudio. Fail if unavailable.
*/
AAudio
};


/**
* Request a specific number of channels.
*
Expand Down Expand Up @@ -131,16 +113,16 @@ class AudioStreamBuilder : public AudioStreamBase {
return this;
}

AudioApi getApiIndex() const { return mAudioApi; }
AudioApi getAudioApi() const { return mAudioApi; }

/**
* Normally you would leave this unspecified, and Oboe will chose the best API
* for the device at runtime.
* @param Must be AudioApi::Unspecified, AudioApi::OpenSLES or AudioApi::AAudio.
* @return pointer to the builder so calls can be chained
*/
AudioStreamBuilder *setApiIndex(AudioApi apiIndex) {
mAudioApi = apiIndex;
AudioStreamBuilder *setAudioApi(AudioApi audioApi) {
mAudioApi = audioApi;
return this;
}

Expand Down
18 changes: 18 additions & 0 deletions include/oboe/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ namespace oboe {
// Reducing latency is most important.
LowLatency = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
};

enum class AudioApi : int32_t {
/**
* Try to use AAudio. If not available then use OpenSL ES.
*/
Unspecified = kUnspecified,

/**
* Use OpenSL ES.
*/
OpenSLES,

/**
* Try to use AAudio. Fail if unavailable.
*/
AAudio
};

} // namespace oboe

#endif // OBOE_DEFINITIONS_H
124 changes: 62 additions & 62 deletions src/common/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#include "oboe/Definitions.h"
#include "oboe/Utilities.h"

// TODO: Return the int value as well as the name
#define OBOE_CASE_ENUM(name) case name: return #name

namespace oboe {

constexpr float kScaleI16ToFloat = (1.0f / 32768.0f);
Expand Down Expand Up @@ -64,102 +61,105 @@ int32_t convertFormatToSizeInBytes(AudioFormat format) {
template<>
const char *convertToText<Result>(Result returnCode) {
switch (returnCode) {
OBOE_CASE_ENUM(Result::OK);
OBOE_CASE_ENUM(Result::ErrorDisconnected);
OBOE_CASE_ENUM(Result::ErrorIllegalArgument);
OBOE_CASE_ENUM(Result::ErrorInternal);
OBOE_CASE_ENUM(Result::ErrorInvalidState);
OBOE_CASE_ENUM(Result::ErrorInvalidHandle);
OBOE_CASE_ENUM(Result::ErrorUnimplemented);
OBOE_CASE_ENUM(Result::ErrorUnavailable);
OBOE_CASE_ENUM(Result::ErrorNoFreeHandles);
OBOE_CASE_ENUM(Result::ErrorNoMemory);
OBOE_CASE_ENUM(Result::ErrorNull);
OBOE_CASE_ENUM(Result::ErrorTimeout);
OBOE_CASE_ENUM(Result::ErrorWouldBlock);
OBOE_CASE_ENUM(Result::ErrorInvalidFormat);
OBOE_CASE_ENUM(Result::ErrorOutOfRange);
OBOE_CASE_ENUM(Result::ErrorNoService);
OBOE_CASE_ENUM(Result::ErrorInvalidRate);
default:
return "Unrecognized result";
case Result::OK: return "OK";
case Result::ErrorDisconnected: return "ErrorDisconnected";
case Result::ErrorIllegalArgument: return "ErrorIllegalArgument";
case Result::ErrorInternal: return "ErrorInternal";
case Result::ErrorInvalidState: return "ErrorInvalidState";
case Result::ErrorInvalidHandle: return "ErrorInvalidHandle";
case Result::ErrorUnimplemented: return "ErrorUnimplemented";
case Result::ErrorUnavailable: return "ErrorUnavailable";
case Result::ErrorNoFreeHandles: return "ErrorNoFreeHandles";
case Result::ErrorNoMemory: return "ErrorNoMemory";
case Result::ErrorNull: return "ErrorNull";
case Result::ErrorTimeout: return "ErrorTimeout";
case Result::ErrorWouldBlock: return "ErrorWouldBlock";
case Result::ErrorInvalidFormat: return "ErrorInvalidFormat";
case Result::ErrorOutOfRange: return "ErrorOutOfRange";
case Result::ErrorNoService: return "ErrorNoService";
case Result::ErrorInvalidRate: return "ErrorInvalidRate";
default: return "Unrecognized result";
}
}

template<>
const char *convertToText<AudioFormat>(AudioFormat format) {
switch (format) {
OBOE_CASE_ENUM(AudioFormat::Invalid);
OBOE_CASE_ENUM(AudioFormat::Unspecified);
OBOE_CASE_ENUM(AudioFormat::I16);
OBOE_CASE_ENUM(AudioFormat::Float);
default:
return "Unrecognized format";
case AudioFormat::Invalid: return "Invalid";
case AudioFormat::Unspecified: return "Unspecified";
case AudioFormat::I16: return "I16";
case AudioFormat::Float: return "Float";
default: return "Unrecognized format";
}
}

template<>
const char *convertToText<PerformanceMode>(PerformanceMode mode) {
switch (mode) {
OBOE_CASE_ENUM(PerformanceMode::LowLatency);
OBOE_CASE_ENUM(PerformanceMode::None);
OBOE_CASE_ENUM(PerformanceMode::PowerSaving);
default:
return "Unrecognized performance mode";
case PerformanceMode::LowLatency: return "LowLatency";
case PerformanceMode::None: return "None";
case PerformanceMode::PowerSaving: return "PowerSaving";
default: return "Unrecognized performance mode";
}
}

template<>
const char *convertToText<SharingMode>(SharingMode mode) {
switch (mode) {
OBOE_CASE_ENUM(SharingMode::Exclusive);
OBOE_CASE_ENUM(SharingMode::Shared);
default:
return "Unrecognized sharing mode";
case SharingMode::Exclusive: return "Exclusive";
case SharingMode::Shared: return "Shared";
default: return "Unrecognized sharing mode";
}
}

template<>
const char *convertToText<DataCallbackResult>(DataCallbackResult result) {
switch (result) {
OBOE_CASE_ENUM(DataCallbackResult::Continue);
OBOE_CASE_ENUM(DataCallbackResult::Stop);
default:
return "Unrecognized data callback result";
case DataCallbackResult::Continue: return "Continue";
case DataCallbackResult::Stop: return "Stop";
default: return "Unrecognized data callback result";
}
}

template<>
const char *convertToText<Direction>(Direction direction) {
switch (direction) {
OBOE_CASE_ENUM(Direction::Input);
OBOE_CASE_ENUM(Direction::Output);
default:
return "Unrecognized direction";
case Direction::Input: return "Input";
case Direction::Output: return "Output";
default: return "Unrecognized direction";
}
}

template<>
const char *convertToText<StreamState>(StreamState state) {
switch (state) {
OBOE_CASE_ENUM(StreamState::Closed);
OBOE_CASE_ENUM(StreamState::Closing);
OBOE_CASE_ENUM(StreamState::Disconnected);
OBOE_CASE_ENUM(StreamState::Flushed);
OBOE_CASE_ENUM(StreamState::Flushing);
OBOE_CASE_ENUM(StreamState::Open);
OBOE_CASE_ENUM(StreamState::Paused);
OBOE_CASE_ENUM(StreamState::Pausing);
OBOE_CASE_ENUM(StreamState::Started);
OBOE_CASE_ENUM(StreamState::Starting);
OBOE_CASE_ENUM(StreamState::Stopped);
OBOE_CASE_ENUM(StreamState::Stopping);
OBOE_CASE_ENUM(StreamState::Uninitialized);
OBOE_CASE_ENUM(StreamState::Unknown);
default:
return "Unrecognized stream state";
case StreamState::Closed: return "Closed";
case StreamState::Closing: return "Closing";
case StreamState::Disconnected: return "Disconnected";
case StreamState::Flushed: return "Flushed";
case StreamState::Flushing: return "Flushing";
case StreamState::Open: return "Open";
case StreamState::Paused: return "Paused";
case StreamState::Pausing: return "Pausing";
case StreamState::Started: return "Started";
case StreamState::Starting: return "Starting";
case StreamState::Stopped: return "Stopped";
case StreamState::Stopping: return "Stopping";
case StreamState::Uninitialized: return "Uninitialized";
case StreamState::Unknown: return "Unknown";
default: return "Unrecognized stream state";
}
}

template<>
const char *convertToText<AudioApi >(AudioApi audioApi) {

switch (audioApi) {
case AudioApi::Unspecified: return "Unspecified";
case AudioApi::OpenSLES: return "OpenSLES";
case AudioApi::AAudio: return "AAudio";
default: return "Unrecognised audio API";
}
}

} // namespace oboe
}// namespace oboe

0 comments on commit b79b1d7

Please sign in to comment.