Put the internal sound definitions into a new `sound` namespace

This commit is contained in:
Desour 2023-09-28 18:59:06 +02:00 committed by DS
parent bbc64a2eb5
commit c90c545d33
18 changed files with 70 additions and 4 deletions

View File

@ -24,6 +24,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "al_helpers.h"
namespace sound {
/*
* RAIIALSoundBuffer
*/
@ -51,3 +53,5 @@ RAIIALSoundBuffer RAIIALSoundBuffer::generate() noexcept
alGenBuffers(1, &buf);
return RAIIALSoundBuffer(buf);
}
} // namespace sound

View File

@ -45,6 +45,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <utility>
namespace sound {
inline const char *getAlErrorString(ALenum err) noexcept
{
switch (err) {
@ -116,3 +118,5 @@ private:
// > [...] the NULL buffer (i.e., 0) which can always be queued.
ALuint m_buffer = 0;
};
} // namespace sound

View File

@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <cstring> // memcpy
namespace sound {
/*
* OggVorbisBufferSource struct
*/
@ -177,3 +179,5 @@ RAIIALSoundBuffer RAIIOggFile::loadBuffer(const OggFileDecodeInfo &decode_info,
return snd_buffer_id;
}
} // namespace sound

View File

@ -29,6 +29,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <optional>
#include <string>
namespace sound {
/**
* For vorbisfile to read from our buffer instead of from a file.
*/
@ -92,3 +94,5 @@ struct RAIIOggFile {
RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start,
ALuint pcm_end);
};
} // namespace sound

View File

@ -28,6 +28,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <cassert>
#include <cmath>
namespace sound {
PlayingSound::PlayingSound(ALuint source_id, std::shared_ptr<ISoundDataOpen> data,
bool loop, f32 volume, f32 pitch, f32 start_time,
const std::optional<std::pair<v3f, v3f>> &pos_vel_opt)
@ -239,3 +241,5 @@ f32 PlayingSound::getGain() noexcept
gain *= 1.0f/3.0f;
return gain;
}
} // namespace sound

View File

@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "sound_data.h"
namespace sound {
/**
* A sound that is currently played.
* Can be streaming.
@ -105,3 +107,5 @@ public:
play();
}
};
} // namespace sound

View File

@ -21,6 +21,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "filesys.h"
namespace sound {
ProxySoundManager::MsgResult ProxySoundManager::handleMsg(SoundManagerMsgToProxy &&msg)
{
using namespace sound_manager_messages_to_proxy;
@ -161,3 +163,5 @@ void ProxySoundManager::updateSoundPosVel(sound_handle_t sound, const v3f &pos_,
{
send(sound_manager_messages_to_mgr::UpdateSoundPosVel{sound, pos_, vel_});
}
} // namespace sound

View File

@ -21,6 +21,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "sound_manager.h"
namespace sound {
/*
* The public ISoundManager interface
*/
@ -69,3 +71,5 @@ public:
void fadeSound(sound_handle_t soundid, f32 step, f32 target_gain) override;
void updateSoundPosVel(sound_handle_t sound, const v3f &pos_, const v3f &vel_) override;
};
} // namespace sound

View File

@ -100,6 +100,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
*
*/
namespace sound {
// constants
// in seconds
@ -117,3 +119,5 @@ static_assert(MIN_STREAM_BUFFER_LENGTH > STREAM_BIGSTEP_TIME * 2.0f,
"See [Streaming of sounds].");
static_assert(SOUND_DURATION_MAX_SINGLE >= MIN_STREAM_BUFFER_LENGTH * 2.0f,
"There's no benefit in streaming if we can't queue more than 2 buffers.");
} // namespace sound

View File

@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "sound_constants.h"
namespace sound {
/*
* ISoundDataOpen struct
*/
@ -229,3 +231,5 @@ std::tuple<ALuint, ALuint, ALuint> SoundDataOpenStream::loadBufferAt(ALuint offs
return {it->m_buffers[new_buf_i].m_buffer.get(), new_buf_end, offset - new_buf_start};
}
} // namespace sound

View File

@ -28,6 +28,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <memory>
#include <tuple>
namespace sound {
/**
* Stores sound pcm data buffers.
*/
@ -171,3 +173,5 @@ private:
std::tuple<ALuint, ALuint, ALuint> loadBufferAt(ALuint offset,
std::vector<ContiguousBuffers>::iterator after_it);
};
} // namespace sound

View File

@ -29,6 +29,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "porting.h"
namespace sound {
void OpenALSoundManager::stepStreams(f32 dtime)
{
// spread work across steps
@ -521,3 +523,5 @@ void *OpenALSoundManager::run()
return nullptr;
}
} // namespace sound

View File

@ -31,13 +31,16 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "threading/thread.h"
#include "util/container.h" // MutexedQueue
namespace sound {
class SoundManagerSingleton;
/*
* The SoundManager thread
*
* It's not an ISoundManager. It doesn't allocate ids, and doesn't accept id 0.
* All sound loading and interaction with OpenAL happens in this thread.
* All sound loading and interaction with OpenAL happens in this thread, and in
* SoundManagerSingleton.
* Access from other threads happens via ProxySoundManager.
*
* See sound_constants.h for more details.
@ -169,3 +172,5 @@ private:
send(sound_manager_messages_to_proxy::ReportRemovedSound{id});
}
};
} // namespace sound

View File

@ -23,6 +23,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "../../sound.h"
#include <variant>
namespace sound {
namespace sound_manager_messages_to_mgr {
struct PauseAll {};
struct ResumeAll {};
@ -78,3 +80,5 @@ using SoundManagerMsgToProxy = std::variant<
sound_manager_messages_to_proxy::Stopped
>;
} // namespace sound

View File

@ -40,5 +40,5 @@ std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton()
std::unique_ptr<ISoundManager> createOpenALSoundManager(SoundManagerSingleton *smg,
std::unique_ptr<SoundFallbackPathProvider> fallback_path_provider)
{
return std::make_unique<ProxySoundManager>(smg, std::move(fallback_path_provider));
return std::make_unique<sound::ProxySoundManager>(smg, std::move(fallback_path_provider));
};

View File

@ -20,10 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "client/sound.h"
#include <memory>
class SoundManagerSingleton;
namespace sound { class SoundManagerSingleton; }
using sound::SoundManagerSingleton;
extern std::shared_ptr<SoundManagerSingleton> g_sound_manager_singleton;
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton();

View File

@ -24,6 +24,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "sound_singleton.h"
namespace sound {
bool SoundManagerSingleton::init()
{
if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr)))) {
@ -67,3 +69,5 @@ SoundManagerSingleton::~SoundManagerSingleton()
{
infostream << "Audio: Global Deinitialized." << std::endl;
}
} // namespace sound

View File

@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include "al_helpers.h"
namespace sound {
/**
* Class for the openal device and context
*/
@ -58,3 +60,5 @@ public:
~SoundManagerSingleton();
};
} // namespace sound