1 /* ------------------------------------------------------------------
2 * Copyright (C) 2009 Martin Storsjo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
19 #define AMRNB_WRAPPER_INTERNAL
21 #include <amrdecode.h>
22 #include <amrencode.h>
23 #include "interf_dec.h"
24 #include "interf_enc.h"
27 #ifndef DISABLE_AMRNB_DECODER
28 void* Decoder_Interface_init(void) {
30 GSMInitDecode(&ptr, (int8*)"Decoder");
34 void Decoder_Interface_exit(void* state) {
35 GSMDecodeFrameExit(&state);
38 void Decoder_Interface_Decode(void* state, const unsigned char* in, short* out, int bfi) {
39 unsigned char type = (in[0] >> 3) & 0x0f;
41 AMRDecode(state, (enum Frame_Type_3GPP) type, (UWord8*) in, out, MIME_IETF);
45 #ifndef DISABLE_AMRNB_ENCODER
46 struct encoder_state {
51 void* Encoder_Interface_init(int dtx) {
52 struct encoder_state* state = (struct encoder_state*) malloc(sizeof(struct encoder_state));
53 AMREncodeInit(&state->encCtx, &state->pidSyncCtx, dtx);
57 void Encoder_Interface_exit(void* s) {
58 struct encoder_state* state = (struct encoder_state*) s;
59 AMREncodeExit(&state->encCtx, &state->pidSyncCtx);
63 int Encoder_Interface_Encode(void* s, enum Mode mode, const short* speech, unsigned char* out, int forceSpeech) {
64 struct encoder_state* state = (struct encoder_state*) s;
65 enum Frame_Type_3GPP frame_type = (enum Frame_Type_3GPP) mode;
66 int ret = AMREncode(state->encCtx, state->pidSyncCtx, mode, (Word16*) speech, out, &frame_type, AMR_TX_IETF);