Home | History | Annotate | Download | only in g711
      1 /*
      2  *  Copyright (c) 2015 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_coding/codecs/g711/audio_decoder_pcm.h"
     12 
     13 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h"
     14 
     15 namespace webrtc {
     16 
     17 void AudioDecoderPcmU::Reset() {}
     18 
     19 size_t AudioDecoderPcmU::Channels() const {
     20   return num_channels_;
     21 }
     22 
     23 int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded,
     24                                      size_t encoded_len,
     25                                      int sample_rate_hz,
     26                                      int16_t* decoded,
     27                                      SpeechType* speech_type) {
     28   RTC_DCHECK_EQ(sample_rate_hz, 8000);
     29   int16_t temp_type = 1;  // Default is speech.
     30   size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type);
     31   *speech_type = ConvertSpeechType(temp_type);
     32   return static_cast<int>(ret);
     33 }
     34 
     35 int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded,
     36                                      size_t encoded_len) const {
     37   // One encoded byte per sample per channel.
     38   return static_cast<int>(encoded_len / Channels());
     39 }
     40 
     41 void AudioDecoderPcmA::Reset() {}
     42 
     43 size_t AudioDecoderPcmA::Channels() const {
     44   return num_channels_;
     45 }
     46 
     47 int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded,
     48                                      size_t encoded_len,
     49                                      int sample_rate_hz,
     50                                      int16_t* decoded,
     51                                      SpeechType* speech_type) {
     52   RTC_DCHECK_EQ(sample_rate_hz, 8000);
     53   int16_t temp_type = 1;  // Default is speech.
     54   size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type);
     55   *speech_type = ConvertSpeechType(temp_type);
     56   return static_cast<int>(ret);
     57 }
     58 
     59 int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded,
     60                                      size_t encoded_len) const {
     61   // One encoded byte per sample per channel.
     62   return static_cast<int>(encoded_len / Channels());
     63 }
     64 
     65 }  // namespace webrtc
     66