File: gvMain.c

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (318 lines) | stat: -rw-r--r-- 7,299 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
GameSpy Voice2 SDK
Dan "Mr. Pants" Schoenblum
dan@gamespy.com

Copyright 2004 GameSpy Industries, Inc

devsupport@gamespy.com
http://gamespy.net
*/

#include "gvMain.h"
#include "gvCodec.h"
#include "gvSource.h"
#include "gvFrame.h"
#include "gvCustomDevice.h"
#if !defined(GV_NO_DEFAULT_HARDWARE)
	#if defined(_WIN32)
		#include "gvDirectSound.h"
	#elif defined(_PS2)
		#include "gvPS2Audio.h"
	#elif defined(_MACOSX)
		#include "gvOSXAudio.h"
	#elif defined(_PSP)
		#include "gvPSPAudio.h"
	#elif defined(_PS3)
		#include "gvPS3Audio.h"
	#else
		#error There is no default hardware support on this platform.  Define GV_NO_DEFAULT_HARDWARE to compile without default hardware support.
	#endif
#endif


/************
** GENERAL **
************/
#if defined(_WIN32)
GVBool gvStartup(HWND hWnd)
#else
GVBool gvStartup(void)
#endif
{
	// init codecs
	gviCodecsInitialize();

	GVIGlobalMute = GVFalse;

	// startup the devices
#if !defined(GV_NO_DEFAULT_HARDWARE)
	#if defined(_WIN32)
		if(!gviHardwareStartup(hWnd))
	#else
		if(!gviHardwareStartup())
	#endif
		{
			return GVFalse;
		}
#endif
	return GVTrue;
}

void gvCleanup(void)
{
#if !defined(GV_NO_DEFAULT_HARDWARE)
	gviHardwareCleanup();
#endif
	gviCodecsCleanup();
	gviFramesCleanup();
}

void gvThink(void)
{
#if !defined(GV_NO_DEFAULT_HARDWARE)
	gviHardwareThink();
#endif
}

/**********
** CODEC **
**********/
GVBool gvSetCodec(GVCodec codec)
{
	return gviSetCodec(codec);
}

void gvSetCustomCodec(GVCustomCodecInfo * info)
{
	gviSetCustomCodec(info);
}

void gvGetCodecInfo(int * samplesPerFrame, int * encodedFrameSize, int * bitsPerSecond)
{
	if(samplesPerFrame)
		*samplesPerFrame = GVISamplesPerFrame;
	if(encodedFrameSize)
		*encodedFrameSize = GVIEncodedFrameSize;
	if(bitsPerSecond)
		*bitsPerSecond = (int)(8 * GVIBytesPerSecond * GVIEncodedFrameSize / GVIBytesPerFrame);
}

/****************
** Sample Rate **
****************/
void gvSetSampleRate(GVRate sampleRate)
{
	gviSetSampleRate(sampleRate);
}

GVRate gvGetSampleRate(void)
{
	return gviGetSampleRate();
}

/************
** DEVICES **
************/
#if !defined(GV_NO_DEFAULT_HARDWARE)
int gvListDevices(GVDeviceInfo devices[], int maxDevices, GVDeviceType types)
{
	return gviHardwareListDevices(devices, maxDevices, types);
}

GVDevice gvNewDevice(GVDeviceID deviceID, GVDeviceType type)
{
	return gviHardwareNewDevice(deviceID, type);
}
#endif

void gvFreeDevice(GVDevice device)
{
	device->m_methods.m_freeDevice(device);
}

GVBool gvStartDevice(GVDevice device, GVDeviceType type)
{
	return device->m_methods.m_startDevice(device, type);
}

void gvStopDevice(GVDevice device, GVDeviceType type)
{
	device->m_methods.m_stopDevice(device, type);
}

GVBool gvIsDeviceStarted(GVDevice device, GVDeviceType type)
{
	return device->m_methods.m_isDeviceStarted(device, type);
}

void gvSetDeviceVolume(GVDevice device, GVDeviceType type, GVScalar volume)
{
	volume = max(volume, 0.0);
	volume = min(volume, 1.0);

	device->m_methods.m_setDeviceVolume(device, type, volume);
}

GVScalar gvGetDeviceVolume(GVDevice device, GVDeviceType type)
{
	return device->m_methods.m_getDeviceVolume(device, type);
}

void gvSetUnpluggedCallback(GVDevice device, gvUnpluggedCallback unpluggedCallback)
{
	device->m_unpluggedCallback = unpluggedCallback;
}

void gvSetFilter(GVDevice device, GVDeviceType type, gvFilterCallback callback)
{
	if(type & GV_CAPTURE)
		device->m_captureFilterCallback = callback;
	if(type & GV_PLAYBACK)
		device->m_playbackFilterCallback = callback;
}

