Home | History | Annotate | Download | only in android
      1 /*
      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 
     15 #include "webrtc/modules/audio_device/android/audio_common.h"
     16 
     17 using webrtc::kNumChannels;
     18 
     19 namespace webrtc_opensl {
     20 
     21 SLDataFormat_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
     42