Rename apps/openmw/mwsound files and classes to follow naming conventions

This commit is contained in:
Alexei Kotov 2025-02-22 23:45:51 +03:00
parent fc850cfe69
commit 72cbf61b43
17 changed files with 185 additions and 194 deletions

View file

@ -1,9 +0,0 @@
apps/openmw/mwsound/efx-presets.h
apps/openmw/mwsound/ffmpeg_decoder.cpp
apps/openmw/mwsound/ffmpeg_decoder.hpp
apps/openmw/mwsound/openal_output.cpp
apps/openmw/mwsound/openal_output.hpp
apps/openmw/mwsound/sound_buffer.cpp
apps/openmw/mwsound/sound_buffer.hpp
apps/openmw/mwsound/sound_decoder.hpp
apps/openmw/mwsound/sound_output.hpp

View file

@ -71,8 +71,8 @@ add_openmw_dir (mwlua
)
add_openmw_dir (mwsound
soundmanagerimp openal_output ffmpeg_decoder sound sound_buffer sound_decoder sound_output
loudness movieaudiofactory alext efx efx-presets regionsoundselector watersoundupdater
soundmanagerimp openaloutput ffmpegdecoder sound soundbuffer sounddecoder soundoutput
loudness movieaudiofactory alext efx efxpresets regionsoundselector watersoundupdater
)
add_openmw_dir (mwworld

View file

@ -39,8 +39,8 @@ namespace MWSound
class Sound;
class Stream;
struct Sound_Decoder;
typedef std::shared_ptr<Sound_Decoder> DecoderPtr;
struct SoundDecoder;
typedef std::shared_ptr<SoundDecoder> DecoderPtr;
/* These must all fit together */
enum class PlayMode

View file

@ -1,7 +1,7 @@
/* Reverb presets for EFX */
#ifndef EFX_PRESETS_H
#define EFX_PRESETS_H
#ifndef GAME_SOUND_EFXPRESETS_H
#define GAME_SOUND_EFXPRESETS_H
#ifndef EFXEAXREVERBPROPERTIES_DEFINED
#define EFXEAXREVERBPROPERTIES_DEFINED
@ -852,4 +852,4 @@ typedef struct
0.1900f, 0.9920f, 5000.0000f, 250.0000f, 0.0000f, 0x0 \
}
#endif /* EFX_PRESETS_H */
#endif

View file

@ -1,4 +1,4 @@
#include "ffmpeg_decoder.hpp"
#include "ffmpegdecoder.hpp"
#include <algorithm>
#include <memory>
@ -44,11 +44,11 @@ namespace MWSound
av_frame_free(&ptr);
}
int FFmpeg_Decoder::readPacket(void* user_data, uint8_t* buf, int buf_size)
int FFmpegDecoder::readPacket(void* user_data, uint8_t* buf, int buf_size)
{
try
{
std::istream& stream = *static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;
std::istream& stream = *static_cast<FFmpegDecoder*>(user_data)->mDataStream;
stream.clear();
stream.read((char*)buf, buf_size);
std::streamsize count = stream.gcount();
@ -65,18 +65,18 @@ namespace MWSound
}
#if OPENMW_FFMPEG_CONST_WRITEPACKET
int FFmpeg_Decoder::writePacket(void*, const uint8_t*, int)
int FFmpegDecoder::writePacket(void*, const uint8_t*, int)
#else
int FFmpeg_Decoder::writePacket(void*, uint8_t*, int)
int FFmpegDecoder::writePacket(void*, uint8_t*, int)
#endif
{
Log(Debug::Error) << "can't write to read-only stream";
return -1;
}
int64_t FFmpeg_Decoder::seek(void* user_data, int64_t offset, int whence)
int64_t FFmpegDecoder::seek(void* user_data, int64_t offset, int whence)
{
std::istream& stream = *static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;
std::istream& stream = *static_cast<FFmpegDecoder*>(user_data)->mDataStream;
whence &= ~AVSEEK_FORCE;
@ -106,7 +106,7 @@ namespace MWSound
/* Used by getAV*Data to search for more compressed data, and buffer it in the
* correct stream. It won't buffer data for streams that the app doesn't have a
* handle for. */
bool FFmpeg_Decoder::getNextPacket()
bool FFmpegDecoder::getNextPacket()
{
if (!mStream)
return false;
@ -129,7 +129,7 @@ namespace MWSound
return false;
}
bool FFmpeg_Decoder::getAVAudioData()
bool FFmpegDecoder::getAVAudioData()
{
bool got_frame = false;
@ -192,7 +192,7 @@ namespace MWSound
return true;
}
size_t FFmpeg_Decoder::readAVAudioData(void* data, size_t length)
size_t FFmpegDecoder::readAVAudioData(void* data, size_t length)
{
size_t dec = 0;
@ -227,7 +227,7 @@ namespace MWSound
return dec;
}
void FFmpeg_Decoder::open(VFS::Path::NormalizedView fname)
void FFmpegDecoder::open(VFS::Path::NormalizedView fname)
{
close();
mDataStream = mResourceMgr->get(fname);
@ -317,7 +317,7 @@ namespace MWSound
mStream = stream;
}
void FFmpeg_Decoder::close()
void FFmpegDecoder::close()
{
mStream = nullptr;
mCodecCtx.reset();
@ -332,7 +332,7 @@ namespace MWSound
mDataStream.reset();
}
std::string FFmpeg_Decoder::getName()
std::string FFmpegDecoder::getName()
{
// In the FFMpeg 4.0 a "filename" field was replaced by "url"
#if LIBAVCODEC_VERSION_INT < 3805796
@ -342,7 +342,7 @@ namespace MWSound
#endif
}
void FFmpeg_Decoder::getInfo(int* samplerate, ChannelConfig* chans, SampleType* type)
void FFmpegDecoder::getInfo(int* samplerate, ChannelConfig* chans, SampleType* type)
{
if (!mStream)
throw std::runtime_error("No audio stream info");
@ -459,7 +459,7 @@ namespace MWSound
}
}
size_t FFmpeg_Decoder::read(char* buffer, size_t bytes)
size_t FFmpegDecoder::read(char* buffer, size_t bytes)
{
if (!mStream)
{
@ -469,7 +469,7 @@ namespace MWSound
return readAVAudioData(buffer, bytes);
}
void FFmpeg_Decoder::readAll(std::vector<char>& output)
void FFmpegDecoder::readAll(std::vector<char>& output)
{
if (!mStream)
{
@ -490,7 +490,7 @@ namespace MWSound
}
}
size_t FFmpeg_Decoder::getSampleOffset()
size_t FFmpegDecoder::getSampleOffset()
{
#if OPENMW_FFMPEG_5_OR_GREATER
std::size_t delay = (mFrameSize - mFramePos) / mOutputChannelLayout.nb_channels
@ -501,8 +501,8 @@ namespace MWSound
return static_cast<std::size_t>(mNextPts * mCodecCtx->sample_rate) - delay;
}
FFmpeg_Decoder::FFmpeg_Decoder(const VFS::Manager* vfs)
: Sound_Decoder(vfs)
FFmpegDecoder::FFmpegDecoder(const VFS::Manager* vfs)
: SoundDecoder(vfs)
, mStream(nullptr)
, mFrameSize(0)
, mFramePos(0)
@ -534,7 +534,7 @@ namespace MWSound
}
}
FFmpeg_Decoder::~FFmpeg_Decoder()
FFmpegDecoder::~FFmpegDecoder()
{
close();
}

