mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 15:12:23 +01:00
Put the internal sound definitions into a new sound
namespace
This commit is contained in:
parent
bbc64a2eb5
commit
c90c545d33
@ -24,6 +24,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "al_helpers.h"
|
#include "al_helpers.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RAIIALSoundBuffer
|
* RAIIALSoundBuffer
|
||||||
*/
|
*/
|
||||||
@ -51,3 +53,5 @@ RAIIALSoundBuffer RAIIALSoundBuffer::generate() noexcept
|
|||||||
alGenBuffers(1, &buf);
|
alGenBuffers(1, &buf);
|
||||||
return RAIIALSoundBuffer(buf);
|
return RAIIALSoundBuffer(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -45,6 +45,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
inline const char *getAlErrorString(ALenum err) noexcept
|
inline const char *getAlErrorString(ALenum err) noexcept
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
@ -116,3 +118,5 @@ private:
|
|||||||
// > [...] the NULL buffer (i.e., 0) which can always be queued.
|
// > [...] the NULL buffer (i.e., 0) which can always be queued.
|
||||||
ALuint m_buffer = 0;
|
ALuint m_buffer = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include <cstring> // memcpy
|
#include <cstring> // memcpy
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* OggVorbisBufferSource struct
|
* OggVorbisBufferSource struct
|
||||||
*/
|
*/
|
||||||
@ -177,3 +179,5 @@ RAIIALSoundBuffer RAIIOggFile::loadBuffer(const OggFileDecodeInfo &decode_info,
|
|||||||
|
|
||||||
return snd_buffer_id;
|
return snd_buffer_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -29,6 +29,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For vorbisfile to read from our buffer instead of from a file.
|
* 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,
|
RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start,
|
||||||
ALuint pcm_end);
|
ALuint pcm_end);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -28,6 +28,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
PlayingSound::PlayingSound(ALuint source_id, std::shared_ptr<ISoundDataOpen> data,
|
PlayingSound::PlayingSound(ALuint source_id, std::shared_ptr<ISoundDataOpen> data,
|
||||||
bool loop, f32 volume, f32 pitch, f32 start_time,
|
bool loop, f32 volume, f32 pitch, f32 start_time,
|
||||||
const std::optional<std::pair<v3f, v3f>> &pos_vel_opt)
|
const std::optional<std::pair<v3f, v3f>> &pos_vel_opt)
|
||||||
@ -239,3 +241,5 @@ f32 PlayingSound::getGain() noexcept
|
|||||||
gain *= 1.0f/3.0f;
|
gain *= 1.0f/3.0f;
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "sound_data.h"
|
#include "sound_data.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A sound that is currently played.
|
* A sound that is currently played.
|
||||||
* Can be streaming.
|
* Can be streaming.
|
||||||
@ -105,3 +107,5 @@ public:
|
|||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -21,6 +21,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
ProxySoundManager::MsgResult ProxySoundManager::handleMsg(SoundManagerMsgToProxy &&msg)
|
ProxySoundManager::MsgResult ProxySoundManager::handleMsg(SoundManagerMsgToProxy &&msg)
|
||||||
{
|
{
|
||||||
using namespace sound_manager_messages_to_proxy;
|
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_});
|
send(sound_manager_messages_to_mgr::UpdateSoundPosVel{sound, pos_, vel_});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -21,6 +21,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "sound_manager.h"
|
#include "sound_manager.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The public ISoundManager interface
|
* The public ISoundManager interface
|
||||||
*/
|
*/
|
||||||
@ -69,3 +71,5 @@ public:
|
|||||||
void fadeSound(sound_handle_t soundid, f32 step, f32 target_gain) override;
|
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;
|
void updateSoundPosVel(sound_handle_t sound, const v3f &pos_, const v3f &vel_) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -100,6 +100,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
|
|
||||||
// in seconds
|
// in seconds
|
||||||
@ -117,3 +119,5 @@ static_assert(MIN_STREAM_BUFFER_LENGTH > STREAM_BIGSTEP_TIME * 2.0f,
|
|||||||
"See [Streaming of sounds].");
|
"See [Streaming of sounds].");
|
||||||
static_assert(SOUND_DURATION_MAX_SINGLE >= MIN_STREAM_BUFFER_LENGTH * 2.0f,
|
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.");
|
"There's no benefit in streaming if we can't queue more than 2 buffers.");
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "sound_constants.h"
|
#include "sound_constants.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ISoundDataOpen struct
|
* 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};
|
return {it->m_buffers[new_buf_i].m_buffer.get(), new_buf_end, offset - new_buf_start};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -28,6 +28,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores sound pcm data buffers.
|
* Stores sound pcm data buffers.
|
||||||
*/
|
*/
|
||||||
@ -171,3 +173,5 @@ private:
|
|||||||
std::tuple<ALuint, ALuint, ALuint> loadBufferAt(ALuint offset,
|
std::tuple<ALuint, ALuint, ALuint> loadBufferAt(ALuint offset,
|
||||||
std::vector<ContiguousBuffers>::iterator after_it);
|
std::vector<ContiguousBuffers>::iterator after_it);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -29,6 +29,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
#include "porting.h"
|
#include "porting.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
void OpenALSoundManager::stepStreams(f32 dtime)
|
void OpenALSoundManager::stepStreams(f32 dtime)
|
||||||
{
|
{
|
||||||
// spread work across steps
|
// spread work across steps
|
||||||
@ -521,3 +523,5 @@ void *OpenALSoundManager::run()
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -31,13 +31,16 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
#include "threading/thread.h"
|
#include "threading/thread.h"
|
||||||
#include "util/container.h" // MutexedQueue
|
#include "util/container.h" // MutexedQueue
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
class SoundManagerSingleton;
|
class SoundManagerSingleton;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The SoundManager thread
|
* The SoundManager thread
|
||||||
*
|
*
|
||||||
* It's not an ISoundManager. It doesn't allocate ids, and doesn't accept id 0.
|
* 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.
|
* Access from other threads happens via ProxySoundManager.
|
||||||
*
|
*
|
||||||
* See sound_constants.h for more details.
|
* See sound_constants.h for more details.
|
||||||
@ -169,3 +172,5 @@ private:
|
|||||||
send(sound_manager_messages_to_proxy::ReportRemovedSound{id});
|
send(sound_manager_messages_to_proxy::ReportRemovedSound{id});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -23,6 +23,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
#include "../../sound.h"
|
#include "../../sound.h"
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
namespace sound_manager_messages_to_mgr {
|
namespace sound_manager_messages_to_mgr {
|
||||||
struct PauseAll {};
|
struct PauseAll {};
|
||||||
struct ResumeAll {};
|
struct ResumeAll {};
|
||||||
@ -78,3 +80,5 @@ using SoundManagerMsgToProxy = std::variant<
|
|||||||
|
|
||||||
sound_manager_messages_to_proxy::Stopped
|
sound_manager_messages_to_proxy::Stopped
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -40,5 +40,5 @@ std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton()
|
|||||||
std::unique_ptr<ISoundManager> createOpenALSoundManager(SoundManagerSingleton *smg,
|
std::unique_ptr<ISoundManager> createOpenALSoundManager(SoundManagerSingleton *smg,
|
||||||
std::unique_ptr<SoundFallbackPathProvider> fallback_path_provider)
|
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));
|
||||||
};
|
};
|
||||||
|
@ -20,10 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "client/sound.h"
|
#include "client/sound.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class SoundManagerSingleton;
|
namespace sound { class SoundManagerSingleton; }
|
||||||
|
using sound::SoundManagerSingleton;
|
||||||
|
|
||||||
extern std::shared_ptr<SoundManagerSingleton> g_sound_manager_singleton;
|
extern std::shared_ptr<SoundManagerSingleton> g_sound_manager_singleton;
|
||||||
|
|
||||||
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton();
|
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton();
|
||||||
|
@ -24,6 +24,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "sound_singleton.h"
|
#include "sound_singleton.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
bool SoundManagerSingleton::init()
|
bool SoundManagerSingleton::init()
|
||||||
{
|
{
|
||||||
if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr)))) {
|
if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr)))) {
|
||||||
@ -67,3 +69,5 @@ SoundManagerSingleton::~SoundManagerSingleton()
|
|||||||
{
|
{
|
||||||
infostream << "Audio: Global Deinitialized." << std::endl;
|
infostream << "Audio: Global Deinitialized." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
@ -26,6 +26,8 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "al_helpers.h"
|
#include "al_helpers.h"
|
||||||
|
|
||||||
|
namespace sound {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for the openal device and context
|
* Class for the openal device and context
|
||||||
*/
|
*/
|
||||||
@ -58,3 +60,5 @@ public:
|
|||||||
|
|
||||||
~SoundManagerSingleton();
|
~SoundManagerSingleton();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sound
|
||||||
|
Loading…
Reference in New Issue
Block a user