1 From 5a5322491704c14f5aed72148db6b134484cedec Mon Sep 17 00:00:00 2001
2 From: xalduin <xalduin@gmail.com>
3 Date: Sat, 12 Feb 2011 23:58:55 -0500
4 Subject: [PATCH 2/3] Fixed wavpack sound loading
7 src/engine/client/sound.cpp | 56 ++++++++++++++++++++++++++++++++++++++----
8 1 files changed, 50 insertions(+), 6 deletions(-)
10 diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp
11 index e38ad32..6101602 100644
12 --- a/src/engine/client/sound.cpp
13 +++ b/src/engine/client/sound.cpp
14 @@ -49,6 +49,54 @@ struct CVoice
19 +static int32_t ReadBytes(void *pFile, void *pBuffer, int32_t Size)
21 + return (int32_t)io_read((IOHANDLE)pFile, pBuffer, Size);
23 +static uint32_t GetPos(void *pFile)
25 + return (uint32_t)io_tell((IOHANDLE)pFile);
27 +static int SetPosAbs(void *pFile, uint32_t Offset)
29 + return io_seek((IOHANDLE)pFile, Offset, IOSEEK_START);
31 +static int SetPosRel(void *pFile, int32_t Offset, int Mode)
36 + Mode = IOSEEK_START;
44 + return io_seek((IOHANDLE)pFile, Offset, Mode);
47 +//TODO: Fix if 'real' functionality is needed by the wavpack header
48 +static int PushBackByte(void *pFile, int Char)
50 + return io_seek((IOHANDLE)pFile, -1, IOSEEK_CUR);
52 +static uint32_t GetLength(void *pFile)
54 + return (uint32_t)io_length((IOHANDLE)pFile);
56 +// Essentially assuming this to always be true, should fix if this isn't the case
57 +static int CanSeek(void *pFile)
59 + return pFile != NULL;
61 +static WavpackStreamReader CWavpackReader = {
62 + ReadBytes, GetPos, SetPosAbs, SetPosRel, PushBackByte, GetLength, CanSeek, 0
66 static CSample m_aSamples[NUM_SAMPLES] = { {0} };
67 static CVoice m_aVoices[NUM_VOICES] = { {0} };
68 static CChannel m_aChannels[NUM_CHANNELS] = { {255, 0} };
69 @@ -328,14 +376,12 @@ int CSound::LoadWV(const char *pFilename)
74 ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
77 dbg_msg("sound/wv", "failed to open file. filename='%s'", pFilename);
84 @@ -345,7 +391,7 @@ int CSound::LoadWV(const char *pFilename)
86 pContext = WavpackOpenFileInput(ReadData, aError);
88 - pContext = WavpackOpenFileInput(pFilename, aError, 0, 0);
89 + pContext = WavpackOpenFileInputEx(&CWavpackReader, ms_File, 0, aError, 0, 0);
93 @@ -398,13 +444,11 @@ int CSound::LoadWV(const char *pFilename)
97 - dbg_msg("sound/wv", "failed to open %s: %s", pFilename, aError);
98 + dbg_msg("sound/wv", "failed to open '%s': %s", pFilename, aError);
107 dbg_msg("sound/wv", "loaded %s", pFilename);