summaryrefslogtreecommitdiff
path: root/soundsystem/snd_io.cpp
blob: 887e1a8d56d3c6455ac845196405eb3505b5a32d (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//===========================================================================//

#include "soundsystem.h"
#include "tier2/riff.h"
#include "filesystem.h"
#include "tier1/strtools.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

//-----------------------------------------------------------------------------
// Purpose: Implements Audio IO on the engine's COMMON filesystem
//-----------------------------------------------------------------------------
class COM_IOReadBinary : public IFileReadBinary
{
public:
	int open( const char *pFileName );
	int read( void *pOutput, int size, int file );
	void seek( int file, int pos );
	unsigned int tell( int file );
	unsigned int size( int file );
	void close( int file );
};


// prepend sound/ to the filename -- all sounds are loaded from the sound/ directory
int COM_IOReadBinary::open( const char *pFileName )
{
	char namebuffer[512];
	FileHandle_t hFile;

	Q_strncpy(namebuffer, "sound", sizeof( namebuffer ) );

	//HACK HACK HACK  the server is sending back sound names with slashes in front... 
	if (pFileName[0]!='/')
	{
		Q_strncat(namebuffer,"/", sizeof( namebuffer ), COPY_ALL_CHARACTERS );
	}

	Q_strncat( namebuffer, pFileName, sizeof( namebuffer ), COPY_ALL_CHARACTERS );

	hFile = g_pFullFileSystem->Open( namebuffer, "rb", "GAME" );

	return (int)hFile;
}

int COM_IOReadBinary::read( void *pOutput, int size, int file )
{
	if ( !file )
		return 0;

	return g_pFullFileSystem->Read( pOutput, size, (FileHandle_t)file );
}

void COM_IOReadBinary::seek( int file, int pos )
{
	if ( !file )
		return;

	g_pFullFileSystem->Seek( (FileHandle_t)file, pos, FILESYSTEM_SEEK_HEAD );
}

unsigned int COM_IOReadBinary::tell( int file )
{
	if ( !file )
		return 0;
	return g_pFullFileSystem->Tell( (FileHandle_t)file );
}

unsigned int COM_IOReadBinary::size( int file )
{
	if (!file)
		return 0;
	return g_pFullFileSystem->Size( (FileHandle_t)file );
}

void COM_IOReadBinary::close( int file )
{
	if (!file)
		return;

	g_pFullFileSystem->Close( (FileHandle_t)file );
}

static COM_IOReadBinary io;
IFileReadBinary *g_pSndIO = &io;