Use a separate type for streams

They're basically the same, but it's to help avoid accidents with passing non-
streaming sounds to the stream functions, or vice-versa.
openmw-38
Chris Robinson 9 years ago
parent 816015d6e6
commit 1ce3e7f5b9

@ -15,6 +15,7 @@ namespace MWWorld
namespace MWSound
{
class Sound;
class Stream;
struct Sound_Decoder;
typedef boost::shared_ptr<Sound_Decoder> DecoderPtr;
}
@ -22,6 +23,7 @@ namespace MWSound
namespace MWBase
{
typedef boost::shared_ptr<MWSound::Sound> SoundPtr;
typedef boost::shared_ptr<MWSound::Stream> SoundStreamPtr;
/// \brief Interface for sound manager (implemented in MWSound)
class SoundManager
@ -104,13 +106,13 @@ namespace MWBase
/// and get an average loudness value (scale [0,1]) at the current time position.
/// If the actor is not saying anything, returns 0.
virtual SoundPtr playTrack(const MWSound::DecoderPtr& decoder, PlayType type) = 0;
virtual SoundStreamPtr playTrack(const MWSound::DecoderPtr& decoder, PlayType type) = 0;
///< Play a 2D audio track, using a custom decoder
virtual void stopTrack(SoundPtr sound) = 0;
virtual void stopTrack(SoundStreamPtr stream) = 0;
///< Stop the given audio track from playing
virtual double getTrackTimeDelay(SoundPtr sound) = 0;
virtual double getTrackTimeDelay(SoundStreamPtr stream) = 0;
///< Retives the time delay, in seconds, of the audio track (must be a sound
/// returned by \ref playTrack). Only intended to be called by the track
/// decoder's read method.
@ -166,7 +168,7 @@ namespace MWBase
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up) = 0;
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0;
virtual void updatePtr(const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0;
virtual void clear() = 0;
};