View file

@ -1,5 +1,5 @@
#ifndef GAME_SOUND_FFMPEG_DECODER_H
#define GAME_SOUND_FFMPEG_DECODER_H
#ifndef GAME_SOUND_FFMPEGDECODER_H
#define GAME_SOUND_FFMPEGDECODER_H
#include <cstdint>
@ -31,7 +31,7 @@ extern "C"
#include <string>
#include "sound_decoder.hpp"
#include "sounddecoder.hpp"
namespace MWSound
{
@ -63,7 +63,7 @@ namespace MWSound
using AVFramePtr = std::unique_ptr<AVFrame, AVFrameDeleter>;
class FFmpeg_Decoder final : public Sound_Decoder
class FFmpegDecoder final : public SoundDecoder
{
AVIOContextPtr mIoCtx;
AVFormatContextPtr mFormatCtx;
@ -114,13 +114,13 @@ namespace MWSound
void readAll(std::vector<char>& output) override;
size_t getSampleOffset() override;
FFmpeg_Decoder& operator=(const FFmpeg_Decoder& rhs);
FFmpeg_Decoder(const FFmpeg_Decoder& rhs);
FFmpegDecoder& operator=(const FFmpegDecoder& rhs);
FFmpegDecoder(const FFmpegDecoder& rhs);
public:
explicit FFmpeg_Decoder(const VFS::Manager* vfs);
explicit FFmpegDecoder(const VFS::Manager* vfs);
virtual ~FFmpeg_Decoder();
virtual ~FFmpegDecoder();
friend class SoundManager;
};

View file

@ -4,7 +4,7 @@
#include <deque>
#include <vector>
#include "sound_decoder.hpp"
#include "sounddecoder.hpp"
namespace MWSound
{

View file

@ -7,17 +7,17 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
#include "sound_decoder.hpp"
#include "sounddecoder.hpp"
namespace MWSound
{
class MovieAudioDecoder;
class MWSoundDecoderBridge final : public Sound_Decoder
class MWSoundDecoderBridge final : public SoundDecoder
{
public:
MWSoundDecoderBridge(MWSound::MovieAudioDecoder* decoder)
: Sound_Decoder(nullptr)
: SoundDecoder(nullptr)
, mDecoder(decoder)
{
}

View file

@ -17,14 +17,13 @@
#include <components/misc/thread.hpp>
#include <components/vfs/manager.hpp>
#include "efxpresets.h"
#include "loudness.hpp"
#include "openal_output.hpp"
#include "openaloutput.hpp"
#include "sound.hpp"
#include "sound_decoder.hpp"
#include "sounddecoder.hpp"
#include "soundmanagerimp.hpp"
#include "efx-presets.h"
#ifndef ALC_ALL_DEVICES_SPECIFIER
#define ALC_ALL_DEVICES_SPECIFIER 0x1013
#endif
@ -301,7 +300,7 @@ namespace MWSound
OpenAL_SoundStream(const OpenAL_SoundStream& rhs);
OpenAL_SoundStream& operator=(const OpenAL_SoundStream& rhs);
friend class OpenAL_Output;
friend class OpenALOutput;
public:
OpenAL_SoundStream(ALuint src, DecoderPtr decoder);
@ -323,7 +322,7 @@ namespace MWSound
//
// A background streaming thread (keeps active streams processed)
//
struct OpenAL_Output::StreamThread
struct OpenALOutput::StreamThread
{
std::vector<OpenAL_SoundStream*> mStreams;
@ -393,13 +392,13 @@ namespace MWSound
StreamThread& operator=(const StreamThread& rhs) = delete;
};
class OpenAL_Output::DefaultDeviceThread
class OpenALOutput::DefaultDeviceThread
{
public:
std::basic_string<ALCchar> mCurrentName;
private:
OpenAL_Output& mOutput;
OpenALOutput& mOutput;
std::atomic<bool> mQuitNow;
std::mutex mMutex;
@ -433,7 +432,7 @@ namespace MWSound
}
public:
DefaultDeviceThread(OpenAL_Output& output, std::basic_string_view<ALCchar> name = {})
DefaultDeviceThread(OpenALOutput& output, std::basic_string_view<ALCchar> name = {})
: mCurrentName(name)
, mOutput(output)
, mQuitNow(false)
@ -655,7 +654,7 @@ namespace MWSound
//
// An OpenAL output device
//
std::vector<std::string> OpenAL_Output::enumerate()
std::vector<std::string> OpenALOutput::enumerate()
{
std::vector<std::string> devlist;
const ALCchar* devnames;
@ -672,14 +671,14 @@ namespace MWSound
return devlist;
}
void OpenAL_Output::eventCallback(
void OpenALOutput::eventCallback(
ALenum eventType, ALuint object, ALuint param, ALsizei length, const ALchar* message, void* userParam)
{
if (eventType == AL_EVENT_TYPE_DISCONNECTED_SOFT)
static_cast<OpenAL_Output*>(userParam)->onDisconnect();
static_cast<OpenALOutput*>(userParam)->onDisconnect();
}
void OpenAL_Output::onDisconnect()
void OpenALOutput::onDisconnect()
{
if (!mInitialized || !alcReopenDeviceSOFT)
return;
@ -702,7 +701,7 @@ namespace MWSound
}
}
bool OpenAL_Output::init(const std::string& devname, const std::string& hrtfname, HrtfMode hrtfmode)
bool OpenALOutput::init(const std::string& devname, const std::string& hrtfname, HrtfMode hrtfmode)
{
deinit();
std::lock_guard<std::mutex> lock(mReopenMutex);
@ -802,7 +801,7 @@ namespace MWSound
{
static const std::array<ALenum, 1> events{ { AL_EVENT_TYPE_DISCONNECTED_SOFT } };
alEventControlSOFT(events.size(), events.data(), AL_TRUE);
alEventCallbackSOFT(&OpenAL_Output::eventCallback, this);
alEventCallbackSOFT(&OpenALOutput::eventCallback, this);
}
else
Log(Debug::Warning) << "Cannot detect audio device changes";
@ -970,7 +969,7 @@ namespace MWSound
return true;
}
void OpenAL_Output::deinit()
void OpenALOutput::deinit()
{
mStreamThread->removeAll();
mDefaultDeviceThread.reset();
@ -1006,7 +1005,7 @@ namespace MWSound
mInitialized = false;
}
std::vector<std::string> OpenAL_Output::enumerateHrtf()
std::vector<std::string> OpenALOutput::enumerateHrtf()
{
std::vector<std::string> ret;
@ -1028,7 +1027,7 @@ namespace MWSound
return ret;
}
std::pair<Sound_Handle, size_t> OpenAL_Output::loadSound(VFS::Path::NormalizedView fname)
std::pair<Sound_Handle, size_t> OpenALOutput::loadSound(VFS::Path::NormalizedView fname)
{
getALError();
@ -1076,7 +1075,7 @@ namespace MWSound
return std::make_pair(MAKE_PTRID(buf), size);
}
size_t OpenAL_Output::unloadSound(Sound_Handle data)
size_t OpenALOutput::unloadSound(Sound_Handle data)
{
ALuint buffer = GET_PTRID(data);
if (!buffer)
@ -1105,7 +1104,7 @@ namespace MWSound
return size;
}
void OpenAL_Output::initCommon2D(
void OpenALOutput::initCommon2D(
ALuint source, const osg::Vec3f& pos, ALfloat gain, ALfloat pitch, bool loop, bool useenv)
{
alSourcef(source, AL_REFERENCE_DISTANCE, 1.0f);
@ -1143,7 +1142,7 @@ namespace MWSound
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
}
void OpenAL_Output::initCommon3D(ALuint source, const osg::Vec3f& pos, ALfloat mindist, ALfloat maxdist,
void OpenALOutput::initCommon3D(ALuint source, const osg::Vec3f& pos, ALfloat mindist, ALfloat maxdist,
ALfloat gain, ALfloat pitch, bool loop, bool useenv)
{
alSourcef(source, AL_REFERENCE_DISTANCE, mindist);
@ -1183,7 +1182,7 @@ namespace MWSound
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
}
void OpenAL_Output::updateCommon(
void OpenALOutput::updateCommon(
ALuint source, const osg::Vec3f& pos, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool useenv)
{
if (useenv && mListenerEnv == Env_Underwater && !mWaterFilter)
@ -1199,7 +1198,7 @@ namespace MWSound
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
}
bool OpenAL_Output::playSound(Sound* sound, Sound_Handle data, float offset)
bool OpenALOutput::playSound(Sound* sound, Sound_Handle data, float offset)
{
ALuint source;
@ -1238,7 +1237,7 @@ namespace MWSound
return true;
}
bool OpenAL_Output::playSound3D(Sound* sound, Sound_Handle data, float offset)
bool OpenALOutput::playSound3D(Sound* sound, Sound_Handle data, float offset)
{
ALuint source;
@ -1277,7 +1276,7 @@ namespace MWSound
return true;
}
void OpenAL_Output::finishSound(Sound* sound)
void OpenALOutput::finishSound(Sound* sound)
{
if (!sound->mHandle)
return;
@ -1294,7 +1293,7 @@ namespace MWSound
mActiveSounds.erase(std::find(mActiveSounds.begin(), mActiveSounds.end(), sound));
}
bool OpenAL_Output::isSoundPlaying(Sound* sound)
bool OpenALOutput::isSoundPlaying(Sound* sound)
{
if (!sound->mHandle)
return false;
@ -1307,7 +1306,7 @@ namespace MWSound
return state == AL_PLAYING || state == AL_PAUSED;
}
void OpenAL_Output::updateSound(Sound* sound)
void OpenALOutput::updateSound(Sound* sound)
{
if (!sound->mHandle)
return;
@ -1318,7 +1317,7 @@ namespace MWSound
getALError();
}
bool OpenAL_Output::streamSound(DecoderPtr decoder, Stream* sound, bool getLoudnessData)
bool OpenALOutput::streamSound(DecoderPtr decoder, Stream* sound, bool getLoudnessData)
{
if (mFreeSources.empty())
{
@ -1349,7 +1348,7 @@ namespace MWSound
return true;
}
bool OpenAL_Output::streamSound3D(DecoderPtr decoder, Stream* sound, bool getLoudnessData)
bool OpenALOutput::streamSound3D(DecoderPtr decoder, Stream* sound, bool getLoudnessData)
{
if (mFreeSources.empty())
{
@ -1380,7 +1379,7 @@ namespace MWSound
return true;
}
void OpenAL_Output::finishStream(Stream* sound)
void OpenALOutput::finishStream(Stream* sound)
{
if (!sound->mHandle)
return;
@ -1402,7 +1401,7 @@ namespace MWSound
delete stream;
}
double OpenAL_Output::getStreamDelay(Stream* sound)
double OpenALOutput::getStreamDelay(Stream* sound)
{
if (!sound->mHandle)
return 0.0;
@ -1410,7 +1409,7 @@ namespace MWSound
return stream->getStreamDelay();
}
double OpenAL_Output::getStreamOffset(Stream* sound)
double OpenALOutput::getStreamOffset(Stream* sound)
{
if (!sound->mHandle)
return 0.0;
@ -1419,7 +1418,7 @@ namespace MWSound
return stream->getStreamOffset();
}
float OpenAL_Output::getStreamLoudness(Stream* sound)
float OpenALOutput::getStreamLoudness(Stream* sound)
{
if (!sound->mHandle)
return 0.0;
@ -1428,7 +1427,7 @@ namespace MWSound
return stream->getCurrentLoudness();
}
bool OpenAL_Output::isStreamPlaying(Stream* sound)
bool OpenALOutput::isStreamPlaying(Stream* sound)
{
if (!sound->mHandle)
return false;
@ -1437,7 +1436,7 @@ namespace MWSound
return stream->isPlaying();
}
void OpenAL_Output::updateStream(Stream* sound)
void OpenALOutput::updateStream(Stream* sound)
{
if (!sound->mHandle)
return;
@ -1449,17 +1448,17 @@ namespace MWSound
getALError();
}
void OpenAL_Output::startUpdate()
void OpenALOutput::startUpdate()
{
alcSuspendContext(alcGetCurrentContext());
}
void OpenAL_Output::finishUpdate()
void OpenALOutput::finishUpdate()
{
alcProcessContext(alcGetCurrentContext());
}
void OpenAL_Output::updateListener(
void OpenALOutput::updateListener(
const osg::Vec3f& pos, const osg::Vec3f& atdir, const osg::Vec3f& updir, Environment env)
{
if (mContext)
@ -1501,7 +1500,7 @@ namespace MWSound
mListenerEnv = env;
}
void OpenAL_Output::pauseSounds(int types)
void OpenALOutput::pauseSounds(int types)
{
std::vector<ALuint> sources;
for (Sound* sound : mActiveSounds)
@ -1524,7 +1523,7 @@ namespace MWSound
}
}
void OpenAL_Output::pauseActiveDevice()
void OpenALOutput::pauseActiveDevice()
{
if (mDevice == nullptr)
return;
@ -1540,7 +1539,7 @@ namespace MWSound
alListenerf(AL_GAIN, 0.0f);
}
void OpenAL_Output::resumeActiveDevice()
void OpenALOutput::resumeActiveDevice()
{
if (mDevice == nullptr)
return;
@ -1556,7 +1555,7 @@ namespace MWSound
alListenerf(AL_GAIN, 1.0f);
}
void OpenAL_Output::resumeSounds(int types)
void OpenALOutput::resumeSounds(int types)
{
std::vector<ALuint> sources;
for (Sound* sound : mActiveSounds)
@ -1579,8 +1578,8 @@ namespace MWSound
}
}
OpenAL_Output::OpenAL_Output(SoundManager& mgr)
: Sound_Output(mgr)
OpenALOutput::OpenALOutput(SoundManager& mgr)
: SoundOutput(mgr)
, mDevice(nullptr)
, mContext(nullptr)
, mListenerPos(0.0f, 0.0f, 0.0f)
@ -1593,12 +1592,12 @@ namespace MWSound
{
}
OpenAL_Output::~OpenAL_Output()
OpenALOutput::~OpenALOutput()
{
OpenAL_Output::deinit();
OpenALOutput::deinit();
}
float OpenAL_Output::getTimeScaledPitch(SoundBase* sound)
float OpenALOutput::getTimeScaledPitch(SoundBase* sound)
{
const bool shouldScale = !(sound->mParams.mFlags & PlayMode::NoScaling);
return shouldScale ? sound->getPitch() * mManager.getSimulationTimeScale() : sound->getPitch();

View file

@ -1,5 +1,5 @@
#ifndef GAME_SOUND_OPENAL_OUTPUT_H
#define GAME_SOUND_OPENAL_OUTPUT_H
#ifndef GAME_SOUND_OPENALOUTPUT_H
#define GAME_SOUND_OPENALOUTPUT_H
#include <deque>
#include <map>
@ -13,7 +13,7 @@
#include "alc.h"
#include "alext.h"
#include "sound_output.hpp"
#include "soundoutput.hpp"
namespace MWSound
{
@ -22,7 +22,7 @@ namespace MWSound
class Sound;
class Stream;
class OpenAL_Output : public Sound_Output
class OpenALOutput : public SoundOutput
{
ALCdevice* mDevice;
ALCcontext* mContext;
@ -72,8 +72,8 @@ namespace MWSound
float getTimeScaledPitch(SoundBase* sound);
OpenAL_Output& operator=(const OpenAL_Output& rhs);
OpenAL_Output(const OpenAL_Output& rhs);
OpenALOutput& operator=(const OpenALOutput& rhs);
OpenALOutput(const OpenALOutput& rhs);
static void eventCallback(
ALenum eventType, ALuint object, ALuint param, ALsizei length, const ALchar* message, void* userParam);
@ -117,8 +117,8 @@ namespace MWSound
void pauseActiveDevice() override;
void resumeActiveDevice() override;
OpenAL_Output(SoundManager& mgr);
virtual ~OpenAL_Output();
OpenALOutput(SoundManager& mgr);
virtual ~OpenALOutput();
};
}

View file

@ -3,7 +3,7 @@
#include <algorithm>
#include "sound_output.hpp"
#include "soundoutput.hpp"
namespace MWSound
{
@ -53,7 +53,7 @@ namespace MWSound
protected:
Sound_Instance mHandle = nullptr;
friend class OpenAL_Output;
friend class OpenALOutput;
public:
void setPosition(const osg::Vec3f& pos) { mParams.mPos = pos; }

View file

@ -1,4 +1,4 @@
#include "sound_buffer.hpp"
#include "soundbuffer.hpp"
#include "../mwbase/environment.hpp"
#include "../mwworld/esmstore.hpp"
@ -35,7 +35,7 @@ namespace MWSound
}
}
SoundBufferPool::SoundBufferPool(Sound_Output& output)
SoundBufferPool::SoundBufferPool(SoundOutput& output)
: mOutput(&output)
, mBufferCacheMax(Settings::sound().mBufferCacheMax * 1024 * 1024)
, mBufferCacheMin(
@ -48,31 +48,31 @@ namespace MWSound
clear();
}
Sound_Buffer* SoundBufferPool::lookup(const ESM::RefId& soundId) const
SoundBuffer* SoundBufferPool::lookup(const ESM::RefId& soundId) const
{
const auto it = mBufferNameMap.find(soundId);
if (it != mBufferNameMap.end())
{
Sound_Buffer* sfx = it->second;
SoundBuffer* sfx = it->second;
if (sfx->getHandle() != nullptr)
return sfx;
}
return nullptr;
}
Sound_Buffer* SoundBufferPool::lookup(std::string_view fileName) const
SoundBuffer* SoundBufferPool::lookup(std::string_view fileName) const
{
const auto it = mBufferFileNameMap.find(std::string(fileName));
if (it != mBufferFileNameMap.end())
{
Sound_Buffer* sfx = it->second;
SoundBuffer* sfx = it->second;
if (sfx->getHandle() != nullptr)
return sfx;
}
return nullptr;
}
Sound_Buffer* SoundBufferPool::loadSfx(Sound_Buffer* sfx)
SoundBuffer* SoundBufferPool::loadSfx(SoundBuffer* sfx)
{
if (sfx->getHandle() != nullptr)
return sfx;
@ -95,7 +95,7 @@ namespace MWSound
return sfx;
}
Sound_Buffer* SoundBufferPool::load(const ESM::RefId& soundId)
SoundBuffer* SoundBufferPool::load(const ESM::RefId& soundId)
{
if (mBufferNameMap.empty())
{
@ -103,7 +103,7 @@ namespace MWSound
insertSound(sound.mId, sound);
}
Sound_Buffer* sfx;
SoundBuffer* sfx;
const auto it = mBufferNameMap.find(soundId);
if (it != mBufferNameMap.end())
sfx = it->second;
@ -118,9 +118,9 @@ namespace MWSound
return loadSfx(sfx);
}
Sound_Buffer* SoundBufferPool::load(std::string_view fileName)
SoundBuffer* SoundBufferPool::load(std::string_view fileName)
{
Sound_Buffer* sfx;
SoundBuffer* sfx;
const auto it = mBufferFileNameMap.find(std::string(fileName));
if (it != mBufferFileNameMap.end())
sfx = it->second;
@ -146,7 +146,7 @@ namespace MWSound
mUnusedBuffers.clear();
}
Sound_Buffer* SoundBufferPool::insertSound(std::string_view fileName)
SoundBuffer* SoundBufferPool::insertSound(std::string_view fileName)
{
static const AudioParams audioParams
= makeAudioParams(MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>());
@ -158,13 +158,13 @@ namespace MWSound
min = std::max(min, 1.0f);
max = std::max(min, max);
Sound_Buffer& sfx = mSoundBuffers.emplace_back(fileName, volume, min, max);
SoundBuffer& sfx = mSoundBuffers.emplace_back(fileName, volume, min, max);
mBufferFileNameMap.emplace(fileName, &sfx);
return &sfx;
}
Sound_Buffer* SoundBufferPool::insertSound(const ESM::RefId& soundId, const ESM::Sound& sound)
SoundBuffer* SoundBufferPool::insertSound(const ESM::RefId& soundId, const ESM::Sound& sound)
{
static const AudioParams audioParams
= makeAudioParams(MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>());
@ -183,7 +183,7 @@ namespace MWSound
min = std::max(min, 1.0f);
max = std::max(min, max);
Sound_Buffer& sfx = mSoundBuffers.emplace_back(
SoundBuffer& sfx = mSoundBuffers.emplace_back(
Misc::ResourceHelpers::correctSoundPath(VFS::Path::Normalized(sound.mSound)), volume, min, max);
mBufferNameMap.emplace(soundId, &sfx);
@ -194,7 +194,7 @@ namespace MWSound
{
while (!mUnusedBuffers.empty() && mBufferCacheSize > mBufferCacheMin)
{
Sound_Buffer* const unused = mUnusedBuffers.back();
SoundBuffer* const unused = mUnusedBuffers.back();
mBufferCacheSize -= mOutput->unloadSound(unused->getHandle());
unused->mHandle = nullptr;

View file

@ -1,14 +1,15 @@
#ifndef GAME_SOUND_SOUND_BUFFER_H
#define GAME_SOUND_SOUND_BUFFER_H
#ifndef GAME_SOUND_SOUNDBUFFER_H
#define GAME_SOUND_SOUNDBUFFER_H
#include <algorithm>
#include <deque>
#include <string>
#include <unordered_map>
#include "sound_output.hpp"
#include <components/esm/refid.hpp>
#include "soundoutput.hpp"
namespace ESM
{
struct Sound;
@ -23,11 +24,11 @@ namespace MWSound
{
class SoundBufferPool;
class Sound_Buffer
class SoundBuffer
{
public:
template <class T>
Sound_Buffer(T&& resname, float volume, float mindist, float maxdist)
SoundBuffer(T&& resname, float volume, float mindist, float maxdist)
: mResourceName(std::forward<T>(resname))
, mVolume(volume)
, mMinDist(mindist)
@ -59,7 +60,7 @@ namespace MWSound
class SoundBufferPool
{
public:
SoundBufferPool(Sound_Output& output);
SoundBufferPool(SoundOutput& output);
SoundBufferPool(const SoundBufferPool&) = delete;
@ -67,20 +68,20 @@ namespace MWSound
/// Lookup a soundId for its sound data (resource name, local volume,
/// minRange, and maxRange)
Sound_Buffer* lookup(const ESM::RefId& soundId) const;
SoundBuffer* lookup(const ESM::RefId& soundId) const;
/// Lookup a sound by file name for its sound data (resource name, local volume,
/// minRange, and maxRange)
Sound_Buffer* lookup(std::string_view fileName) const;
SoundBuffer* lookup(std::string_view fileName) const;
/// Lookup a soundId for its sound data (resource name, local volume,
/// minRange, and maxRange), and ensure it's ready for use.
Sound_Buffer* load(const ESM::RefId& soundId);
SoundBuffer* load(const ESM::RefId& soundId);
// Lookup for a sound by file name, and ensure it's ready for use.
Sound_Buffer* load(std::string_view fileName);
SoundBuffer* load(std::string_view fileName);
void use(Sound_Buffer& sfx)
void use(SoundBuffer& sfx)
{
if (sfx.mUses++ == 0)
{
@ -90,7 +91,7 @@ namespace MWSound
}
}
void release(Sound_Buffer& sfx)
void release(SoundBuffer& sfx)
{
if (--sfx.mUses == 0)
mUnusedBuffers.push_front(&sfx);
@ -99,23 +100,23 @@ namespace MWSound
void clear();
private:
Sound_Buffer* loadSfx(Sound_Buffer* sfx);
SoundBuffer* loadSfx(SoundBuffer* sfx);
Sound_Output* mOutput;
std::deque<Sound_Buffer> mSoundBuffers;
std::unordered_map<ESM::RefId, Sound_Buffer*> mBufferNameMap;
std::unordered_map<std::string, Sound_Buffer*> mBufferFileNameMap;
SoundOutput* mOutput;
std::deque<SoundBuffer> mSoundBuffers;
std::unordered_map<ESM::RefId, SoundBuffer*> mBufferNameMap;
std::unordered_map<std::string, SoundBuffer*> mBufferFileNameMap;
std::size_t mBufferCacheMax;
std::size_t mBufferCacheMin;
std::size_t mBufferCacheSize = 0;
// NOTE: unused buffers are stored in front-newest order.
std::deque<Sound_Buffer*> mUnusedBuffers;
std::deque<SoundBuffer*> mUnusedBuffers;
inline Sound_Buffer* insertSound(const ESM::RefId& soundId, const ESM::Sound& sound);
inline Sound_Buffer* insertSound(std::string_view fileName);
inline SoundBuffer* insertSound(const ESM::RefId& soundId, const ESM::Sound& sound);
inline SoundBuffer* insertSound(std::string_view fileName);
inline void unloadUnused();
};
}
#endif /* GAME_SOUND_SOUND_BUFFER_H */
#endif /* GAME_SOUND_SOUNDBUFFER_H */

View file

@ -1,5 +1,5 @@
#ifndef GAME_SOUND_SOUND_DECODER_H
#define GAME_SOUND_SOUND_DECODER_H
#ifndef GAME_SOUND_SOUNDDECODER_H
#define GAME_SOUND_SOUNDDECODER_H
#include <components/vfs/pathutil.hpp>
@ -34,7 +34,7 @@ namespace MWSound
size_t framesToBytes(size_t frames, ChannelConfig config, SampleType type);
size_t bytesToFrames(size_t bytes, ChannelConfig config, SampleType type);
struct Sound_Decoder
struct SoundDecoder
{
const VFS::Manager* mResourceMgr;
@ -48,15 +48,15 @@ namespace MWSound
virtual void readAll(std::vector<char>& output);
virtual size_t getSampleOffset() = 0;
Sound_Decoder(const VFS::Manager* resourceMgr)
SoundDecoder(const VFS::Manager* resourceMgr)
: mResourceMgr(resourceMgr)
{
}
virtual ~Sound_Decoder() {}
virtual ~SoundDecoder() {}
private:
Sound_Decoder(const Sound_Decoder& rhs);
Sound_Decoder& operator=(const Sound_Decoder& rhs);
SoundDecoder(const SoundDecoder& rhs);
SoundDecoder& operator=(const SoundDecoder& rhs);
};
}

View file

@ -26,12 +26,12 @@
#include "../mwmechanics/actorutil.hpp"
#include "constants.hpp"
#include "ffmpeg_decoder.hpp"
#include "openal_output.hpp"
#include "ffmpegdecoder.hpp"
#include "openaloutput.hpp"
#include "sound.hpp"
#include "sound_buffer.hpp"
#include "sound_decoder.hpp"
#include "sound_output.hpp"
#include "soundbuffer.hpp"
#include "sounddecoder.hpp"
#include "soundoutput.hpp"
namespace MWSound
{
@ -57,7 +57,7 @@ namespace MWSound
return settings;
}
float initialFadeVolume(float squaredDist, Sound_Buffer* sfx, Type type, PlayMode mode)
float initialFadeVolume(float squaredDist, SoundBuffer* sfx, Type type, PlayMode mode)
{
// If a sound is farther away than its maximum distance, start playing it with a zero fade volume.
// It can still become audible once the player moves closer.
@ -111,7 +111,7 @@ namespace MWSound
SoundManager::SoundManager(const VFS::Manager* vfs, bool useSound)
: mVFS(vfs)
, mOutput(std::make_unique<OpenAL_Output>(*this))
, mOutput(std::make_unique<OpenALOutput>(*this))
, mWaterSoundUpdater(makeWaterSoundUpdaterSettings())
, mSoundBuffers(*mOutput)
, mMusicType(MWSound::MusicType::Normal)
@ -169,7 +169,7 @@ namespace MWSound
// Return a new decoder instance, used as needed by the output implementations
DecoderPtr SoundManager::getDecoder()
{
return std::make_shared<FFmpeg_Decoder>(mVFS);
return std::make_shared<FFmpegDecoder>(mVFS);
}
DecoderPtr SoundManager::loadVoice(VFS::Path::NormalizedView voicefile)
@ -459,7 +459,7 @@ namespace MWSound
return false;
}
Sound* SoundManager::playSound(Sound_Buffer* sfx, float volume, float pitch, Type type, PlayMode mode, float offset)
Sound* SoundManager::playSound(SoundBuffer* sfx, float volume, float pitch, Type type, PlayMode mode, float offset)
{
if (!mOutput->isInitialized())
return nullptr;
@ -495,7 +495,7 @@ namespace MWSound
if (!mVFS->exists(normalizedName))
return nullptr;
Sound_Buffer* sfx = mSoundBuffers.load(normalizedName);
SoundBuffer* sfx = mSoundBuffers.load(normalizedName);
if (!sfx)
return nullptr;
@ -508,14 +508,14 @@ namespace MWSound
if (!mOutput->isInitialized())
return nullptr;
Sound_Buffer* sfx = mSoundBuffers.load(soundId);
SoundBuffer* sfx = mSoundBuffers.load(soundId);
if (!sfx)
return nullptr;
return playSound(sfx, volume, pitch, type, mode, offset);
}
Sound* SoundManager::playSound3D(const MWWorld::ConstPtr& ptr, Sound_Buffer* sfx, float volume, float pitch,
Sound* SoundManager::playSound3D(const MWWorld::ConstPtr& ptr, SoundBuffer* sfx, float volume, float pitch,
Type type, PlayMode mode, float offset)
{
if (!mOutput->isInitialized())
@ -576,7 +576,7 @@ namespace MWSound
return nullptr;
// Look up the sound in the ESM data
Sound_Buffer* sfx = mSoundBuffers.load(soundId);
SoundBuffer* sfx = mSoundBuffers.load(soundId);
if (!sfx)
return nullptr;
@ -594,7 +594,7 @@ namespace MWSound
if (!mVFS->exists(normalizedName))
return nullptr;
Sound_Buffer* sfx = mSoundBuffers.load(normalizedName);
SoundBuffer* sfx = mSoundBuffers.load(normalizedName);
if (!sfx)
return nullptr;
@ -608,7 +608,7 @@ namespace MWSound
return nullptr;
// Look up the sound in the ESM data
Sound_Buffer* sfx = mSoundBuffers.load(soundId);
SoundBuffer* sfx = mSoundBuffers.load(soundId);
if (!sfx)
return nullptr;
@ -642,7 +642,7 @@ namespace MWSound
mOutput->finishSound(sound);
}
void SoundManager::stopSound(Sound_Buffer* sfx, const MWWorld::ConstPtr& ptr)
void SoundManager::stopSound(SoundBuffer* sfx, const MWWorld::ConstPtr& ptr)
{
SoundMap::iterator snditer = mActiveSounds.find(ptr.mRef);
if (snditer != mActiveSounds.end())
@ -660,7 +660,7 @@ namespace MWSound
if (!mOutput->isInitialized())
return;
Sound_Buffer* sfx = mSoundBuffers.lookup(soundId);
SoundBuffer* sfx = mSoundBuffers.lookup(soundId);
if (!sfx)
return;
@ -673,7 +673,7 @@ namespace MWSound
return;
std::string normalizedName = VFS::Path::normalizeFilename(fileName);
Sound_Buffer* sfx = mSoundBuffers.lookup(normalizedName);
SoundBuffer* sfx = mSoundBuffers.lookup(normalizedName);
if (!sfx)
return;
@ -725,7 +725,7 @@ namespace MWSound
SoundMap::iterator snditer = mActiveSounds.find(ptr.mRef);
if (snditer != mActiveSounds.end())
{
Sound_Buffer* sfx = mSoundBuffers.lookup(soundId);
SoundBuffer* sfx = mSoundBuffers.lookup(soundId);
if (sfx == nullptr)
return;
for (SoundBufferRefPair& sndbuf : snditer->second.mList)
@ -743,7 +743,7 @@ namespace MWSound
SoundMap::const_iterator snditer = mActiveSounds.find(ptr.mRef);
if (snditer != mActiveSounds.end())
{
Sound_Buffer* sfx = mSoundBuffers.lookup(normalizedName);
SoundBuffer* sfx = mSoundBuffers.lookup(normalizedName);
if (!sfx)
return false;
@ -761,7 +761,7 @@ namespace MWSound
SoundMap::const_iterator snditer = mActiveSounds.find(ptr.mRef);
if (snditer != mActiveSounds.end())
{
Sound_Buffer* sfx = mSoundBuffers.lookup(soundId);
SoundBuffer* sfx = mSoundBuffers.lookup(soundId);
if (!sfx)
return false;
@ -846,7 +846,7 @@ namespace MWSound
const auto update = mWaterSoundUpdater.update(player, *world);
WaterSoundAction action;
Sound_Buffer* sfx;
SoundBuffer* sfx;
std::tie(action, sfx) = getWaterSoundAction(update, curcell);
switch (action)
@ -870,7 +870,7 @@ namespace MWSound
mLastCell = curcell;
}
std::pair<SoundManager::WaterSoundAction, Sound_Buffer*> SoundManager::getWaterSoundAction(
std::pair<SoundManager::WaterSoundAction, SoundBuffer*> SoundManager::getWaterSoundAction(
const WaterSoundUpdate& update, const MWWorld::Cell* cell) const
{
if (mNearWaterSound)
@ -880,7 +880,7 @@ namespace MWSound
bool soundIdChanged = false;
Sound_Buffer* sfx = mSoundBuffers.lookup(update.mId);
SoundBuffer* sfx = mSoundBuffers.lookup(update.mId);
if (mLastCell != cell)
{
const auto snditer = mActiveSounds.find(nullptr);
@ -1168,7 +1168,7 @@ namespace MWSound
// Default readAll implementation, for decoders that can't do anything
// better
void Sound_Decoder::readAll(std::vector<char>& output)
void SoundDecoder::readAll(std::vector<char>& output)
{
size_t total = output.size();
size_t got;

View file

@ -15,7 +15,7 @@
#include "../mwbase/soundmanager.hpp"
#include "regionsoundselector.hpp"
#include "sound_buffer.hpp"
#include "soundbuffer.hpp"
#include "type.hpp"
#include "watersoundupdater.hpp"
@ -37,8 +37,8 @@ namespace MWWorld
namespace MWSound
{
class Sound_Output;
struct Sound_Decoder;
class SoundOutput;
struct SoundDecoder;
class SoundBase;
class Sound;
class Stream;
@ -50,7 +50,7 @@ namespace MWSound
{
const VFS::Manager* mVFS;
std::unique_ptr<Sound_Output> mOutput;
std::unique_ptr<SoundOutput> mOutput;
WaterSoundUpdater mWaterSoundUpdater;
@ -60,7 +60,7 @@ namespace MWSound
Misc::ObjectPool<Stream> mStreams;
typedef std::pair<SoundPtr, Sound_Buffer*> SoundBufferRefPair;
typedef std::pair<SoundPtr, SoundBuffer*> SoundBufferRefPair;
typedef std::vector<SoundBufferRefPair> SoundBufferRefPairList;
struct ActiveSound
@ -109,7 +109,7 @@ namespace MWSound
Sound* mCurrentRegionSound;
Sound_Buffer* insertSound(const std::string& soundId, const ESM::Sound* sound);
SoundBuffer* insertSound(const std::string& soundId, const ESM::Sound* sound);
// returns a decoder to start streaming, or nullptr if the sound was not found
DecoderPtr loadVoice(VFS::Path::NormalizedView voicefile);
@ -126,9 +126,9 @@ namespace MWSound
bool remove3DSoundAtDistance(PlayMode mode, const MWWorld::ConstPtr& ptr) const;
Sound* playSound(Sound_Buffer* sfx, float volume, float pitch, Type type = Type::Sfx,
Sound* playSound(SoundBuffer* sfx, float volume, float pitch, Type type = Type::Sfx,
PlayMode mode = PlayMode::Normal, float offset = 0);
Sound* playSound3D(const MWWorld::ConstPtr& ptr, Sound_Buffer* sfx, float volume, float pitch, Type type,
Sound* playSound3D(const MWWorld::ConstPtr& ptr, SoundBuffer* sfx, float volume, float pitch, Type type,
PlayMode mode, float offset);
void updateSounds(float duration);
@ -144,7 +144,7 @@ namespace MWSound
PlaySound,
};
std::pair<WaterSoundAction, Sound_Buffer*> getWaterSoundAction(
std::pair<WaterSoundAction, SoundBuffer*> getWaterSoundAction(
const WaterSoundUpdate& update, const MWWorld::Cell* cell) const;
SoundManager(const SoundManager& rhs);
@ -152,9 +152,9 @@ namespace MWSound
protected:
DecoderPtr getDecoder();
friend class OpenAL_Output;
friend class OpenALOutput;
void stopSound(Sound_Buffer* sfx, const MWWorld::ConstPtr& ptr);
void stopSound(SoundBuffer* sfx, const MWWorld::ConstPtr& ptr);
///< Stop the given object from playing given sound buffer.
public:

View file

@ -1,5 +1,5 @@
#ifndef GAME_SOUND_SOUND_OUTPUT_H
#define GAME_SOUND_SOUND_OUTPUT_H
#ifndef GAME_SOUND_SOUNDOUTPUT_H
#define GAME_SOUND_SOUNDOUTPUT_H
#include <memory>
#include <string>
@ -13,7 +13,7 @@
namespace MWSound
{
class SoundManager;
struct Sound_Decoder;
struct SoundDecoder;
class Sound;
class Stream;
@ -30,7 +30,7 @@ namespace MWSound
using HrtfMode = Settings::HrtfMode;
class Sound_Output
class SoundOutput
{
SoundManager& mManager;
@ -71,24 +71,24 @@ namespace MWSound
virtual void pauseActiveDevice() = 0;
virtual void resumeActiveDevice() = 0;
Sound_Output& operator=(const Sound_Output& rhs);
Sound_Output(const Sound_Output& rhs);
SoundOutput& operator=(const SoundOutput& rhs);
SoundOutput(const SoundOutput& rhs);
protected:
bool mInitialized;
Sound_Output(SoundManager& mgr)
SoundOutput(SoundManager& mgr)
: mManager(mgr)
, mInitialized(false)
{
}
public:
virtual ~Sound_Output() {}
virtual ~SoundOutput() {}
bool isInitialized() const { return mInitialized; }
friend class OpenAL_Output;
friend class OpenALOutput;
friend class SoundManager;
friend class SoundBufferPool;
};