Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (C) 2014 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 ANDROID_MEDIA_AUDIOFORMAT_H
     18 #define ANDROID_MEDIA_AUDIOFORMAT_H
     19 
     20 #include <system/audio.h>
     21 
     22 // keep these values in sync with AudioFormat.java
     23 #define ENCODING_PCM_16BIT  2
     24 #define ENCODING_PCM_8BIT   3
     25 #define ENCODING_PCM_FLOAT  4
     26 #define ENCODING_AC3        5
     27 #define ENCODING_E_AC3      6
     28 #define ENCODING_INVALID    0
     29 #define ENCODING_DEFAULT    1
     30 
     31 
     32 
     33 #define CHANNEL_INVALID 0
     34 #define CHANNEL_OUT_DEFAULT 1
     35 
     36 static inline audio_format_t audioFormatToNative(int audioFormat)
     37 {
     38     switch (audioFormat) {
     39     case ENCODING_PCM_16BIT:
     40         return AUDIO_FORMAT_PCM_16_BIT;
     41     case ENCODING_PCM_8BIT:
     42         return AUDIO_FORMAT_PCM_8_BIT;
     43     case ENCODING_PCM_FLOAT:
     44         return AUDIO_FORMAT_PCM_FLOAT;
     45     case ENCODING_AC3:
     46         return AUDIO_FORMAT_AC3;
     47     case ENCODING_E_AC3:
     48         return AUDIO_FORMAT_E_AC3;
     49     case ENCODING_DEFAULT:
     50         return AUDIO_FORMAT_DEFAULT;
     51     default:
     52         return AUDIO_FORMAT_INVALID;
     53     }
     54 }
     55 
     56 static inline int audioFormatFromNative(audio_format_t nativeFormat)
     57 {
     58     switch (nativeFormat) {
     59     case AUDIO_FORMAT_PCM_16_BIT:
     60         return ENCODING_PCM_16BIT;
     61     case AUDIO_FORMAT_PCM_8_BIT:
     62         return ENCODING_PCM_8BIT;
     63     case AUDIO_FORMAT_PCM_FLOAT:
     64         return ENCODING_PCM_FLOAT;
     65     case AUDIO_FORMAT_AC3:
     66         return ENCODING_AC3;
     67     case AUDIO_FORMAT_E_AC3:
     68         return ENCODING_E_AC3;
     69     case AUDIO_FORMAT_DEFAULT:
     70         return ENCODING_DEFAULT;
     71     default:
     72         return ENCODING_INVALID;
     73     }
     74 }
     75 
     76 static inline audio_channel_mask_t outChannelMaskToNative(int channelMask)
     77 {
     78     switch (channelMask) {
     79     case CHANNEL_OUT_DEFAULT:
     80     case CHANNEL_INVALID:
     81         return AUDIO_CHANNEL_NONE;
     82     default:
     83         return (audio_channel_mask_t)(channelMask>>2);
     84     }
     85 }
     86 
     87 static inline int outChannelMaskFromNative(audio_channel_mask_t nativeMask)
     88 {
     89     switch (nativeMask) {
     90     case AUDIO_CHANNEL_NONE:
     91         return CHANNEL_OUT_DEFAULT;
     92     default:
     93         return (int)nativeMask<<2;
     94     }
     95 }
     96 
     97 static inline audio_channel_mask_t inChannelMaskToNative(int channelMask)
     98 {
     99     return (audio_channel_mask_t)channelMask;
    100 }
    101 
    102 static inline int inChannelMaskFromNative(audio_channel_mask_t nativeMask)
    103 {
    104     return (int)nativeMask;
    105 }
    106 
    107 #endif // ANDROID_MEDIA_AUDIOFORMAT_H
    108