From e3cb83f76ca066210148aa3efa474812cfd26e21 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 25 Apr 2011 17:52:24 -0700 Subject: [PATCH 01/15] Added plCachedFileReader class for cached sfx. --- .../PubUtilLib/plAudioCore/CMakeLists.txt | 2 + .../plAudioCore/plCachedFileReader.cpp | 176 ++++++++++++++++++ .../plAudioCore/plCachedFileReader.h | 77 ++++++++ 3 files changed, 255 insertions(+) create mode 100644 Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp create mode 100644 Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plAudioCore/CMakeLists.txt index 3a2f0d4f..5bfab358 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plAudioCore/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories(${Vorbis_INCLUDE_DIR}) set(plAudioCore_SOURCES plAudioFileReader.cpp plBufferedFileReader.cpp + plCachedFileReader.cpp plFastWavReader.cpp plOGGCodec.cpp plSoundBuffer.cpp @@ -22,6 +23,7 @@ set(plAudioCore_HEADERS plAudioCoreCreatable.h plAudioFileReader.h plBufferedFileReader.h + plCachedFileReader.h plFastWavReader.h plOGGCodec.h plSoundBuffer.h diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp new file mode 100644 index 00000000..870a684f --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp @@ -0,0 +1,176 @@ +/*==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 . + +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 "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(); +} + +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; +} diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h new file mode 100644 index 00000000..cc913c78 --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h @@ -0,0 +1,77 @@ +/*==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 . + +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() const { return fHeader; } + + 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: + char fFilename[512]; + FILE * fFileHandle; + plWAVHeader fHeader; + UInt32 fDataLength; + UInt32 fCurPosition; + + void IError(const char *msg); +}; + +#endif //_plcachedfilereader_h From 547ce8c0908e62e264e4f4fbfb26ef2e7a3afce2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 25 Apr 2011 19:15:54 -0700 Subject: [PATCH 02/15] Fixes to make it compile properly. --- .../Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp | 8 ++++++++ .../Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp index 870a684f..f1c30cb3 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp @@ -34,6 +34,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // // ////////////////////////////////////////////////////////////////////////////// +#include "hsTypes.h" #include "plCachedFileReader.h" //// Constructor/Destructor ////////////////////////////////////////////////// @@ -84,6 +85,13 @@ void plCachedFileReader::IError(const char *msg) Close(); } +plWAVHeader &plCachedFileReader::GetHeader() +{ + hsAssert(IsValid(), "GetHeader() called on an invalid cache file"); + + return fHeader; +} + void plCachedFileReader::Close() { if (fFileHandle != nil) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h index cc913c78..287437d2 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h @@ -48,7 +48,7 @@ public: plAudioCore::ChannelSelect whichChan = plAudioCore::kAll); virtual ~plCachedFileReader(); - virtual plWAVHeader &GetHeader() const { return fHeader; } + virtual plWAVHeader &GetHeader(); virtual void Close(); @@ -65,6 +65,11 @@ public: virtual hsBool IsValid() { return fFileHandle != nil; } protected: + enum + { + kPCMFormatTag = 1 + }; + char fFilename[512]; FILE * fFileHandle; plWAVHeader fHeader; From 7cecdae5c067922d9c2e58d253521e58a6258fd2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 25 Apr 2011 20:10:42 -0700 Subject: [PATCH 03/15] Don't use CWaveFile for caching sounds. As a sideeffect, cached sounds are no longer wave files. --- .../PubUtilLib/plAudioCore/plAudioFileReader.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp index 7568754c..46443245 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plFile/plFileUtils.h" #include "plUnifiedTime/plUnifiedTime.h" #include "plBufferedFileReader.h" +#include "plCachedFileReader.h" #include "plFastWavReader.h" #include "plOGGCodec.h" #include "plWavFile.h" @@ -73,7 +74,7 @@ plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore { char cachedPath[256]; IGetCachedPath(path, cachedPath, whichChan); - plAudioFileReader *r = TRACKED_NEW plFastWAV(cachedPath, plAudioCore::kAll); + plAudioFileReader *r = TRACKED_NEW plCachedFileReader(cachedPath, plAudioCore::kAll); return r; } @@ -92,7 +93,7 @@ plAudioFileReader* plAudioFileReader::CreateWriter(const char* path, plWAVHeader { 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); return writer; } @@ -113,11 +114,11 @@ void plAudioFileReader::IGetCachedPath(const char* path, char* cachedPath, plAud strncat(cachedPath, fileName, fileExt-fileName-1); if (whichChan == plAudioCore::kLeft) - strcat(cachedPath, "-Left.wav"); + strcat(cachedPath, "-Left.tmp"); else if (whichChan == plAudioCore::kRight) - strcat(cachedPath, "-Right.wav"); + strcat(cachedPath, "-Right.tmp"); else if (whichChan == plAudioCore::kAll) - strcat(cachedPath, ".wav"); + strcat(cachedPath, ".tmp"); } void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCore::ChannelSelect whichChan) From 31a0a83b10b8a94f8491e48ac5877d72a0c7e0a2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 25 Apr 2011 20:27:17 -0700 Subject: [PATCH 04/15] Remove unused plWAVClipBuffer class. --- .../Plasma/PubUtilLib/plAudio/CMakeLists.txt | 2 - .../PubUtilLib/plAudio/plWAVClipBuffer.cpp | 210 ------------------ .../PubUtilLib/plAudio/plWAVClipBuffer.h | 78 ------- 3 files changed, 290 deletions(-) delete mode 100644 Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.cpp delete mode 100644 Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.h diff --git a/Sources/Plasma/PubUtilLib/plAudio/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plAudio/CMakeLists.txt index 23c90923..27da66ce 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plAudio/CMakeLists.txt @@ -16,7 +16,6 @@ set(plAudio_SOURCES plSound.cpp plSoundEvent.cpp plVoiceChat.cpp - plWAVClipBuffer.cpp plWin32GroupedSound.cpp plWin32Sound.cpp plWin32StaticSound.cpp @@ -34,7 +33,6 @@ set(plAudio_HEADERS plSound.h plSoundEvent.h plVoiceChat.h - plWAVClipBuffer.h plWin32GroupedSound.h plWin32Sound.h plWin32StaticSound.h diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.cpp b/Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.cpp deleted file mode 100644 index cc34aea2..00000000 --- a/Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.cpp +++ /dev/null @@ -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 . - -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; -} diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.h b/Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.h deleted file mode 100644 index a631c703..00000000 --- a/Sources/Plasma/PubUtilLib/plAudio/plWAVClipBuffer.h +++ /dev/null @@ -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 . - -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 From 72ec482a3ef02fb2946d1245b0a9a0f3facbd806 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 25 Apr 2011 21:38:13 -0700 Subject: [PATCH 05/15] Do not build these as part of plClient. --- Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp | 4 ++++ Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp index 4dd0724e..d5784c0e 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp @@ -26,6 +26,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "plWavFile.h" +#ifdef MAXPLUGINCODE + #ifdef DX_OLD_SDK #include #else @@ -1091,3 +1093,5 @@ public: }; #endif + +#endif //MAXPLUGINCODE diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h index 6d36cdf7..ea772668 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h @@ -26,6 +26,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef plWavFile_H #define plWavFile_H +#ifdef MAXPLUGINCODE #define WAVEFILE_READ 1 #define WAVEFILE_WRITE 2 @@ -110,5 +111,6 @@ protected: HRESULT WriteMMIO( WAVEFORMATEX *pwfxDest ); HRESULT IClose(); }; +#endif //MAXPLUGINCODE #endif // plWavFile_H From 4da32cb955bfd561231f10bb305d8f124eb21601 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 26 Apr 2011 22:29:17 -0700 Subject: [PATCH 06/15] Fix some compiler warnings. --- Sources/Plasma/PubUtilLib/plAudio/plAudioCaps.cpp | 1 + Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plAudioCaps.cpp b/Sources/Plasma/PubUtilLib/plAudio/plAudioCaps.cpp index 1014f689..18e1bcd0 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plAudioCaps.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plAudioCaps.cpp @@ -39,6 +39,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #endif +#include #include #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp index 116659c5..8a392ca6 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp @@ -33,9 +33,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // // ////////////////////////////////////////////////////////////////////////////// -#include -#include -#include #include #include From bf142aa075addd11955df379e819c453e1b1c4d0 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 26 Apr 2011 23:33:22 -0700 Subject: [PATCH 07/15] Require winmm.lib for the microphone stuff. --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index e4c7667b..d0bd4802 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -214,6 +214,7 @@ if (WIN32) target_link_libraries(plClient Version) target_link_libraries(plClient Vfw32) target_link_libraries(plClient Ws2_32) + target_link_libraries(plClient winmm) target_link_libraries(plClient strmiids) endif(WIN32) From 08e401eabc6c4f01776c04fa477cbbc96d139473 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 26 Apr 2011 23:51:38 -0700 Subject: [PATCH 08/15] Change streamingCache to temp to prevent conflicts. --- Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp index 46443245..b3141e84 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -48,7 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plOGGCodec.h" #include "plWavFile.h" -#define kCacheDirName "streamingCache" +#define kCacheDirName "temp" static void hsStrUpper(char *s) { From c8284bd808b5f452fbabd40382d63c1cff4e3a7e Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 26 Apr 2011 23:52:00 -0700 Subject: [PATCH 09/15] Cache the file when it is played for the first time. --- Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp index b3141e84..59aedcc1 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -75,6 +75,12 @@ plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore char cachedPath[256]; IGetCachedPath(path, cachedPath, whichChan); 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 + ICacheFile(path, true, whichChan); + r = TRACKED_NEW plCachedFileReader(cachedPath, plAudioCore::kAll); + } return r; } From f64567e382930b46d5a1ae380c9cf4c7d741bd2e Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Wed, 27 Apr 2011 21:50:10 -0700 Subject: [PATCH 10/15] Don't build plClientPatcher (-2 warnings) --- Sources/Plasma/Apps/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/Apps/CMakeLists.txt b/Sources/Plasma/Apps/CMakeLists.txt index 9c6cef19..51823f67 100644 --- a/Sources/Plasma/Apps/CMakeLists.txt +++ b/Sources/Plasma/Apps/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory(plClient) -add_subdirectory(plClientPatcher) +#add_subdirectory(plClientPatcher) # This isn't used anywhere add_subdirectory(plPythonPack) add_subdirectory(plUruLauncher) From 0ac813c00331b574a4774308859d6f34f737ae4e Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 30 Apr 2011 13:56:18 -0700 Subject: [PATCH 11/15] Fix a memleak pointed out by Zrax. --- Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp index 59aedcc1..cafa6797 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -78,6 +78,7 @@ plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore 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); } From e218cab8f47c62ded314ead7f85b8bd7d9e96886 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 10 May 2011 08:19:48 -0700 Subject: [PATCH 12/15] Fix linking against winmm.lib for MaxMain. --- Sources/Tools/MaxMain/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Tools/MaxMain/CMakeLists.txt b/Sources/Tools/MaxMain/CMakeLists.txt index dfd469e9..d39c5d25 100644 --- a/Sources/Tools/MaxMain/CMakeLists.txt +++ b/Sources/Tools/MaxMain/CMakeLists.txt @@ -203,6 +203,7 @@ if (WIN32) target_link_libraries(MaxMain Strmiids) target_link_libraries(MaxMain Vfw32) target_link_libraries(MaxMain Ws2_32) + target_link_libraries(MaxMain winmm) endif(WIN32) source_group("Header Files" FILES ${MaxMain_HEADERS}) From d45786dadb23077a158004a6db39b7443f95f593 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 10 May 2011 15:21:04 -0700 Subject: [PATCH 13/15] Revert "Don't build plClientPatcher (-2 warnings)" This reverts commit ae7212bc5a40ee0ae959d3b3d97b258a890fd9f4. --- Sources/Plasma/Apps/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/Apps/CMakeLists.txt b/Sources/Plasma/Apps/CMakeLists.txt index 51823f67..9c6cef19 100644 --- a/Sources/Plasma/Apps/CMakeLists.txt +++ b/Sources/Plasma/Apps/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory(plClient) -#add_subdirectory(plClientPatcher) # This isn't used anywhere +add_subdirectory(plClientPatcher) add_subdirectory(plPythonPack) add_subdirectory(plUruLauncher) From 2bbf1f77f3aa2c2e4e96d900bbf815102aa07f02 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 11 May 2011 17:44:11 -0400 Subject: [PATCH 14/15] Change the Max Plugin defines so that CWaveFile is still available --- CMakeLists.txt | 2 +- Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp | 4 ++-- Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h | 4 ++-- Sources/Tools/CMakeLists.txt | 2 -- cmake/FindMaxSDK.cmake | 5 +++++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32e72045..1b4c51da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,4 +86,4 @@ endif(MSVC) include_directories(${OPENSSL_INCLUDE_DIR}) add_subdirectory(Sources/Plasma) -add_subdirectory(Sources/Tools) +add_subdirectory(Sources/Tools) \ No newline at end of file diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp index d5784c0e..02afb0b1 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.cpp @@ -26,7 +26,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "plWavFile.h" -#ifdef MAXPLUGINCODE +#ifdef BUILDING_MAXPLUGIN #ifdef DX_OLD_SDK #include @@ -1094,4 +1094,4 @@ public: #endif -#endif //MAXPLUGINCODE +#endif // BUILDING_MAXPLUGIN diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h index ea772668..f88d81fb 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h @@ -26,7 +26,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef plWavFile_H #define plWavFile_H -#ifdef MAXPLUGINCODE +#ifdef BUILDING_MAXPLUGIN #define WAVEFILE_READ 1 #define WAVEFILE_WRITE 2 @@ -111,6 +111,6 @@ protected: HRESULT WriteMMIO( WAVEFORMATEX *pwfxDest ); HRESULT IClose(); }; -#endif //MAXPLUGINCODE +#endif // BUILDING_MAXPLUGIN #endif // plWavFile_H diff --git a/Sources/Tools/CMakeLists.txt b/Sources/Tools/CMakeLists.txt index 40049d08..b7581384 100644 --- a/Sources/Tools/CMakeLists.txt +++ b/Sources/Tools/CMakeLists.txt @@ -4,8 +4,6 @@ #add_subdirectory(plResBrowser) # Max Stuff goes below here... -option(3dsm_BUILD_PLUGIN "Do we want to build the 3ds Max plugin?" OFF) - if(3dsm_BUILD_PLUGIN) add_definitions(-DMAXPLUGINCODE) diff --git a/cmake/FindMaxSDK.cmake b/cmake/FindMaxSDK.cmake index 90ebdff5..3a059d06 100644 --- a/cmake/FindMaxSDK.cmake +++ b/cmake/FindMaxSDK.cmake @@ -87,4 +87,9 @@ if (3dsm_FOUND) if(NOT 3dsm_FIND_QUIETLY) message(STATUS "Found 3ds Max SDK: ${3dsm_PATH}") endif() + + option(3dsm_BUILD_PLUGIN "Do we want to build the 3ds Max plugin?" OFF) + if (3dsm_BUILD_PLUGIN) + add_definitions(-DBUILDING_MAXPLUGIN) + endif() endif() \ No newline at end of file From e59e3258c1300a077ff7994536299542002c02a6 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 11 May 2011 18:07:22 -0400 Subject: [PATCH 15/15] Fix for fCurPosition being uninitialized garbage --- Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp index f1c30cb3..2b812c93 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp @@ -41,7 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com plCachedFileReader::plCachedFileReader(const char *path, plAudioCore::ChannelSelect whichChan) - : fFileHandle(nil) + : fFileHandle(nil), fCurPosition(0) { hsAssert(path != nil, "Invalid path specified in plCachedFileReader");