blob: da1e25483c93ea8607a185731a04736ef3725c1b [file] [log] [blame]
henrike@webrtc.org82f014a2013-09-10 18:24:07 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/audio_device/android/opensles_common.h"
12
13#include <assert.h>
14
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +000015#include "webrtc/modules/audio_device/android/audio_common.h"
16
17using webrtc::kNumChannels;
18
henrikab2619892015-05-18 16:49:16 +020019namespace webrtc {
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000020
21SLDataFormat_PCM CreatePcmConfiguration(int sample_rate) {
22 SLDataFormat_PCM configuration;
23 configuration.formatType = SL_DATAFORMAT_PCM;
24 configuration.numChannels = kNumChannels;
25 // According to the opensles documentation in the ndk:
26 // samplesPerSec is actually in units of milliHz, despite the misleading name.
27 // It further recommends using constants. However, this would lead to a lot
28 // of boilerplate code so it is not done here.
29 configuration.samplesPerSec = sample_rate * 1000;
30 configuration.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
31 configuration.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
32 configuration.channelMask = SL_SPEAKER_FRONT_CENTER;
33 if (2 == configuration.numChannels) {
34 configuration.channelMask =
35 SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
36 }
37 configuration.endianness = SL_BYTEORDER_LITTLEENDIAN;
38 return configuration;
39}
40
41} // namespace webrtc_opensl