Skip to content

Commit

Permalink
Put the internal sound definitions into a new sound namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Sep 30, 2023
1 parent bbc64a2 commit c90c545
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/client/sound/al_helpers.cpp
Expand Up @@ -24,6 +24,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,

#include "al_helpers.h"

namespace sound {

/*
* RAIIALSoundBuffer
*/
Expand Down Expand Up @@ -51,3 +53,5 @@ RAIIALSoundBuffer RAIIALSoundBuffer::generate() noexcept
alGenBuffers(1, &buf);
return RAIIALSoundBuffer(buf);
}

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/al_helpers.h
Expand Up @@ -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) {
Expand Down Expand Up @@ -116,3 +118,5 @@ struct RAIIALSoundBuffer final
// > [...] the NULL buffer (i.e., 0) which can always be queued.
ALuint m_buffer = 0;
};

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/ogg_file.cpp
Expand Up @@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,

#include <cstring> // memcpy

namespace sound {

/*
* OggVorbisBufferSource struct
*/
Expand Down Expand Up @@ -177,3 +179,5 @@ RAIIALSoundBuffer RAIIOggFile::loadBuffer(const OggFileDecodeInfo &decode_info,

return snd_buffer_id;
}

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/ogg_file.h
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -92,3 +94,5 @@ struct RAIIOggFile {
RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start,
ALuint pcm_end);
};

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/playing_sound.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -239,3 +241,5 @@ f32 PlayingSound::getGain() noexcept
gain *= 1.0f/3.0f;
return gain;
}

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/playing_sound.h
Expand Up @@ -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.
Expand Down Expand Up @@ -105,3 +107,5 @@ class PlayingSound final
play();
}
};

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/proxy_sound_manager.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/client/sound/proxy_sound_manager.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -69,3 +71,5 @@ class ProxySoundManager final : public ISoundManager
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
4 changes: 4 additions & 0 deletions src/client/sound/sound_constants.h
Expand Up @@ -100,6 +100,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
*
*/

namespace sound {

// constants

// in seconds
Expand All @@ -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
4 changes: 4 additions & 0 deletions src/client/sound/sound_data.cpp
Expand Up @@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,

#include "sound_constants.h"

namespace sound {

/*
* ISoundDataOpen struct
*/
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/client/sound/sound_data.h
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -171,3 +173,5 @@ struct SoundDataOpenStream final : ISoundDataOpen
std::tuple<ALuint, ALuint, ALuint> loadBufferAt(ALuint offset,
std::vector<ContiguousBuffers>::iterator after_it);
};

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/sound_manager.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -521,3 +523,5 @@ void *OpenALSoundManager::run()

return nullptr;
}

} // namespace sound
7 changes: 6 additions & 1 deletion src/client/sound/sound_manager.h
Expand Up @@ -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.
Expand Down Expand Up @@ -169,3 +172,5 @@ class OpenALSoundManager final : public Thread
send(sound_manager_messages_to_proxy::ReportRemovedSound{id});
}
};

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/sound_manager_messages.h
Expand Up @@ -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 {};
Expand Down Expand Up @@ -78,3 +80,5 @@ using SoundManagerMsgToProxy = std::variant<

sound_manager_messages_to_proxy::Stopped
>;

} // namespace sound
2 changes: 1 addition & 1 deletion src/client/sound/sound_openal.cpp
Expand Up @@ -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));
};
5 changes: 3 additions & 2 deletions src/client/sound/sound_openal.h
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/client/sound/sound_singleton.cpp
Expand Up @@ -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)))) {
Expand Down Expand Up @@ -67,3 +69,5 @@ SoundManagerSingleton::~SoundManagerSingleton()
{
infostream << "Audio: Global Deinitialized." << std::endl;
}

} // namespace sound
4 changes: 4 additions & 0 deletions src/client/sound/sound_singleton.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -58,3 +60,5 @@ class SoundManagerSingleton

~SoundManagerSingleton();
};

} // namespace sound

0 comments on commit c90c545

Please sign in to comment.