mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 10:37:41 -04:00
Merge branch 'master' of https://github.com/dvpdiner2/Plasma
This commit is contained in:
@ -214,6 +214,7 @@ if (WIN32)
|
|||||||
target_link_libraries(plClient Version)
|
target_link_libraries(plClient Version)
|
||||||
target_link_libraries(plClient Vfw32)
|
target_link_libraries(plClient Vfw32)
|
||||||
target_link_libraries(plClient Ws2_32)
|
target_link_libraries(plClient Ws2_32)
|
||||||
|
target_link_libraries(plClient winmm)
|
||||||
target_link_libraries(plClient strmiids)
|
target_link_libraries(plClient strmiids)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ set(plAudio_SOURCES
|
|||||||
plSound.cpp
|
plSound.cpp
|
||||||
plSoundEvent.cpp
|
plSoundEvent.cpp
|
||||||
plVoiceChat.cpp
|
plVoiceChat.cpp
|
||||||
plWAVClipBuffer.cpp
|
|
||||||
plWin32GroupedSound.cpp
|
plWin32GroupedSound.cpp
|
||||||
plWin32Sound.cpp
|
plWin32Sound.cpp
|
||||||
plWin32StaticSound.cpp
|
plWin32StaticSound.cpp
|
||||||
@ -34,7 +33,6 @@ set(plAudio_HEADERS
|
|||||||
plSound.h
|
plSound.h
|
||||||
plSoundEvent.h
|
plSoundEvent.h
|
||||||
plVoiceChat.h
|
plVoiceChat.h
|
||||||
plWAVClipBuffer.h
|
|
||||||
plWin32GroupedSound.h
|
plWin32GroupedSound.h
|
||||||
plWin32Sound.h
|
plWin32Sound.h
|
||||||
plWin32StaticSound.h
|
plWin32StaticSound.h
|
||||||
|
@ -39,6 +39,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#include <eax.h>
|
#include <eax.h>
|
||||||
#include <eaxlegacy.h>
|
#include <eaxlegacy.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <iostream>
|
||||||
#include <DShow.h>
|
#include <DShow.h>
|
||||||
|
|
||||||
#include "plStatusLog/plStatusLog.h"
|
#include "plStatusLog/plStatusLog.h"
|
||||||
|
@ -1,210 +0,0 @@
|
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools
|
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|
||||||
or by snail mail at:
|
|
||||||
Cyan Worlds, Inc.
|
|
||||||
14617 N Newport Hwy
|
|
||||||
Mead, WA 99021
|
|
||||||
|
|
||||||
*==LICENSE==*/
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// //
|
|
||||||
// plWAVClipBuffer - Helper class for writing out WAV data in a buffered //
|
|
||||||
// manner, with support for clipping off the specified //
|
|
||||||
// amount at the end, but without knowing beforehand //
|
|
||||||
// exactly how much data we'll have. //
|
|
||||||
// //
|
|
||||||
// The algorithm goes something like this: we keep two buffers, both the //
|
|
||||||
// size of the amount we want to clip. We then start filling in the first //
|
|
||||||
// buffer, overflowing into the second buffer and wrapping back to the //
|
|
||||||
// first again in a circular fashion. When we fill up one buffer and are //
|
|
||||||
// about to advance to the next, we write that next buffer out. Why? //
|
|
||||||
// Because we know that, even if we got no more data in, we have enough //
|
|
||||||
// data in the first buffer to clip out the amount we want, so the other //
|
|
||||||
// half (which will have older data, being a circular buffer) can be //
|
|
||||||
// written out safely. //
|
|
||||||
// //
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "hsTypes.h"
|
|
||||||
#include "plWAVClipBuffer.h"
|
|
||||||
#include "hsStream.h"
|
|
||||||
#include "hsUtils.h"
|
|
||||||
|
|
||||||
#include "plAudioCore/plWavFile.h"
|
|
||||||
|
|
||||||
|
|
||||||
//// Constructor/Destructor //////////////////////////////////////////////////
|
|
||||||
|
|
||||||
plWAVClipBuffer::plWAVClipBuffer( UInt32 clipSize, CWaveFile *outFile )
|
|
||||||
{
|
|
||||||
fBuffers[ 0 ] = fBuffers[ 1 ] = nil;
|
|
||||||
fFlushCalled = true;
|
|
||||||
Init( clipSize, outFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
plWAVClipBuffer::~plWAVClipBuffer()
|
|
||||||
{
|
|
||||||
IShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
//// Init & IShutdown ////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void plWAVClipBuffer::Init( UInt32 clipSize, CWaveFile *outFile )
|
|
||||||
{
|
|
||||||
IShutdown();
|
|
||||||
if( clipSize > 0 )
|
|
||||||
{
|
|
||||||
fBuffers[ 0 ] = TRACKED_NEW UInt8[ clipSize ];
|
|
||||||
fBuffers[ 1 ] = TRACKED_NEW UInt8[ clipSize ];
|
|
||||||
memset( fBuffers[ 0 ], 0, clipSize );
|
|
||||||
memset( fBuffers[ 1 ], 0, clipSize );
|
|
||||||
}
|
|
||||||
fWhichBuffer = 0;
|
|
||||||
fBufferSize = clipSize;
|
|
||||||
fCursor = 0;
|
|
||||||
fFirstFlip = true;
|
|
||||||
fOutFile = outFile;
|
|
||||||
fFlushCalled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void plWAVClipBuffer::IShutdown( void )
|
|
||||||
{
|
|
||||||
hsAssert( fFlushCalled, "WAVClipBuffer shut down without flushing it!!!" );
|
|
||||||
|
|
||||||
delete [] fBuffers[ 0 ];
|
|
||||||
delete [] fBuffers[ 1 ];
|
|
||||||
}
|
|
||||||
|
|
||||||
//// WriteData ///////////////////////////////////////////////////////////////
|
|
||||||
// The main workhorse; call this to add data to the buffer.
|
|
||||||
|
|
||||||
hsBool plWAVClipBuffer::WriteData( UInt32 size, UInt8 *data )
|
|
||||||
{
|
|
||||||
while( size > 0 )
|
|
||||||
{
|
|
||||||
UInt32 toWrite = fBufferSize - fCursor;
|
|
||||||
if( size < toWrite )
|
|
||||||
{
|
|
||||||
// Just write, haven't filled a buffer yet
|
|
||||||
memcpy( fBuffers[ fWhichBuffer ] + fCursor, data, size );
|
|
||||||
data += size;
|
|
||||||
fCursor += size;
|
|
||||||
return true; // All done!
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill up to the end of a buffer, then flip
|
|
||||||
memcpy( fBuffers[ fWhichBuffer ] + fCursor, data, toWrite );
|
|
||||||
data += toWrite;
|
|
||||||
fCursor += toWrite;
|
|
||||||
size -= toWrite;
|
|
||||||
|
|
||||||
// Flip now...
|
|
||||||
fWhichBuffer = 1 - fWhichBuffer;
|
|
||||||
fCursor = 0;
|
|
||||||
|
|
||||||
// Now we can write out this buffer, since it'll be old data and
|
|
||||||
// we have enough in the other buffer to clip with. The *only*
|
|
||||||
// time we don't want to do this is the first time we flip, since
|
|
||||||
// at that point, the buffer we just flipped to hasn't been filled yet.
|
|
||||||
// (Every time afterwards, we'll always be flipping to a buffer with old
|
|
||||||
// data).
|
|
||||||
if( fFirstFlip )
|
|
||||||
fFirstFlip = false;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Write it out before we overwrite it!
|
|
||||||
UINT written;
|
|
||||||
HRESULT hr = fOutFile->Write( fBufferSize, fBuffers[ fWhichBuffer ], &written );
|
|
||||||
|
|
||||||
if( FAILED( hr ) )
|
|
||||||
{
|
|
||||||
hsAssert( false, "ERROR writing WMA stream to WAV file" );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if( written != fBufferSize )
|
|
||||||
{
|
|
||||||
hsAssert( false, "Unable to write all of WMA stream to WAV file" );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanly got here, so just return success
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//// Flush ///////////////////////////////////////////////////////////////////
|
|
||||||
// Writes out the remaining data, minus our clip value (which is fBufferSize)
|
|
||||||
// So here's our situation: at this point, one of two things could be true:
|
|
||||||
//
|
|
||||||
// 1) We haven't received enough data to clip by, at which point we don't
|
|
||||||
// write any more and bail (this will be true if fFirstFlip is still true)
|
|
||||||
//
|
|
||||||
// 2) Our cursor is at 0, which means we have one filled buffer that hasn't been
|
|
||||||
// written out and our current buffer is empty. At this point, we discard the
|
|
||||||
// filled buffer (which is precisely the length we want to clip by) and we're done.
|
|
||||||
//
|
|
||||||
// 3) The buffer we're on should be partially filled, while the other one is older
|
|
||||||
// data. So, we want to write out the older data and the partial buffer all the way,
|
|
||||||
// except for the clip size. Since we can therefore never write out any data in the
|
|
||||||
// partial buffer (since that count will always be less than the clip size and thus be
|
|
||||||
// the second half of what we clip), we simply figure out how much of the other one we
|
|
||||||
// clip and write out the rest.
|
|
||||||
|
|
||||||
hsBool plWAVClipBuffer::Flush( void )
|
|
||||||
{
|
|
||||||
fFlushCalled = true;
|
|
||||||
|
|
||||||
if( fFirstFlip )
|
|
||||||
return false; // We failed--not enough data to clip with
|
|
||||||
|
|
||||||
if( fCursor == 0 )
|
|
||||||
{
|
|
||||||
// Our current buffer is empty, so the other buffer is precisely what we clip.
|
|
||||||
// So just discard and return successfully
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The hard case--we always discard the partial buffer we're on, so figure out
|
|
||||||
// how much we want to save of the other buffer. The math is:
|
|
||||||
// Partial buffer amount we're clipping = fCursor
|
|
||||||
// Amount of other buffer we're clipping = fBufferSize - fCursor
|
|
||||||
// Amount of other buffer we're writing = fBufferSize - ( fBufferSize - fCursor ) = fCursor
|
|
||||||
// Go figure :)
|
|
||||||
|
|
||||||
UInt32 toWrite = fCursor;
|
|
||||||
|
|
||||||
UINT written;
|
|
||||||
HRESULT hr = fOutFile->Write( toWrite, fBuffers[ 1 - fWhichBuffer ], &written );
|
|
||||||
|
|
||||||
if( FAILED( hr ) )
|
|
||||||
{
|
|
||||||
hsAssert( false, "ERROR writing WMA stream to WAV file" );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if( written != toWrite )
|
|
||||||
{
|
|
||||||
hsAssert( false, "Unable to write all of WMA stream to WAV file" );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All done!
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools
|
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|
||||||
or by snail mail at:
|
|
||||||
Cyan Worlds, Inc.
|
|
||||||
14617 N Newport Hwy
|
|
||||||
Mead, WA 99021
|
|
||||||
|
|
||||||
*==LICENSE==*/
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// //
|
|
||||||
// plWAVClipBuffer - Helper class for writing out WAV data in a buffered //
|
|
||||||
// manner, with support for clipping off the specified //
|
|
||||||
// amount at the end, but without knowing beforehand //
|
|
||||||
// exactly how much data we'll have. //
|
|
||||||
// //
|
|
||||||
// The algorithm goes something like this: we keep two buffers, both the //
|
|
||||||
// size of the amount we want to clip. We then start filling in the first //
|
|
||||||
// buffer, overflowing into the second buffer and wrapping back to the //
|
|
||||||
// first again in a circular fashion. When we fill up one buffer and are //
|
|
||||||
// about to advance to the next, we write that next buffer out. Why? //
|
|
||||||
// Because we know that, even if we got no more data in, we have enough //
|
|
||||||
// data in the first buffer to clip out the amount we want, so the other //
|
|
||||||
// half (which will have older data, being a circular buffer) can be //
|
|
||||||
// written out safely. //
|
|
||||||
// //
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _plWAVClipBuffer_h
|
|
||||||
#define _plWAVClipBuffer_h
|
|
||||||
|
|
||||||
//// Class Definition ////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class CWaveFile;
|
|
||||||
class plWAVClipBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
plWAVClipBuffer( UInt32 clipSize, CWaveFile *outFile );
|
|
||||||
~plWAVClipBuffer();
|
|
||||||
|
|
||||||
// Inits the buffer. Can re-init if you wish
|
|
||||||
void Init( UInt32 clipSize, CWaveFile *outFile );
|
|
||||||
|
|
||||||
// Writes/adds data to the buffer
|
|
||||||
hsBool WriteData( UInt32 size, UInt8 *data );
|
|
||||||
|
|
||||||
// Call at the end, flushes the buffer and performs the clipping
|
|
||||||
hsBool Flush( void );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
UInt8 *fBuffers[ 2 ];
|
|
||||||
UInt8 fWhichBuffer; // 0 or 1
|
|
||||||
UInt32 fCursor, fBufferSize;
|
|
||||||
hsBool fFirstFlip, fFlushCalled;
|
|
||||||
|
|
||||||
CWaveFile *fOutFile;
|
|
||||||
|
|
||||||
void IShutdown( void );
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //_plWAVClipBuffer_h
|
|
@ -10,6 +10,7 @@ include_directories(${Vorbis_INCLUDE_DIR})
|
|||||||
set(plAudioCore_SOURCES
|
set(plAudioCore_SOURCES
|
||||||
plAudioFileReader.cpp
|
plAudioFileReader.cpp
|
||||||
plBufferedFileReader.cpp
|
plBufferedFileReader.cpp
|
||||||
|
plCachedFileReader.cpp
|
||||||
plFastWavReader.cpp
|
plFastWavReader.cpp
|
||||||
plOGGCodec.cpp
|
plOGGCodec.cpp
|
||||||
plSoundBuffer.cpp
|
plSoundBuffer.cpp
|
||||||
@ -22,6 +23,7 @@ set(plAudioCore_HEADERS
|
|||||||
plAudioCoreCreatable.h
|
plAudioCoreCreatable.h
|
||||||
plAudioFileReader.h
|
plAudioFileReader.h
|
||||||
plBufferedFileReader.h
|
plBufferedFileReader.h
|
||||||
|
plCachedFileReader.h
|
||||||
plFastWavReader.h
|
plFastWavReader.h
|
||||||
plOGGCodec.h
|
plOGGCodec.h
|
||||||
plSoundBuffer.h
|
plSoundBuffer.h
|
||||||
|
@ -43,11 +43,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#include "plFile/plFileUtils.h"
|
#include "plFile/plFileUtils.h"
|
||||||
#include "plUnifiedTime/plUnifiedTime.h"
|
#include "plUnifiedTime/plUnifiedTime.h"
|
||||||
#include "plBufferedFileReader.h"
|
#include "plBufferedFileReader.h"
|
||||||
|
#include "plCachedFileReader.h"
|
||||||
#include "plFastWavReader.h"
|
#include "plFastWavReader.h"
|
||||||
#include "plOGGCodec.h"
|
#include "plOGGCodec.h"
|
||||||
#include "plWavFile.h"
|
#include "plWavFile.h"
|
||||||
|
|
||||||
#define kCacheDirName "streamingCache"
|
#define kCacheDirName "temp"
|
||||||
|
|
||||||
static void hsStrUpper(char *s)
|
static void hsStrUpper(char *s)
|
||||||
{
|
{
|
||||||
@ -73,7 +74,14 @@ plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore
|
|||||||
{
|
{
|
||||||
char cachedPath[256];
|
char cachedPath[256];
|
||||||
IGetCachedPath(path, cachedPath, whichChan);
|
IGetCachedPath(path, cachedPath, whichChan);
|
||||||
plAudioFileReader *r = TRACKED_NEW plFastWAV(cachedPath, plAudioCore::kAll);
|
plAudioFileReader *r = TRACKED_NEW plCachedFileReader(cachedPath, plAudioCore::kAll);
|
||||||
|
if (!r->IsValid()) {
|
||||||
|
// So we tried to play a cached file and it didn't exist
|
||||||
|
// Oops... we should cache it now
|
||||||
|
delete r;
|
||||||
|
ICacheFile(path, true, whichChan);
|
||||||
|
r = TRACKED_NEW plCachedFileReader(cachedPath, plAudioCore::kAll);
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +100,7 @@ plAudioFileReader* plAudioFileReader::CreateWriter(const char* path, plWAVHeader
|
|||||||
{
|
{
|
||||||
const char* ext = plFileUtils::GetFileExt(path);
|
const char* ext = plFileUtils::GetFileExt(path);
|
||||||
|
|
||||||
plAudioFileReader* writer = TRACKED_NEW CWaveFile(path, plAudioCore::kAll);
|
plAudioFileReader* writer = TRACKED_NEW plCachedFileReader(path, plAudioCore::kAll);
|
||||||
writer->OpenForWriting(path, header);
|
writer->OpenForWriting(path, header);
|
||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
@ -113,11 +121,11 @@ void plAudioFileReader::IGetCachedPath(const char* path, char* cachedPath, plAud
|
|||||||
strncat(cachedPath, fileName, fileExt-fileName-1);
|
strncat(cachedPath, fileName, fileExt-fileName-1);
|
||||||
|
|
||||||
if (whichChan == plAudioCore::kLeft)
|
if (whichChan == plAudioCore::kLeft)
|
||||||
strcat(cachedPath, "-Left.wav");
|
strcat(cachedPath, "-Left.tmp");
|
||||||
else if (whichChan == plAudioCore::kRight)
|
else if (whichChan == plAudioCore::kRight)
|
||||||
strcat(cachedPath, "-Right.wav");
|
strcat(cachedPath, "-Right.tmp");
|
||||||
else if (whichChan == plAudioCore::kAll)
|
else if (whichChan == plAudioCore::kAll)
|
||||||
strcat(cachedPath, ".wav");
|
strcat(cachedPath, ".tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCore::ChannelSelect whichChan)
|
void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCore::ChannelSelect whichChan)
|
||||||
|
184
Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp
Normal file
184
Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
/*==LICENSE==*
|
||||||
|
|
||||||
|
CyanWorlds.com Engine - MMOG client, server and tools
|
||||||
|
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||||
|
or by snail mail at:
|
||||||
|
Cyan Worlds, Inc.
|
||||||
|
14617 N Newport Hwy
|
||||||
|
Mead, WA 99021
|
||||||
|
|
||||||
|
*==LICENSE==*/
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// plCachedFileReader - Reads (and writes, how ironic) decompressed sound //
|
||||||
|
// data that is temporarily held in a cache. //
|
||||||
|
// //
|
||||||
|
//// NOTES ///////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// 2011.04.24 - Created by dpogue. //
|
||||||
|
// //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "hsTypes.h"
|
||||||
|
#include "plCachedFileReader.h"
|
||||||
|
|
||||||
|
//// Constructor/Destructor //////////////////////////////////////////////////
|
||||||
|
|
||||||
|
plCachedFileReader::plCachedFileReader(const char *path,
|
||||||
|
plAudioCore::ChannelSelect whichChan)
|
||||||
|
: fFileHandle(nil)
|
||||||
|
{
|
||||||
|
hsAssert(path != nil, "Invalid path specified in plCachedFileReader");
|
||||||
|
|
||||||
|
strncpy(fFilename, path, sizeof(fFilename));
|
||||||
|
|
||||||
|
/// Open the file as a plain binary stream
|
||||||
|
fFileHandle = fopen(path, "rb");
|
||||||
|
if (fFileHandle != nil)
|
||||||
|
{
|
||||||
|
if (fread(&fHeader, 1, sizeof(plWAVHeader), fFileHandle)
|
||||||
|
!= sizeof(plWAVHeader))
|
||||||
|
{
|
||||||
|
IError("Invalid WAV file header in plCachedFileReader");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check format
|
||||||
|
if (fHeader.fFormatTag != kPCMFormatTag)
|
||||||
|
{
|
||||||
|
IError("Invalid format in plCachedFileReader");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(fFileHandle, 0, SEEK_END);
|
||||||
|
fDataLength = ftell(fFileHandle) - sizeof(plWAVHeader);
|
||||||
|
|
||||||
|
fseek(fFileHandle, sizeof(plWAVHeader), SEEK_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plCachedFileReader::~plCachedFileReader()
|
||||||
|
{
|
||||||
|
if (fFileHandle != nil) {
|
||||||
|
fclose(fFileHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void plCachedFileReader::IError(const char *msg)
|
||||||
|
{
|
||||||
|
hsAssert(false, msg);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
plWAVHeader &plCachedFileReader::GetHeader()
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "GetHeader() called on an invalid cache file");
|
||||||
|
|
||||||
|
return fHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void plCachedFileReader::Close()
|
||||||
|
{
|
||||||
|
if (fFileHandle != nil)
|
||||||
|
{
|
||||||
|
fclose(fFileHandle);
|
||||||
|
fFileHandle = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt32 plCachedFileReader::GetDataSize()
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "GetDataSize() called on an invalid cache file");
|
||||||
|
|
||||||
|
return fDataLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
float plCachedFileReader::GetLengthInSecs()
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "GetLengthInSecs() called on an invalid cache file");
|
||||||
|
|
||||||
|
return (float)fDataLength / (float)fHeader.fAvgBytesPerSec;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsBool plCachedFileReader::SetPosition(UInt32 numBytes)
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "SetPosition() called on an invalid cache file");
|
||||||
|
|
||||||
|
fCurPosition = numBytes;
|
||||||
|
|
||||||
|
hsAssert(fCurPosition <= fDataLength, "Invalid position while seeking");
|
||||||
|
|
||||||
|
return !fseek(fFileHandle, sizeof(plWAVHeader) + fCurPosition, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
hsBool plCachedFileReader::Read(UInt32 numBytes, void *buffer)
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "Read() called on an invalid cache file");
|
||||||
|
|
||||||
|
size_t numRead = fread(buffer, 1, numBytes, fFileHandle);
|
||||||
|
|
||||||
|
fCurPosition += numRead;
|
||||||
|
hsAssert(fCurPosition <= fDataLength, "Invalid position while reading");
|
||||||
|
|
||||||
|
return numRead >= numBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt32 plCachedFileReader::NumBytesLeft()
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "NumBytesLeft() called on an invalid cache file");
|
||||||
|
hsAssert(fCurPosition <= fDataLength, "Invalid position while reading");
|
||||||
|
|
||||||
|
return fDataLength - fCurPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsBool plCachedFileReader::OpenForWriting(const char *path, plWAVHeader &header)
|
||||||
|
{
|
||||||
|
hsAssert(path != nil, "Invalid path specified in plCachedFileReader");
|
||||||
|
|
||||||
|
fHeader = header;
|
||||||
|
fCurPosition = 0;
|
||||||
|
fDataLength = 0;
|
||||||
|
strncpy(fFilename, path, sizeof(fFilename));
|
||||||
|
|
||||||
|
/// Open the file as a plain binary stream
|
||||||
|
fFileHandle = fopen(path, "wb");
|
||||||
|
|
||||||
|
if (fFileHandle != nil)
|
||||||
|
{
|
||||||
|
if (fwrite(&fHeader, 1, sizeof(plWAVHeader), fFileHandle)
|
||||||
|
!= sizeof(plWAVHeader))
|
||||||
|
{
|
||||||
|
IError("Could not write WAV file header in plCachedFileReader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fFileHandle != nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt32 plCachedFileReader::Write(UInt32 bytes, void* buffer)
|
||||||
|
{
|
||||||
|
hsAssert(IsValid(), "Write() called on an invalid cache file");
|
||||||
|
|
||||||
|
size_t written = fwrite(buffer, 1, bytes, fFileHandle);
|
||||||
|
|
||||||
|
fCurPosition += written;
|
||||||
|
fDataLength += written;
|
||||||
|
|
||||||
|
return (UInt32)written;
|
||||||
|
}
|
82
Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h
Normal file
82
Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*==LICENSE==*
|
||||||
|
|
||||||
|
CyanWorlds.com Engine - MMOG client, server and tools
|
||||||
|
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||||
|
or by snail mail at:
|
||||||
|
Cyan Worlds, Inc.
|
||||||
|
14617 N Newport Hwy
|
||||||
|
Mead, WA 99021
|
||||||
|
|
||||||
|
*==LICENSE==*/
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// plCachedFileReader - Reads (and writes, how ironic) decompressed sound //
|
||||||
|
// data that is temporarily held in a cache. //
|
||||||
|
// //
|
||||||
|
//// NOTES ///////////////////////////////////////////////////////////////////
|
||||||
|
// //
|
||||||
|
// 2011.04.24 - Created by dpogue. //
|
||||||
|
// //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _plcachedfilereader_h
|
||||||
|
#define _plcachedfilereader_h
|
||||||
|
|
||||||
|
#include "plAudioFileReader.h"
|
||||||
|
|
||||||
|
//// Class Definition ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class plCachedFileReader : public plAudioFileReader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
plCachedFileReader(const char *path,
|
||||||
|
plAudioCore::ChannelSelect whichChan = plAudioCore::kAll);
|
||||||
|
virtual ~plCachedFileReader();
|
||||||
|
|
||||||
|
virtual plWAVHeader &GetHeader();
|
||||||
|
|
||||||
|
virtual void Close();
|
||||||
|
|
||||||
|
virtual UInt32 GetDataSize();
|
||||||
|
virtual float GetLengthInSecs();
|
||||||
|
|
||||||
|
virtual hsBool SetPosition(UInt32 numBytes);
|
||||||
|
virtual hsBool Read(UInt32 numBytes, void *buffer);
|
||||||
|
virtual UInt32 NumBytesLeft();
|
||||||
|
|
||||||
|
virtual hsBool OpenForWriting(const char *path, plWAVHeader &header);
|
||||||
|
virtual UInt32 Write(UInt32 bytes, void *buffer);
|
||||||
|
|
||||||
|
virtual hsBool IsValid() { return fFileHandle != nil; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
kPCMFormatTag = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
char fFilename[512];
|
||||||
|
FILE * fFileHandle;
|
||||||
|
plWAVHeader fHeader;
|
||||||
|
UInt32 fDataLength;
|
||||||
|
UInt32 fCurPosition;
|
||||||
|
|
||||||
|
void IError(const char *msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //_plcachedfilereader_h
|
@ -33,9 +33,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
// //
|
// //
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <vorbis/codec.h>
|
#include <vorbis/codec.h>
|
||||||
|
@ -26,6 +26,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "plWavFile.h"
|
#include "plWavFile.h"
|
||||||
|
|
||||||
|
#ifdef MAXPLUGINCODE
|
||||||
|
|
||||||
#ifdef DX_OLD_SDK
|
#ifdef DX_OLD_SDK
|
||||||
#include <dxerr9.h>
|
#include <dxerr9.h>
|
||||||
#else
|
#else
|
||||||
@ -1091,3 +1093,5 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif //MAXPLUGINCODE
|
||||||
|
@ -26,6 +26,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#ifndef plWavFile_H
|
#ifndef plWavFile_H
|
||||||
#define plWavFile_H
|
#define plWavFile_H
|
||||||
|
|
||||||
|
#ifdef MAXPLUGINCODE
|
||||||
#define WAVEFILE_READ 1
|
#define WAVEFILE_READ 1
|
||||||
#define WAVEFILE_WRITE 2
|
#define WAVEFILE_WRITE 2
|
||||||
|
|
||||||
@ -110,5 +111,6 @@ protected:
|
|||||||
HRESULT WriteMMIO( WAVEFORMATEX *pwfxDest );
|
HRESULT WriteMMIO( WAVEFORMATEX *pwfxDest );
|
||||||
HRESULT IClose();
|
HRESULT IClose();
|
||||||
};
|
};
|
||||||
|
#endif //MAXPLUGINCODE
|
||||||
|
|
||||||
#endif // plWavFile_H
|
#endif // plWavFile_H
|
||||||
|
@ -203,6 +203,7 @@ if (WIN32)
|
|||||||
target_link_libraries(MaxMain Strmiids)
|
target_link_libraries(MaxMain Strmiids)
|
||||||
target_link_libraries(MaxMain Vfw32)
|
target_link_libraries(MaxMain Vfw32)
|
||||||
target_link_libraries(MaxMain Ws2_32)
|
target_link_libraries(MaxMain Ws2_32)
|
||||||
|
target_link_libraries(MaxMain winmm)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
source_group("Header Files" FILES ${MaxMain_HEADERS})
|
source_group("Header Files" FILES ${MaxMain_HEADERS})
|
||||||
|
Reference in New Issue
Block a user