Home | History | Annotate | Download | only in core
      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 
     32     int32_t getDeviceId() const {
     33         return mDeviceId;
     34     }
     35 
     36     void setDeviceId(int32_t deviceId) {
     37         mDeviceId = deviceId;
     38     }
     39 
     40     int32_t getSampleRate() const {
     41         return mSampleRate;
     42     }
     43 
     44     void setSampleRate(int32_t sampleRate) {
     45         mSampleRate = sampleRate;
     46     }
     47 
     48     int32_t getSamplesPerFrame() const {
     49         return mSamplesPerFrame;
     50     }
     51 
     52     /**
     53      * This is also known as channelCount.
     54      */
     55     void setSamplesPerFrame(int32_t samplesPerFrame) {
     56         mSamplesPerFrame = samplesPerFrame;
     57     }
     58 
     59     aaudio_format_t getFormat() const {
     60         return mAudioFormat;
     61     }
     62 
     63     void setFormat(aaudio_format_t audioFormat) {
     64         mAudioFormat = audioFormat;
     65     }
     66 
     67     aaudio_sharing_mode_t getSharingMode() const {
     68         return mSharingMode;
     69     }
     70 
     71     void setSharingMode(aaudio_sharing_mode_t sharingMode) {
     72         mSharingMode = sharingMode;
     73     }
     74 
     75     int32_t getBufferCapacity() const {
     76         return mBufferCapacity;
     77     }
     78 
     79     void setBufferCapacity(int32_t frames) {
     80         mBufferCapacity = frames;
     81     }
     82 
     83     aaudio_direction_t getDirection() const {
     84         return mDirection;
     85     }
     86 
     87     void setDirection(aaudio_direction_t direction) {
     88         mDirection = direction;
     89     }
     90 
     91     aaudio_usage_t getUsage() const {
     92         return mUsage;
     93     }
     94 
     95     void setUsage(aaudio_usage_t usage) {
     96         mUsage = usage;
     97     }
     98 
     99     aaudio_content_type_t getContentType() const {
    100         return mContentType;
    101     }
    102 
    103     void setContentType(aaudio_content_type_t contentType) {
    104         mContentType = contentType;
    105     }
    106 
    107     aaudio_input_preset_t getInputPreset() const {
    108         return mInputPreset;
    109     }
    110 
    111     void setInputPreset(aaudio_input_preset_t inputPreset) {
    112         mInputPreset = inputPreset;
    113     }
    114 
    115     aaudio_session_id_t getSessionId() const {
    116         return mSessionId;
    117     }
    118 
    119     void setSessionId(aaudio_session_id_t sessionId) {
    120         mSessionId = sessionId;
    121     }
    122 
    123     int32_t calculateBytesPerFrame() const {
    124         return getSamplesPerFrame() * AAudioConvert_formatToSizeInBytes(getFormat());
    125     }
    126 
    127     /**
    128      * Copy variables defined in other AAudioStreamParameters instance to this one.
    129      * @param other
    130      */
    131     void copyFrom(const AAudioStreamParameters &other);
    132 
    133     virtual aaudio_result_t validate() const;
    134 
    135     void dump() const;
    136 
    137 private:
    138     int32_t                    mSamplesPerFrame = AAUDIO_UNSPECIFIED;
    139     int32_t                    mSampleRate      = AAUDIO_UNSPECIFIED;
    140     int32_t                    mDeviceId        = AAUDIO_UNSPECIFIED;
    141     aaudio_sharing_mode_t      mSharingMode     = AAUDIO_SHARING_MODE_SHARED;
    142     aaudio_format_t            mAudioFormat     = AAUDIO_FORMAT_UNSPECIFIED;
    143     aaudio_direction_t         mDirection       = AAUDIO_DIRECTION_OUTPUT;
    144     aaudio_usage_t             mUsage           = AAUDIO_UNSPECIFIED;
    145     aaudio_content_type_t      mContentType     = AAUDIO_UNSPECIFIED;
    146     aaudio_input_preset_t      mInputPreset     = AAUDIO_UNSPECIFIED;
    147     int32_t                    mBufferCapacity  = AAUDIO_UNSPECIFIED;
    148     aaudio_session_id_t        mSessionId       = AAUDIO_SESSION_ID_NONE;
    149 };
    150 
    151 } /* namespace aaudio */
    152 
    153 #endif //AAUDIO_STREAM_PARAMETERS_H
    154