AudioStreamBuilder.h revision 3316d5e6d375a4f09c681205e9094d30a0bfc4a2
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_AUDIOSTREAMBUILDER_H 18#define AAUDIO_AUDIOSTREAMBUILDER_H 19 20#include <stdint.h> 21 22#include <aaudio/AAudioDefinitions.h> 23#include <aaudio/AAudio.h> 24 25#include "AudioStream.h" 26 27namespace aaudio { 28 29/** 30 * Factory class for an AudioStream. 31 */ 32class AudioStreamBuilder { 33public: 34 AudioStreamBuilder(); 35 36 ~AudioStreamBuilder(); 37 38 int getSamplesPerFrame() const { 39 return mSamplesPerFrame; 40 } 41 42 /** 43 * This is also known as channelCount. 44 */ 45 AudioStreamBuilder* setSamplesPerFrame(int samplesPerFrame) { 46 mSamplesPerFrame = samplesPerFrame; 47 return this; 48 } 49 50 aaudio_direction_t getDirection() const { 51 return mDirection; 52 } 53 54 AudioStreamBuilder* setDirection(aaudio_direction_t direction) { 55 mDirection = direction; 56 return this; 57 } 58 59 int32_t getSampleRate() const { 60 return mSampleRate; 61 } 62 63 AudioStreamBuilder* setSampleRate(int32_t sampleRate) { 64 mSampleRate = sampleRate; 65 return this; 66 } 67 68 aaudio_audio_format_t getFormat() const { 69 return mFormat; 70 } 71 72 AudioStreamBuilder *setFormat(aaudio_audio_format_t format) { 73 mFormat = format; 74 return this; 75 } 76 77 aaudio_sharing_mode_t getSharingMode() const { 78 return mSharingMode; 79 } 80 81 AudioStreamBuilder* setSharingMode(aaudio_sharing_mode_t sharingMode) { 82 mSharingMode = sharingMode; 83 return this; 84 } 85 86 int32_t getBufferCapacity() const { 87 return mBufferCapacity; 88 } 89 90 AudioStreamBuilder* setBufferCapacity(int32_t frames) { 91 mBufferCapacity = frames; 92 return this; 93 } 94 95 int32_t getDeviceId() const { 96 return mDeviceId; 97 } 98 99 AudioStreamBuilder* setDeviceId(int32_t deviceId) { 100 mDeviceId = deviceId; 101 return this; 102 } 103 104 aaudio_result_t build(AudioStream **streamPtr); 105 106private: 107 int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED; 108 int32_t mSampleRate = AAUDIO_UNSPECIFIED; 109 int32_t mDeviceId = AAUDIO_DEVICE_UNSPECIFIED; 110 aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED; 111 aaudio_audio_format_t mFormat = AAUDIO_FORMAT_UNSPECIFIED; 112 aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; 113 int32_t mBufferCapacity = AAUDIO_UNSPECIFIED; 114}; 115 116} /* namespace aaudio */ 117 118#endif /* AAUDIO_AUDIOSTREAMBUILDER_H */ 119