00001 /* 00002 * RageSoundReader_Preload - Preload sounds from another reader 00003 */ 00004 00005 #ifndef RAGE_SOUND_READER_PRELOAD 00006 #define RAGE_SOUND_READER_PRELOAD 00007 00008 #include "RageSoundReader.h" 00009 00010 /* Trivial wrapper to refcount strings, since std::string is not always 00011 * refcounted. Without this, Copy() is very slow. */ 00012 class rc_string 00013 { 00014 mutable string *buf; 00015 mutable int *cnt; 00016 00017 public: 00018 rc_string(); 00019 rc_string(const rc_string &rhs); 00020 ~rc_string(); 00021 string &get_owned(); 00022 const string &get() const; 00023 }; 00024 00025 class RageSoundReader_Preload: public SoundReader 00026 { 00027 rc_string buf; 00028 00029 /* Bytes: */ 00030 int position; 00031 00032 int total_samples() const; 00033 00034 int samplerate; 00035 unsigned channels; 00036 float OffsetFix; 00037 00038 public: 00039 /* Return true if the sound has been preloaded, in which case source will 00040 * be deleted. Otherwise, return false. */ 00041 bool Open(SoundReader *source); 00042 int GetLength() const; 00043 int GetLength_Fast() const; 00044 int SetPosition_Accurate(int ms); 00045 int SetPosition_Fast(int ms); 00046 int Read(char *buf, unsigned len); 00047 int GetSampleRate() const { return samplerate; } 00048 unsigned GetNumChannels() const { return channels; } 00049 bool IsStreamingFromDisk() const { return false; } 00050 00051 SoundReader *Copy() const; 00052 ~RageSoundReader_Preload() { } 00053 00054 /* Attempt to preload a sound. pSound must be rewound. */ 00055 static bool PreloadSound( SoundReader *&pSound ); 00056 }; 00057 00058 #endif 00059 00060 /* 00061 * Copyright (c) 2003 Glenn Maynard 00062 * All rights reserved. 00063 * 00064 * Permission is hereby granted, free of charge, to any person obtaining a 00065 * copy of this software and associated documentation files (the 00066 * "Software"), to deal in the Software without restriction, including 00067 * without limitation the rights to use, copy, modify, merge, publish, 00068 * distribute, and/or sell copies of the Software, and to permit persons to 00069 * whom the Software is furnished to do so, provided that the above 00070 * copyright notice(s) and this permission notice appear in all copies of 00071 * the Software and that both the above copyright notice(s) and this 00072 * permission notice appear in supporting documentation. 00073 * 00074 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00075 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00076 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00077 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00078 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00079 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00080 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00081 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00082 * PERFORMANCE OF THIS SOFTWARE. 00083 */