File: gvGSM.c

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (97 lines) | stat: -rw-r--r-- 1,864 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "gvGSM.h"
#include <gsm.h>

// these are standard for GSM
#define GVI_SAMPLES_PER_FRAME  160
#define GVI_ENCODED_FRAME_SIZE  33

static GVBool gviGSMInitialized;
static gsm gviGSMEncoderState;

GVBool gviGSMInitialize(void)
{
	const int gsm_ltp = 1;

	// we shouldn't already be initialized
	if(gviGSMInitialized)
		return GVFalse;

	// create a new encoder state
	gviGSMEncoderState = gsm_create();
	if(!gviGSMEncoderState)
		return GVFalse;

	// set the LTP cut option
	gsm_option(gviGSMEncoderState, GSM_OPT_LTP_CUT, &gsm_ltp);

	// we're now initialized
	gviGSMInitialized = GVTrue;

	return GVTrue;
}

void gviGSMCleanup(void)
{
	// make sure there is something to cleanup
	if(!gviGSMInitialized)
		return;

	// destroy the encoder state
	gsm_destroy(gviGSMEncoderState);
	gviGSMEncoderState = NULL;

	// no longer initialized
	gviGSMInitialized = GVFalse;
}

int gviGSMGetSamplesPerFrame(void)
{
	return GVI_SAMPLES_PER_FRAME;
}

int gviGSMGetEncodedFrameSize(void)
{
	return GVI_ENCODED_FRAME_SIZE;
}

GVBool gviGSMNewDecoder(GVDecoderData * data)
{
	gsm decoder;

	// create a new decoder state
	decoder = gsm_create();
	if(!decoder)
		return GVFalse;

	*data = decoder;
	return GVTrue;
}

void gviGSMFreeDecoder(GVDecoderData data)
{
	// destory the decoder state
	gsm_destroy((gsm)data);
}

void gviGSMEncode(GVByte * out, const GVSample * in)
{
	gsm_encode((gsm)gviGSMEncoderState, (gsm_signal*)in, (gsm_byte*)out);
}

void gviGSMDecodeAdd(GVSample * out, const GVByte * in, GVDecoderData data)
{
	GVSample temp[GVI_SAMPLES_PER_FRAME];
	int i;

	// decode it
	gsm_decode((gsm)data, (gsm_byte*)in, (gsm_signal*)temp);

	// add the output
	for(i = 0 ; i < GVI_SAMPLES_PER_FRAME ; i++)
		out[i] += temp[i];
}

void gviGSMDecodeSet(GVSample * out, const GVByte * in, GVDecoderData data)
{
	gsm_decode((gsm)data, (gsm_byte*)in, (gsm_signal*)out);
}