@ -92,7 +92,7 @@ namespace MWSound
mDecoderBridge.reset();
}
MWBase::SoundPtr mAudioTrack;
MWBase::SoundStreamPtr mAudioTrack;
boost::shared_ptr<MWSoundDecoderBridge> mDecoderBridge;
};
@ -163,7 +163,8 @@ namespace MWSound
boost::shared_ptr<MWSound::MovieAudioDecoder> decoder(new MWSound::MovieAudioDecoder(videoState));
decoder->setupFormat();
MWBase::SoundPtr sound = MWBase::Environment::get().getSoundManager()->playTrack(decoder->mDecoderBridge, MWBase::SoundManager::Play_TypeMovie);
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
MWBase::SoundStreamPtr sound = sndMgr->playTrack(decoder->mDecoderBridge, MWBase::SoundManager::Play_TypeMovie);
if (!sound.get())
{
decoder.reset();

@ -776,9 +776,9 @@ bool OpenAL_Output::isSoundPlaying(MWBase::SoundPtr sound)
}
MWBase::SoundPtr OpenAL_Output::streamSound(DecoderPtr decoder, float basevol, float pitch, int flags)
MWBase::SoundStreamPtr OpenAL_Output::streamSound(DecoderPtr decoder, float basevol, float pitch, int flags)
{
boost::shared_ptr<Sound> sound;
MWBase::SoundStreamPtr sound;
OpenAL_SoundStream *stream = 0;
ALuint source;
@ -810,7 +810,7 @@ MWBase::SoundPtr OpenAL_Output::streamSound(DecoderPtr decoder, float basevol, f
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
throwALerror();
sound.reset(new Sound(osg::Vec3f(0.0f, 0.0f, 0.0f), 1.0f, basevol, pitch, 1.0f, 1000.0f, flags));
sound.reset(new Stream(osg::Vec3f(0.0f, 0.0f, 0.0f), 1.0f, basevol, pitch, 1.0f, 1000.0f, flags));
stream = new OpenAL_SoundStream(source, decoder);
mStreamThread->add(stream);
sound->mHandle = stream;
@ -826,9 +826,9 @@ MWBase::SoundPtr OpenAL_Output::streamSound(DecoderPtr decoder, float basevol, f
return sound;
}
MWBase::SoundPtr OpenAL_Output::streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos, float volume, float basevol, float pitch, float mindist, float maxdist, int flags)
MWBase::SoundStreamPtr OpenAL_Output::streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos, float volume, float basevol, float pitch, float mindist, float maxdist, int flags)
{
boost::shared_ptr<Sound> sound;
MWBase::SoundStreamPtr sound;
OpenAL_SoundStream *stream = 0;
ALuint source;
@ -862,7 +862,7 @@ MWBase::SoundPtr OpenAL_Output::streamSound3D(DecoderPtr decoder, const osg::Vec
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
throwALerror();
sound.reset(new Sound(pos, volume, basevol, pitch, mindist, maxdist, flags));
sound.reset(new Stream(pos, volume, basevol, pitch, mindist, maxdist, flags));
stream = new OpenAL_SoundStream(source, decoder);
mStreamThread->add(stream);
sound->mHandle = stream;
@ -878,7 +878,7 @@ MWBase::SoundPtr OpenAL_Output::streamSound3D(DecoderPtr decoder, const osg::Vec
return sound;
}
void OpenAL_Output::stopStream(MWBase::SoundPtr sound)
void OpenAL_Output::stopStream(MWBase::SoundStreamPtr sound)
{
if(!sound->mHandle)
return;
@ -897,7 +897,7 @@ void OpenAL_Output::stopStream(MWBase::SoundPtr sound)
delete stream;
}
double OpenAL_Output::getStreamDelay(MWBase::SoundPtr sound)
double OpenAL_Output::getStreamDelay(MWBase::SoundStreamPtr sound)
{
if(!sound->mHandle)
return 0.0;
@ -905,7 +905,7 @@ double OpenAL_Output::getStreamDelay(MWBase::SoundPtr sound)
return stream->getStreamDelay();
}
double OpenAL_Output::getStreamOffset(MWBase::SoundPtr sound)
double OpenAL_Output::getStreamOffset(MWBase::SoundStreamPtr sound)
{
if(!sound->mHandle)
return 0.0;
@ -914,7 +914,7 @@ double OpenAL_Output::getStreamOffset(MWBase::SoundPtr sound)
return stream->getStreamOffset();
}
bool OpenAL_Output::isStreamPlaying(MWBase::SoundPtr sound)
bool OpenAL_Output::isStreamPlaying(MWBase::SoundStreamPtr sound)
{
if(!sound->mHandle)
return false;

@ -26,7 +26,7 @@ namespace MWSound
typedef std::vector<MWBase::SoundPtr> SoundVec;
SoundVec mActiveSounds;
typedef std::vector<MWBase::SoundPtr> StreamVec;
typedef std::vector<MWBase::SoundStreamPtr> StreamVec;
StreamVec mActiveStreams;
Environment mLastEnvironment;
@ -45,13 +45,13 @@ namespace MWSound
virtual void stopSound(MWBase::SoundPtr sound);
virtual bool isSoundPlaying(MWBase::SoundPtr sound);
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags);
virtual MWBase::SoundPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
float vol, float basevol, float pitch, float min, float max, int flags);
virtual void stopStream(MWBase::SoundPtr sound);
virtual double getStreamDelay(MWBase::SoundPtr sound);
virtual double getStreamOffset(MWBase::SoundPtr sound);
virtual bool isStreamPlaying(MWBase::SoundPtr sound);
virtual MWBase::SoundStreamPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags);
virtual MWBase::SoundStreamPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
float vol, float basevol, float pitch, float min, float max, int flags);
virtual void stopStream(MWBase::SoundStreamPtr sound);
virtual double getStreamDelay(MWBase::SoundStreamPtr sound);
virtual double getStreamOffset(MWBase::SoundStreamPtr sound);
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound);
virtual void startUpdate();
virtual void finishUpdate();

