blob: be70e44de5b00f8ee020871fc2c89655426c0133 [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
15namespace webrtc_opensl {
16
17SLDataFormat_PCM CreatePcmConfiguration(int sample_rate) {
18 SLDataFormat_PCM configuration;
19 configuration.formatType = SL_DATAFORMAT_PCM;
20 configuration.numChannels = kNumChannels;
21 // According to the opensles documentation in the ndk:
22 // samplesPerSec is actually in units of milliHz, despite the misleading name.
23 // It further recommends using constants. However, this would lead to a lot
24 // of boilerplate code so it is not done here.
25 configuration.samplesPerSec = sample_rate * 1000;
26 configuration.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
27 configuration.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
28 configuration.channelMask = SL_SPEAKER_FRONT_CENTER;
29 if (2 == configuration.numChannels) {
30 configuration.channelMask =
31 SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
32 }
33 configuration.endianness = SL_BYTEORDER_LITTLEENDIAN;
34 return configuration;
35}
36
37} // namespace webrtc_opensl