File: gvLogitechPS2Codecs.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 (118 lines) | stat: -rw-r--r-- 2,866 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "gvLogitechPS2Codecs.h"
#include <liblgcodec.h>

#if !defined(_PS2)
#error This file should only be used with the PlayStation2
#endif

static GVBool GVILGCodecInitialized;
static int GVILGCodecHandle;
static int GVILGCodecBytesPerFrame;
static int GVILGCodecSamplesPerFrame;
static int GVILGCodecEncodedFrameSize;
static GVSample * GVILGCodecDecodeBuffer;

GVBool gviLGCodecInitialize(const char * name)
{
	lgCodecDesc * codecDesc;
	int i;
	int rcode;

	// check if the lib hasn't been initialized
	if(!GVILGCodecInitialized)
	{
		// initialize it
		rcode = lgCodecInit();
		if(LGCODEC_FAILED(rcode))
			return GVFalse;

		// we're now initialized
		GVILGCodecInitialized = GVTrue;
	}

	// find the codec
	for(i = 0 ; (codecDesc = lgCodecEnumerate(i)) ; i++)
	{
		// check if the name matches
		if(strcmp(codecDesc->name, name) == 0)
			break;
	}

	// check if we didn't find it
	if(!codecDesc)
		return GVFalse;

	// allocate memory for the decode buffer
	GVILGCodecDecodeBuffer = (GVSample *)gsimalloc((unsigned int)codecDesc->bytes_per_pcm_frame);
	if(!GVILGCodecDecodeBuffer)
		return GVFalse;

	// open a handle to the codec
	rcode = lgCodecOpen(codecDesc->id, &GVILGCodecHandle);
	if(LGCODEC_FAILED(rcode))
	{
		gsifree(GVILGCodecDecodeBuffer);
		return GVFalse;
	}

	// store the codec info
	GVILGCodecBytesPerFrame = codecDesc->bytes_per_pcm_frame;
	GVILGCodecSamplesPerFrame = (int)(GVILGCodecBytesPerFrame / GV_BYTES_PER_SAMPLE);
	GVILGCodecEncodedFrameSize = codecDesc->bytes_per_enc_frame;

	return GVTrue;
}

void gviLGCodecCleanup(void)
{
	gsifree(GVILGCodecDecodeBuffer);
	GVILGCodecDecodeBuffer = NULL;
	lgCodecClose(GVILGCodecHandle);
}

int gviLGCodecGetSamplesPerFrame(void)
{
	return GVILGCodecSamplesPerFrame;
}

int gviLGCodecGetEncodedFrameSize(void)
{
	return GVILGCodecEncodedFrameSize;
}

void gviLGCodecEncode(GVByte * out, const GVSample * in)
{
	int destSize = GVILGCodecEncodedFrameSize;
	lgCodecEncode(GVILGCodecHandle, in, GVILGCodecBytesPerFrame, out, &destSize);
	assert(destSize == GVILGCodecEncodedFrameSize);
}

void gviLGCodecDecodeAdd(GVSample * out, const GVByte * in, GVDecoderData data)
{
	int i;
	int destSize;

	destSize = GVILGCodecBytesPerFrame;
	lgCodecDecode(GVILGCodecHandle, in, GVILGCodecEncodedFrameSize, GVILGCodecDecodeBuffer, &destSize);
	assert(destSize == GVILGCodecBytesPerFrame);

	for(i = 0 ; i < GVILGCodecSamplesPerFrame ; i++)
		out[i] += GVILGCodecDecodeBuffer[i];
		
	GSI_UNUSED(data);
}

void gviLGCodecDecodeSet(GVSample * out, const GVByte * in, GVDecoderData data)
{
	int i;
	int destSize;

	destSize = GVILGCodecBytesPerFrame;
	lgCodecDecode(GVILGCodecHandle, in, GVILGCodecEncodedFrameSize, GVILGCodecDecodeBuffer, &destSize);
	assert(destSize == GVILGCodecBytesPerFrame);

	for(i = 0 ; i < GVILGCodecSamplesPerFrame ; i++)
		out[i] = GVILGCodecDecodeBuffer[i];
		
	GSI_UNUSED(data);
}