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 #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
12 #define MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
13
14 #include "rtc_base/checks.h"
15
16 namespace webrtc {
17
18 template <typename T>
IsOk()19 bool AudioDecoderIsacT<T>::Config::IsOk() const {
20 return (sample_rate_hz == 16000 || sample_rate_hz == 32000);
21 }
22
23 template <typename T>
AudioDecoderIsacT(const Config & config)24 AudioDecoderIsacT<T>::AudioDecoderIsacT(const Config& config)
25 : sample_rate_hz_(config.sample_rate_hz) {
26 RTC_CHECK(config.IsOk()) << "Unsupported sample rate "
27 << config.sample_rate_hz;
28 RTC_CHECK_EQ(0, T::Create(&isac_state_));
29 T::DecoderInit(isac_state_);
30 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz_));
31 }
32
33 template <typename T>
~AudioDecoderIsacT()34 AudioDecoderIsacT<T>::~AudioDecoderIsacT() {
35 RTC_CHECK_EQ(0, T::Free(isac_state_));
36 }
37
38 template <typename T>
DecodeInternal(const uint8_t * encoded,size_t encoded_len,int sample_rate_hz,int16_t * decoded,SpeechType * speech_type)39 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded,
40 size_t encoded_len,
41 int sample_rate_hz,
42 int16_t* decoded,
43 SpeechType* speech_type) {
44 RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz);
45 int16_t temp_type = 1; // Default is speech.
46 int ret =
47 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type);
48 *speech_type = ConvertSpeechType(temp_type);
49 return ret;
50 }
51
52 template <typename T>
HasDecodePlc()53 bool AudioDecoderIsacT<T>::HasDecodePlc() const {
54 return false;
55 }
56
57 template <typename T>
DecodePlc(size_t num_frames,int16_t * decoded)58 size_t AudioDecoderIsacT<T>::DecodePlc(size_t num_frames, int16_t* decoded) {
59 return T::DecodePlc(isac_state_, decoded, num_frames);
60 }
61
62 template <typename T>
Reset()63 void AudioDecoderIsacT<T>::Reset() {
64 T::DecoderInit(isac_state_);
65 }
66
67 template <typename T>
ErrorCode()68 int AudioDecoderIsacT<T>::ErrorCode() {
69 return T::GetErrorCode(isac_state_);
70 }
71
72 template <typename T>
SampleRateHz()73 int AudioDecoderIsacT<T>::SampleRateHz() const {
74 return sample_rate_hz_;
75 }
76
77 template <typename T>
Channels()78 size_t AudioDecoderIsacT<T>::Channels() const {
79 return 1;
80 }
81
82 } // namespace webrtc
83
84 #endif // MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
85