Upgrade Audio (part 2)

This commit is contained in:
Jérôme Leclercq
2021-05-24 22:09:47 +02:00
parent ac57b3fbf4
commit 8cdd0b51cb
15 changed files with 158 additions and 104 deletions

View File

@@ -8,9 +8,11 @@
#define NAZARA_ALGORITHM_AUDIO_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Enums.hpp>
namespace Nz
{
inline UInt32 GetChannelCount(AudioFormat format);
template<typename T> void MixToMono(T* input, T* output, UInt32 channelCount, UInt64 frameCount);
}

View File

@@ -2,11 +2,52 @@
// This file is part of the "Nazara Engine - Audio module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Audio/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
/*!
* \ingroup audio
* \brief Get the number of channels occupied by an audio format
* \returns The number of channels occupied by an audio format (mono returns 1, stero returns 2, etc.)
*
* \param format A valid audio format
*
* \remark The format must be valid (using AudioFormat::Unknown will trigger an error)
*/
UInt32 GetChannelCount(AudioFormat format)
{
NazaraAssert(format != AudioFormat::Unknown, "invalid audio format");
switch (format)
{
case AudioFormat::Unknown: //< Just to make the compiler stop complaining
break;
case AudioFormat::U16_Mono:
return 1;
case AudioFormat::U16_Stereo:
return 2;
case AudioFormat::U16_Quad:
return 4;
case AudioFormat::U16_5_1:
return 6;
case AudioFormat::U16_6_1:
return 7;
case AudioFormat::U16_7_1:
return 8;
}
return 0;
}
/*!
* \ingroup audio
* \brief Mixes channels in mono

View File

@@ -32,7 +32,6 @@ namespace Nz
Audio(Audio&&) = delete;
~Audio();
AudioFormat GetAudioFormat(unsigned int channelCount) const;
float GetDopplerFactor() const;
float GetGlobalVolume() const;
Vector3f GetListenerDirection() const;

View File

@@ -9,27 +9,32 @@
namespace Nz
{
enum AudioFormat
enum class AudioFormat
{
AudioFormat_Unknown = -1,
Unknown = -1,
// The integer value is the number of channels used by the format
AudioFormat_Mono = 1,
AudioFormat_Stereo = 2,
AudioFormat_Quad = 4,
AudioFormat_5_1 = 6,
AudioFormat_6_1 = 7,
AudioFormat_7_1 = 8,
U16_Mono,
U16_Stereo,
U16_Quad,
U16_5_1,
U16_6_1,
U16_7_1,
AudioFormat_Max = AudioFormat_7_1
Max = U16_7_1
};
enum SoundStatus
constexpr std::size_t AudioFormatCount = static_cast<std::size_t>(AudioFormat::Max) + 1;
enum class SoundStatus
{
SoundStatus_Playing,
SoundStatus_Paused,
SoundStatus_Stopped
Playing,
Paused,
Stopped,
Max = Stopped
};
constexpr std::size_t SoundStatusCount = static_cast<std::size_t>(SoundStatus::Max) + 1;
}
#endif // NAZARA_ENUMS_AUDIO_HPP

View File

@@ -80,7 +80,7 @@ namespace Nz
static void Uninitialize();
static ALenum AudioFormat[AudioFormat_Max + 1];
static ALenum AudioFormat[AudioFormatCount];
private:
static void CloseDevice();