• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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_STREAM_PARAMETERS_H
18 #define AAUDIO_STREAM_PARAMETERS_H
19 
20 #include <stdint.h>
21 
22 #include <aaudio/AAudio.h>
23 #include <utility/AAudioUtilities.h>
24 
25 namespace aaudio {
26 
27 class AAudioStreamParameters {
28 public:
29     AAudioStreamParameters();
30     virtual ~AAudioStreamParameters();
31 
getDeviceId()32     int32_t getDeviceId() const {
33         return mDeviceId;
34     }
35 
setDeviceId(int32_t deviceId)36     void setDeviceId(int32_t deviceId) {
37         mDeviceId = deviceId;
38     }
39 
getSampleRate()40     int32_t getSampleRate() const {
41         return mSampleRate;
42     }
43 
setSampleRate(int32_t sampleRate)44     void setSampleRate(int32_t sampleRate) {
45         mSampleRate = sampleRate;
46     }
47 
getSamplesPerFrame()48     int32_t getSamplesPerFrame() const {
49         return mSamplesPerFrame;
50     }
51 
52     /**
53      * This is also known as channelCount.
54      */
setSamplesPerFrame(int32_t samplesPerFrame)55     void setSamplesPerFrame(int32_t samplesPerFrame) {
56         mSamplesPerFrame = samplesPerFrame;
57     }
58 
getFormat()59     audio_format_t getFormat() const {
60         return mAudioFormat;
61     }
62 
setFormat(audio_format_t audioFormat)63     void setFormat(audio_format_t audioFormat) {
64         mAudioFormat = audioFormat;
65     }
66 
getSharingMode()67     aaudio_sharing_mode_t getSharingMode() const {
68         return mSharingMode;
69     }
70 
setSharingMode(aaudio_sharing_mode_t sharingMode)71     void setSharingMode(aaudio_sharing_mode_t sharingMode) {
72         mSharingMode = sharingMode;
73     }
74 
getBufferCapacity()75     int32_t getBufferCapacity() const {
76         return mBufferCapacity;
77     }
78 
setBufferCapacity(int32_t frames)79     void setBufferCapacity(int32_t frames) {
80         mBufferCapacity = frames;
81     }
82 
getDirection()83     aaudio_direction_t getDirection() const {
84         return mDirection;
85     }
86 
setDirection(aaudio_direction_t direction)87     void setDirection(aaudio_direction_t direction) {
88         mDirection = direction;
89     }
90 
getUsage()91     aaudio_usage_t getUsage() const {
92         return mUsage;
93     }
94 
setUsage(aaudio_usage_t usage)95     void setUsage(aaudio_usage_t usage) {
96         mUsage = usage;
97     }
98 
getContentType()99     aaudio_content_type_t getContentType() const {
100         return mContentType;
101     }
102 
setContentType(aaudio_content_type_t contentType)103     void setContentType(aaudio_content_type_t contentType) {
104         mContentType = contentType;
105     }
106 
getInputPreset()107     aaudio_input_preset_t getInputPreset() const {
108         return mInputPreset;
109     }
110 
setInputPreset(aaudio_input_preset_t inputPreset)111     void setInputPreset(aaudio_input_preset_t inputPreset) {
112         mInputPreset = inputPreset;
113     }
114 
getAllowedCapturePolicy()115     aaudio_allowed_capture_policy_t getAllowedCapturePolicy() const {
116         return mAllowedCapturePolicy;
117     }
118 
setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy)119     void setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy) {
120         mAllowedCapturePolicy = policy;
121     }
122 
getSessionId()123     aaudio_session_id_t getSessionId() const {
124         return mSessionId;
125     }
126 
setSessionId(aaudio_session_id_t sessionId)127     void setSessionId(aaudio_session_id_t sessionId) {
128         mSessionId = sessionId;
129     }
130 
131     /**
132      * @return bytes per frame of getFormat()
133      */
calculateBytesPerFrame()134     int32_t calculateBytesPerFrame() const {
135         return getSamplesPerFrame() * audio_bytes_per_sample(getFormat());
136     }
137 
138     /**
139      * Copy variables defined in other AAudioStreamParameters instance to this one.
140      * @param other
141      */
142     void copyFrom(const AAudioStreamParameters &other);
143 
144     virtual aaudio_result_t validate() const;
145 
146     void dump() const;
147 
148 private:
149     int32_t                         mSamplesPerFrame      = AAUDIO_UNSPECIFIED;
150     int32_t                         mSampleRate           = AAUDIO_UNSPECIFIED;
151     int32_t                         mDeviceId             = AAUDIO_UNSPECIFIED;
152     aaudio_sharing_mode_t           mSharingMode          = AAUDIO_SHARING_MODE_SHARED;
153     audio_format_t                  mAudioFormat          = AUDIO_FORMAT_DEFAULT;
154     aaudio_direction_t              mDirection            = AAUDIO_DIRECTION_OUTPUT;
155     aaudio_usage_t                  mUsage                = AAUDIO_UNSPECIFIED;
156     aaudio_content_type_t           mContentType          = AAUDIO_UNSPECIFIED;
157     aaudio_input_preset_t           mInputPreset          = AAUDIO_UNSPECIFIED;
158     int32_t                         mBufferCapacity       = AAUDIO_UNSPECIFIED;
159     aaudio_allowed_capture_policy_t mAllowedCapturePolicy = AAUDIO_UNSPECIFIED;
160     aaudio_session_id_t             mSessionId            = AAUDIO_SESSION_ID_NONE;
161 };
162 
163 } /* namespace aaudio */
164 
165 #endif //AAUDIO_STREAM_PARAMETERS_H
166