AudioStreamBuilder.h revision a4eb0d86a29be2763be5fac51727858d5095794b
1/* 2 * Copyright 2015 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 AAUDIO_AUDIO_STREAM_BUILDER_H 18#define AAUDIO_AUDIO_STREAM_BUILDER_H 19 20#include <stdint.h> 21 22#include <aaudio/AAudio.h> 23 24#include "AudioStream.h" 25 26namespace aaudio { 27 28/** 29 * Factory class for an AudioStream. 30 */ 31class AudioStreamBuilder { 32public: 33 AudioStreamBuilder(); 34 35 ~AudioStreamBuilder(); 36 37 int getSamplesPerFrame() const { 38 return mSamplesPerFrame; 39 } 40 41 /** 42 * This is also known as channelCount. 43 */ 44 AudioStreamBuilder* setSamplesPerFrame(int samplesPerFrame) { 45 mSamplesPerFrame = samplesPerFrame; 46 return this; 47 } 48 49 aaudio_direction_t getDirection() const { 50 return mDirection; 51 } 52 53 AudioStreamBuilder* setDirection(aaudio_direction_t direction) { 54 mDirection = direction; 55 return this; 56 } 57 58 int32_t getSampleRate() const { 59 return mSampleRate; 60 } 61 62 AudioStreamBuilder* setSampleRate(int32_t sampleRate) { 63 mSampleRate = sampleRate; 64 return this; 65 } 66 67 aaudio_audio_format_t getFormat() const { 68 return mFormat; 69 } 70 71 AudioStreamBuilder *setFormat(aaudio_audio_format_t format) { 72 mFormat = format; 73 return this; 74 } 75 76 aaudio_sharing_mode_t getSharingMode() const { 77 return mSharingMode; 78 } 79 80 AudioStreamBuilder* setSharingMode(aaudio_sharing_mode_t sharingMode) { 81 mSharingMode = sharingMode; 82 return this; 83 } 84 85 int32_t getBufferCapacity() const { 86 return mBufferCapacity; 87 } 88 89 AudioStreamBuilder* setBufferCapacity(int32_t frames) { 90 mBufferCapacity = frames; 91 return this; 92 } 93 94 int32_t getDeviceId() const { 95 return mDeviceId; 96 } 97 98 AudioStreamBuilder* setDeviceId(int32_t deviceId) { 99 mDeviceId = deviceId; 100 return this; 101 } 102 103 AAudioStream_dataCallback getDataCallbackProc() const { 104 return mDataCallbackProc; 105 } 106 107 AudioStreamBuilder* setDataCallbackProc(AAudioStream_dataCallback proc) { 108 mDataCallbackProc = proc; 109 return this; 110 } 111 112 113 void *getDataCallbackUserData() const { 114 return mDataCallbackUserData; 115 } 116 117 AudioStreamBuilder* setDataCallbackUserData(void *userData) { 118 mDataCallbackUserData = userData; 119 return this; 120 } 121 122 AAudioStream_errorCallback getErrorCallbackProc() const { 123 return mErrorCallbackProc; 124 } 125 126 AudioStreamBuilder* setErrorCallbackProc(AAudioStream_errorCallback proc) { 127 mErrorCallbackProc = proc; 128 return this; 129 } 130 131 AudioStreamBuilder* setErrorCallbackUserData(void *userData) { 132 mErrorCallbackUserData = userData; 133 return this; 134 } 135 136 void *getErrorCallbackUserData() const { 137 return mErrorCallbackUserData; 138 } 139 140 int32_t getFramesPerDataCallback() const { 141 return mFramesPerDataCallback; 142 } 143 144 AudioStreamBuilder* setFramesPerDataCallback(int32_t sizeInFrames) { 145 mFramesPerDataCallback = sizeInFrames; 146 return this; 147 } 148 149 aaudio_result_t build(AudioStream **streamPtr); 150 151private: 152 int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED; 153 int32_t mSampleRate = AAUDIO_UNSPECIFIED; 154 int32_t mDeviceId = AAUDIO_DEVICE_UNSPECIFIED; 155 aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED; 156 aaudio_audio_format_t mFormat = AAUDIO_FORMAT_UNSPECIFIED; 157 aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; 158 int32_t mBufferCapacity = AAUDIO_UNSPECIFIED; 159 160 AAudioStream_dataCallback mDataCallbackProc = nullptr; // external callback functions 161 void *mDataCallbackUserData = nullptr; 162 int32_t mFramesPerDataCallback = AAUDIO_UNSPECIFIED; // frames 163 164 AAudioStream_errorCallback mErrorCallbackProc = nullptr; 165 void *mErrorCallbackUserData = nullptr; 166}; 167 168} /* namespace aaudio */ 169 170#endif //AAUDIO_AUDIO_STREAM_BUILDER_H 171