/************
** CAPTURE **
************/
GVBool gvCapturePacket(GVDevice device, GVByte * packet, int * len, GVFrameStamp * frameStamp, GVScalar * volume)
{
	return device->m_methods.m_capturePacket(device, packet, len, frameStamp, volume);
}

int gvGetAvailableCaptureBytes(GVDevice device)
{
	return device->m_methods.m_getAvailableCaptureBytes(device);
}

void gvSetCaptureThreshold(GVDevice device, GVScalar threshold)
{
	device->m_methods.m_setCaptureThreshold(device, threshold);
}

GVScalar gvGetCaptureThreshold(GVDevice device)
{
	return device->m_methods.m_getCaptureThreshold(device);
}

void gvSetCaptureMode(GVDevice device, GVCaptureMode captureMode)
{
	//This only works with Capture devices.
	assert(device->m_types & GV_CAPTURE);

	//See if we are switching from Threshold to PTT.
	if ((device->m_captureMode == GVCaptureModeThreshold) && (captureMode == GVCaptureModePushToTalk))
	{
		device->m_savedCaptureThreshold = gvGetCaptureThreshold(device);
		gvSetCaptureThreshold(device, 0.0f);

		//Stop the capture device.
		if (gvIsDeviceStarted(device, GV_CAPTURE))
			gvStopDevice(device, GV_CAPTURE);
	}
	//See if we are switching from PTT to Threshold.
	if ((device->m_captureMode == GVCaptureModePushToTalk) && (captureMode == GVCaptureModeThreshold))
	{
		gvSetCaptureThreshold(device, device->m_savedCaptureThreshold);

		//Turn on the capture device.
		gvStartDevice(device, GV_CAPTURE);
	}

	device->m_captureMode = captureMode;
}

GVCaptureMode gvGetCaptureMode(GVDevice device)
{
	return device->m_captureMode;
}

void gvSetPushToTalk(GVDevice device, GVBool talkOn)
{
	if (talkOn)
		gvStartDevice(device, GV_CAPTURE);
	else
		gvStopDevice(device, GV_CAPTURE);
}

GVBool gvGetPushToTalk(GVDevice device)
{
	return gvIsDeviceStarted(device, GV_CAPTURE);
}

/*************
** PLAYBACK **
*************/
void gvPlayPacket(GVDevice device, const GVByte * data, int len, GVSource source, GVFrameStamp frameStamp, GVBool mute)
{
	device->m_methods.m_playPacket(device, data, len, source, frameStamp, mute);
}

GVBool gvIsSourceTalking(GVDevice device, GVSource source)
{
	return device->m_methods.m_isSourceTalking(device, source);
}

int gvListTalkingSources(GVDevice device, GVSource sources[], int maxSources)
{
	return device->m_methods.m_listTalkingSources(device, sources, maxSources);
}

void gvSetGlobalMute(GVBool mute)
{
	gviSetGlobalMute(mute);
}

GVBool gvGetGlobalMute(void)
{
	return gviGetGlobalMute();
}


/******************
** CUSTOM DEVICE **
******************/
GVDevice gvNewCustomDevice(GVDeviceType type)
{
	return gviCustomNewDevice(type);
}

GVBool gvGetCustomPlaybackAudio(GVDevice device, GVSample * audio, int numSamples)
{
	return gviGetCustomPlaybackAudio(device, audio, numSamples);
}

GVBool gvSetCustomCaptureAudio(GVDevice device, const GVSample * audio, int numSamples,
                               GVByte * packet, int * packetLen, GVFrameStamp * frameStamp, GVScalar * volume)
{
	return gviSetCustomCaptureAudio(device, audio, numSamples, packet, packetLen, frameStamp, volume);
}

/*************
** CHANNELS **
*************/
int gvGetNumChannels(GVDevice device, GVDeviceType type)
{
	if(device->m_methods.m_getNumChannels)
		return device->m_methods.m_getNumChannels(device, type);
	return 0;
}

void gvGetChannelName(GVDevice device, GVDeviceType type, int channel, gsi_char name[GV_CHANNEL_NAME_LEN])
{
	if(device->m_methods.m_getNumChannels)
		device->m_methods.m_getChannelName(device, type, channel, name);
}

void gvSetChannel(GVDevice device, GVDeviceType type, int channel)
{
	if(device->m_methods.m_setChannel)
		device->m_methods.m_setChannel(device, type, channel);
}

int gvGetChannel(GVDevice device, GVDeviceType type)
{
	if(device->m_methods.m_getChannel)
		return device->m_methods.m_getChannel(device, type);
	return 0;
}