niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
Mirko Bonadei | bc3b782 | 2018-02-01 14:30:53 +0100 | [diff] [blame^] | 13 | |
| 14 | #include "modules/audio_coding/codecs/g722/g722_enc_dec.h" |
| 15 | #include "modules/audio_coding/codecs/g722/g722_interface.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 16 | #include "typedefs.h" // NOLINT(build/include) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 18 | int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | { |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 20 | *G722enc_inst=(G722EncInst*)malloc(sizeof(G722EncoderState)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | if (*G722enc_inst!=NULL) { |
| 22 | return(0); |
| 23 | } else { |
| 24 | return(-1); |
| 25 | } |
| 26 | } |
| 27 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 28 | int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | { |
| 30 | // Create and/or reset the G.722 encoder |
| 31 | // Bitrate 64 kbps and wideband mode (2) |
pwestin@webrtc.org | ebcb642 | 2011-12-22 12:20:06 +0000 | [diff] [blame] | 32 | G722enc_inst = (G722EncInst *) WebRtc_g722_encode_init( |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 33 | (G722EncoderState*) G722enc_inst, 64000, 2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | if (G722enc_inst == NULL) { |
| 35 | return -1; |
| 36 | } else { |
| 37 | return 0; |
| 38 | } |
| 39 | } |
| 40 | |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 41 | int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | { |
| 43 | // Free encoder memory |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 44 | return WebRtc_g722_encode_release((G722EncoderState*) G722enc_inst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 47 | size_t WebRtcG722_Encode(G722EncInst *G722enc_inst, |
| 48 | const int16_t* speechIn, |
| 49 | size_t len, |
| 50 | uint8_t* encoded) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | { |
| 52 | unsigned char *codechar = (unsigned char*) encoded; |
| 53 | // Encode the input speech vector |
Peter Kasting | 728d903 | 2015-06-11 14:31:38 -0700 | [diff] [blame] | 54 | return WebRtc_g722_encode((G722EncoderState*) G722enc_inst, codechar, |
| 55 | speechIn, len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | } |
| 57 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 58 | int16_t WebRtcG722_CreateDecoder(G722DecInst **G722dec_inst) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | { |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 60 | *G722dec_inst=(G722DecInst*)malloc(sizeof(G722DecoderState)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | if (*G722dec_inst!=NULL) { |
| 62 | return(0); |
| 63 | } else { |
| 64 | return(-1); |
| 65 | } |
| 66 | } |
| 67 | |
Karl Wiberg | 4376648 | 2015-08-27 15:22:11 +0200 | [diff] [blame] | 68 | void WebRtcG722_DecoderInit(G722DecInst* inst) { |
| 69 | // Create and/or reset the G.722 decoder |
| 70 | // Bitrate 64 kbps and wideband mode (2) |
| 71 | WebRtc_g722_decode_init((G722DecoderState*)inst, 64000, 2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 74 | int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | { |
| 76 | // Free encoder memory |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 77 | return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 80 | size_t WebRtcG722_Decode(G722DecInst *G722dec_inst, |
| 81 | const uint8_t *encoded, |
| 82 | size_t len, |
| 83 | int16_t *decoded, |
| 84 | int16_t *speechType) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | { |
| 86 | // Decode the G.722 encoder stream |
| 87 | *speechType=G722_WEBRTC_SPEECH; |
Peter Kasting | 728d903 | 2015-06-11 14:31:38 -0700 | [diff] [blame] | 88 | return WebRtc_g722_decode((G722DecoderState*) G722dec_inst, decoded, |
| 89 | encoded, len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | } |
| 91 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 92 | int16_t WebRtcG722_Version(char *versionStr, short len) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | { |
| 94 | // Get version string |
| 95 | char version[30] = "2.0.0\n"; |
| 96 | if (strlen(version) < (unsigned int)len) |
| 97 | { |
| 98 | strcpy(versionStr, version); |
| 99 | return 0; |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | return -1; |
| 104 | } |
| 105 | } |