• 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     aaudio_format_t getFormat() const {
60         return mAudioFormat;
61     }
62 
setFormat(aaudio_format_t audioFormat)63     void setFormat(aaudio_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 
calculateBytesPerFrame()91     int32_t calculateBytesPerFrame() const {
92         return getSamplesPerFrame() * AAudioConvert_formatToSizeInBytes(getFormat());
93     }
94 
95     /**
96      * Copy variables defined in other AAudioStreamParameters instance to this one.
97      * @param other
98      */
99     void copyFrom(const AAudioStreamParameters &other);
100 
101     virtual aaudio_result_t validate() const;
102 
103     void dump() const;
104 
105 private:
106     int32_t                    mSamplesPerFrame = AAUDIO_UNSPECIFIED;
107     int32_t                    mSampleRate      = AAUDIO_UNSPECIFIED;
108     int32_t                    mDeviceId        = AAUDIO_UNSPECIFIED;
109     aaudio_sharing_mode_t      mSharingMode     = AAUDIO_SHARING_MODE_SHARED;
110     aaudio_format_t            mAudioFormat     = AAUDIO_FORMAT_UNSPECIFIED;
111     aaudio_direction_t         mDirection       = AAUDIO_DIRECTION_OUTPUT;
112     int32_t                    mBufferCapacity  = AAUDIO_UNSPECIFIED;
113 };
114 
115 } /* namespace aaudio */
116 
117 #endif //AAUDIO_STREAM_PARAMETERS_H
118