@ -5,8 +5,7 @@
namespace MWSound
{
class Sound
{
class Sound {
Sound& operator=(const Sound &rhs);
Sound(const Sound &rhs);
@ -51,7 +50,17 @@ namespace MWSound
, mMinDistance(mindist), mMaxDistance(maxdist), mFlags(flags)
, mFadeOutTime(0.0f), mHandle(0)
{ }
~Sound() { }
};
// Same as above, but it's a different type since the output handles them differently
class Stream : public Sound {
Stream& operator=(const Stream &rhs);
Stream(const Stream &rhs);
public:
Stream(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
: Sound(pos, vol, basevol, pitch, mindist, maxdist, flags)
{ }
};
}

@ -38,13 +38,13 @@ namespace MWSound
virtual void stopSound(MWBase::SoundPtr sound) = 0;
virtual bool isSoundPlaying(MWBase::SoundPtr sound) = 0;
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags) = 0;
virtual MWBase::SoundPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
float vol, float basevol, float pitch, float min, float max, int flags) = 0;
virtual void stopStream(MWBase::SoundPtr sound) = 0;
virtual double getStreamDelay(MWBase::SoundPtr sound) = 0;
virtual double getStreamOffset(MWBase::SoundPtr sound) = 0;
virtual bool isStreamPlaying(MWBase::SoundPtr sound) = 0;
virtual MWBase::SoundStreamPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags) = 0;
virtual MWBase::SoundStreamPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
float vol, float basevol, float pitch, float min, float max, int flags) = 0;
virtual void stopStream(MWBase::SoundStreamPtr sound) = 0;
virtual double getStreamDelay(MWBase::SoundStreamPtr sound) = 0;
virtual double getStreamOffset(MWBase::SoundStreamPtr sound) = 0;
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound) = 0;
virtual void startUpdate() = 0;
virtual void finishUpdate() = 0;

