blob: 807dd32762bb7a819de28ede6377ce6a92584589 [file] [log] [blame]
Glenn Kastenfe834d32014-01-08 14:49:08 -08001/*
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
Eric Laurentff0d9f02014-06-09 17:23:02 -070023#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
Eric Laurentb69681c2014-05-19 19:02:51 -070032
33#define CHANNEL_INVALID 0
34#define CHANNEL_OUT_DEFAULT 1
Glenn Kastenfe834d32014-01-08 14:49:08 -080035
36static 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;
Glenn Kasten313f5982014-04-30 18:02:08 -070043 case ENCODING_PCM_FLOAT:
44 return AUDIO_FORMAT_PCM_FLOAT;
Eric Laurentff0d9f02014-06-09 17:23:02 -070045 case ENCODING_AC3:
46 return AUDIO_FORMAT_AC3;
47 case ENCODING_E_AC3:
48 return AUDIO_FORMAT_E_AC3;
Eric Laurentb69681c2014-05-19 19:02:51 -070049 case ENCODING_DEFAULT:
50 return AUDIO_FORMAT_DEFAULT;
Glenn Kastenfe834d32014-01-08 14:49:08 -080051 default:
52 return AUDIO_FORMAT_INVALID;
53 }
54}
55
Eric Laurentb69681c2014-05-19 19:02:51 -070056static 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;
Eric Laurentff0d9f02014-06-09 17:23:02 -070065 case AUDIO_FORMAT_AC3:
66 return ENCODING_AC3;
67 case AUDIO_FORMAT_E_AC3:
68 return ENCODING_E_AC3;
Eric Laurentb69681c2014-05-19 19:02:51 -070069 case AUDIO_FORMAT_DEFAULT:
70 return ENCODING_DEFAULT;
71 default:
72 return ENCODING_INVALID;
73 }
74}
75
76static 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
87static 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
97static inline audio_channel_mask_t inChannelMaskToNative(int channelMask)
98{
99 return (audio_channel_mask_t)channelMask;
100}
101
102static inline int inChannelMaskFromNative(audio_channel_mask_t nativeMask)
103{
104 return (int)nativeMask;
105}
106
Glenn Kastenfe834d32014-01-08 14:49:08 -0800107#endif // ANDROID_MEDIA_AUDIOFORMAT_H