@ -241,7 +241,7 @@ namespace MWSound
return decoder;
}
MWBase::SoundPtr SoundManager::playVoice(DecoderPtr decoder, const osg::Vec3f &pos, bool playlocal)
MWBase::SoundStreamPtr SoundManager::playVoice(DecoderPtr decoder, const osg::Vec3f &pos, bool playlocal)
{
MWBase::World* world = MWBase::Environment::get().getWorld();
static const float fAudioMinDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMinDistanceMult")->getFloat();
@ -392,7 +392,7 @@ namespace MWSound
mPendingSaySounds[ptr] = std::make_pair(decoder, loudness);
else
{
MWBase::SoundPtr sound = playVoice(decoder, objpos, (ptr == MWMechanics::getPlayer()));
MWBase::SoundStreamPtr sound = playVoice(decoder, objpos, (ptr == MWMechanics::getPlayer()));
mActiveSaySounds[ptr] = std::make_pair(sound, loudness);
}
}
@ -407,7 +407,7 @@ namespace MWSound
SaySoundMap::const_iterator snditer = mActiveSaySounds.find(ptr);
if(snditer != mActiveSaySounds.end())
{
MWBase::SoundPtr sound = snditer->second.first;
MWBase::SoundStreamPtr sound = snditer->second.first;
Sound_Loudness *loudness = snditer->second.second;
float sec = mOutput->getStreamOffset(sound);
return loudness->getLoudnessAtTime(sec);
@ -432,7 +432,7 @@ namespace MWSound
mPendingSaySounds[MWWorld::Ptr()] = std::make_pair(decoder, loudness);
else
{
MWBase::SoundPtr sound = playVoice(decoder, osg::Vec3f(), true);
MWBase::SoundStreamPtr sound = playVoice(decoder, osg::Vec3f(), true);
mActiveSaySounds[MWWorld::Ptr()] = std::make_pair(sound, loudness);
}
}
@ -466,9 +466,9 @@ namespace MWSound
}
MWBase::SoundPtr SoundManager::playTrack(const DecoderPtr& decoder, PlayType type)
MWBase::SoundStreamPtr SoundManager::playTrack(const DecoderPtr& decoder, PlayType type)
{
MWBase::SoundPtr track;
MWBase::SoundStreamPtr track;
if(!mOutput->isInitialized())
return track;
try
@ -482,14 +482,14 @@ namespace MWSound
return track;
}
void SoundManager::stopTrack(MWBase::SoundPtr sound)
void SoundManager::stopTrack(MWBase::SoundStreamPtr stream)
{
mOutput->stopStream(sound);
mOutput->stopStream(stream);
}
double SoundManager::getTrackTimeDelay(MWBase::SoundPtr sound)
double SoundManager::getTrackTimeDelay(MWBase::SoundStreamPtr stream)
{
return mOutput->getStreamDelay(sound);
return mOutput->getStreamDelay(stream);
}
@ -876,7 +876,7 @@ namespace MWSound
const ESM::Position &pos = ptr.getRefData().getPosition();
const osg::Vec3f objpos(pos.asVec3());
MWBase::SoundPtr sound = playVoice(decoder,
MWBase::SoundStreamPtr sound = playVoice(decoder,
objpos, (ptr == MWMechanics::getPlayer())
);
mActiveSaySounds[ptr] = std::make_pair(sound, loudness);
@ -895,7 +895,7 @@ namespace MWSound
while(sayiter != mActiveSaySounds.end())
{
MWWorld::Ptr ptr = sayiter->first;
MWBase::SoundPtr sound = sayiter->second.first;
MWBase::SoundStreamPtr sound = sayiter->second.first;
if(!ptr.isEmpty() && sound->getIs3D())
{
const ESM::Position &pos = ptr.getRefData().getPosition();
@ -963,7 +963,7 @@ namespace MWSound
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
for(;sayiter != mActiveSaySounds.end();++sayiter)
{
MWBase::SoundPtr sound = sayiter->second.first;
MWBase::SoundStreamPtr sound = sayiter->second.first;
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
}
if(mMusic)

@ -79,7 +79,7 @@ namespace MWSound
typedef std::deque<Sound_Buffer*> SoundList;
SoundList mUnusedBuffers;
boost::shared_ptr<Sound> mMusic;
MWBase::SoundStreamPtr mMusic;
std::string mCurrentPlaylist;
typedef std::pair<MWBase::SoundPtr,Sound_Buffer*> SoundBufferRefPair;
@ -87,7 +87,7 @@ namespace MWSound
typedef std::map<MWWorld::Ptr,SoundBufferRefPairList> SoundMap;
SoundMap mActiveSounds;
typedef std::pair<MWBase::SoundPtr,Sound_Loudness*> SoundLoudnessPair;
typedef std::pair<MWBase::SoundStreamPtr,Sound_Loudness*> SoundLoudnessPair;
typedef std::map<MWWorld::Ptr,SoundLoudnessPair> SaySoundMap;
SaySoundMap mActiveSaySounds;
@ -113,7 +113,7 @@ namespace MWSound
// to start streaming
DecoderPtr loadVoice(const std::string &voicefile, Sound_Loudness **lipdata);
MWBase::SoundPtr playVoice(DecoderPtr decoder, const osg::Vec3f &pos, bool playlocal);
MWBase::SoundStreamPtr playVoice(DecoderPtr decoder, const osg::Vec3f &pos, bool playlocal);
void streamMusicFull(const std::string& filename);
void updateSounds(float duration);
@ -170,13 +170,13 @@ namespace MWSound
/// and get an average loudness value (scale [0,1]) at the current time position.
/// If the actor is not saying anything, returns 0.
virtual MWBase::SoundPtr playTrack(const DecoderPtr& decoder, PlayType type);
virtual MWBase::SoundStreamPtr playTrack(const DecoderPtr& decoder, PlayType type);
///< Play a 2D audio track, using a custom decoder
virtual void stopTrack(MWBase::SoundPtr sound);
virtual void stopTrack(MWBase::SoundStreamPtr stream);
///< Stop the given audio track from playing
virtual double getTrackTimeDelay(MWBase::SoundPtr sound);
virtual double getTrackTimeDelay(MWBase::SoundStreamPtr stream);
///< Retives the time delay, in seconds, of the audio track (must be a sound
/// returned by \ref playTrack). Only intended to be called by the track
/// decoder's read method.

Loading…
Cancel
Save