1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Get moved audio code linking

This commit is contained in:
Ted John
2017-03-29 17:46:02 +01:00
committed by Gymnasiast
parent d206d181f2
commit e426c70bbc
9 changed files with 72 additions and 40 deletions

View File

@@ -26,10 +26,10 @@
namespace OpenRCT2 { namespace Audio
{
class AudioChannelImpl : public IAudioChannel
class AudioChannelImpl : public ISDLAudioChannel
{
private:
IAudioSource * _source = nullptr;
ISDLAudioSource * _source = nullptr;
SpeexResamplerState * _resampler = nullptr;
sint32 _group = MIXER_GROUP_SOUND;
@@ -232,7 +232,7 @@ namespace OpenRCT2 { namespace Audio
void Play(IAudioSource * source, sint32 loop) override
{
_source = source;
_source = static_cast<ISDLAudioSource *>(source);
_loop = loop;
_offset = 0;
_done = false;
@@ -290,7 +290,7 @@ namespace OpenRCT2 { namespace Audio
}
};
IAudioChannel * AudioChannel::Create()
ISDLAudioChannel * AudioChannel::Create()
{
return new (std::nothrow) AudioChannelImpl();
}

View File

@@ -15,23 +15,34 @@
#pragma endregion
#include <openrct2/audio/AudioContext.h>
#include "AudioContext.h"
namespace OpenRCT2 { namespace Audio
{
class AudioContext : public IAudioContext
{
private:
IAudioMixer * _audioMixer;
public:
virtual ~AudioContext()
AudioContext()
{
_audioMixer = AudioMixer::Create();
}
virtual void SetOutputDevice(const char * deviceName) override
IAudioMixer * GetMixer() override
{
return _audioMixer;
}
virtual IAudioSource * CreateStreamFromWAV(const std::string &path) override
void SetOutputDevice(const char * deviceName) override
{
return nullptr;
_audioMixer->Init(deviceName);
}
IAudioSource * CreateStreamFromWAV(const std::string &path) override
{
return AudioSource::CreateStreamFromWAV(path);
}
void StartTitleMusic() override { }

View File

@@ -3,11 +3,16 @@
#include <string>
#include <openrct2/common.h>
#include <openrct2/audio/AudioChannel.h>
#include <openrct2/audio/AudioSource.h>
struct SDL_RWops;
struct SpeexResamplerState_;
typedef struct SpeexResamplerState_ SpeexResamplerState;
namespace OpenRCT2 { namespace Audio
{
struct AudioFormat;
interface IAudioSource;
struct AudioFormat;
#pragma pack(push, 1)
struct WaveFormat
@@ -34,6 +39,18 @@ namespace OpenRCT2 { namespace Audio
assert_struct_size(WaveFormatEx, 18);
#pragma pack(pop)
interface ISDLAudioSource : public IAudioSource
{
virtual AudioFormat GetFormat() const abstract;
};
interface ISDLAudioChannel : public IAudioChannel
{
virtual AudioFormat GetFormat() const abstract;
virtual SpeexResamplerState * GetResampler() const abstract;
virtual void SetResampler(SpeexResamplerState * value) abstract;
};
namespace AudioSource
{
IAudioSource * CreateMemoryFromCSS1(const std::string &path, size_t index, const AudioFormat * targetFormat = nullptr);
@@ -41,4 +58,14 @@ namespace OpenRCT2 { namespace Audio
IAudioSource * CreateStreamFromWAV(const std::string &path);
IAudioSource * CreateStreamFromWAV(SDL_RWops * rw);
}
namespace AudioChannel
{
ISDLAudioChannel * Create();
}
namespace AudioMixer
{
IAudioMixer * Create();
}
} }

View File

@@ -40,7 +40,6 @@ extern "C"
namespace OpenRCT2 { namespace Audio
{
struct Buffer
{
private:
@@ -74,14 +73,14 @@ namespace OpenRCT2 { namespace Audio
}
};
class AudioMixer final : public IAudioMixer
class AudioMixerImpl final : public IAudioMixer
{
private:
IAudioSource * _nullSource = nullptr;
SDL_AudioDeviceID _deviceId = 0;
AudioFormat _format = { 0 };
std::list<IAudioChannel *> _channels;
std::list<ISDLAudioChannel *> _channels;
float _volume = 1.0f;
float _adjustSoundVolume = 0.0f;
float _adjustMusicVolume = 0.0f;
@@ -96,18 +95,18 @@ namespace OpenRCT2 { namespace Audio
Buffer _effectBuffer;
public:
AudioMixer()
AudioMixerImpl()
{
_nullSource = AudioSource::CreateNull();
}
~AudioMixer()
~AudioMixerImpl()
{
Close();
delete _nullSource;
}
void Init(const char* device) override
void Init(const char * device) override
{
Close();
@@ -118,7 +117,7 @@ namespace OpenRCT2 { namespace Audio
want.samples = 1024;
want.callback = [](void * arg, uint8 * dst, sint32 length) -> void
{
auto mixer = static_cast<AudioMixer *>(arg);
auto mixer = static_cast<AudioMixerImpl *>(arg);
mixer->GetNextAudioChunk(dst, (size_t)length);
};
want.userdata = this;
@@ -182,7 +181,7 @@ namespace OpenRCT2 { namespace Audio
IAudioChannel * Play(IAudioSource * source, sint32 loop, bool deleteondone, bool deletesourceondone) override
{
Lock();
IAudioChannel * channel = AudioChannel::Create();
ISDLAudioChannel * channel = AudioChannel::Create();
if (channel != nullptr)
{
channel->Play(source, loop);
@@ -260,11 +259,10 @@ namespace OpenRCT2 { namespace Audio
Memory::Set(dst, 0, length);
// Mix channels onto output buffer
std::list<IAudioChannel *>::iterator it = _channels.begin();
auto it = _channels.begin();
while (it != _channels.end())
{
IAudioChannel * channel = *it;
auto channel = *it;
sint32 group = channel->GetGroup();
if (group != MIXER_GROUP_SOUND || gConfigSound.sound_enabled)
{
@@ -297,7 +295,7 @@ namespace OpenRCT2 { namespace Audio
}
}
void MixChannel(IAudioChannel * channel, uint8 * data, size_t length)
void MixChannel(ISDLAudioChannel * channel, uint8 * data, size_t length)
{
sint32 byteRate = _format.GetByteRate();
sint32 numSamples = (sint32)(length / byteRate);
@@ -372,7 +370,7 @@ namespace OpenRCT2 { namespace Audio
* Resample the given buffer into _effectBuffer.
* Assumes that srcBuffer is the same format as _format.
*/
size_t ApplyResample(IAudioChannel * channel, const void * srcBuffer, sint32 srcSamples, sint32 dstSamples)
size_t ApplyResample(ISDLAudioChannel * channel, const void * srcBuffer, sint32 srcSamples, sint32 dstSamples)
{
sint32 byteRate = _format.GetByteRate();
@@ -536,4 +534,9 @@ namespace OpenRCT2 { namespace Audio
return result;
}
};
IAudioMixer * AudioMixer::Create()
{
return new AudioMixerImpl();
}
} }

View File

@@ -27,7 +27,7 @@ namespace OpenRCT2 { namespace Audio
* An audio source where raw PCM data is streamed directly from
* a file.
*/
class FileAudioSource final : public IAudioSource
class FileAudioSource final : public ISDLAudioSource
{
private:
AudioFormat _format = { 0 };
@@ -41,12 +41,12 @@ namespace OpenRCT2 { namespace Audio
Unload();
}
uint64 GetLength() override
uint64 GetLength() const override
{
return _dataLength;
}
AudioFormat GetFormat() override
AudioFormat GetFormat() const override
{
return _format;
}

View File

@@ -29,7 +29,7 @@ namespace OpenRCT2 { namespace Audio
* An audio source where raw PCM data is initially loaded into RAM from
* a file and then streamed.
*/
class MemoryAudioSource final : public IAudioSource
class MemoryAudioSource final : public ISDLAudioSource
{
private:
AudioFormat _format = { 0 };
@@ -43,12 +43,12 @@ namespace OpenRCT2 { namespace Audio
Unload();
}
uint64 GetLength() override
uint64 GetLength() const override
{
return _length;
}
AudioFormat GetFormat() override
AudioFormat GetFormat() const override
{
return _format;
}

View File

@@ -32,9 +32,6 @@ namespace OpenRCT2 { namespace Audio
virtual IAudioSource * GetSource() const abstract;
// virtual SpeexResamplerState * GetResampler() const abstract;
// virtual void SetResampler(SpeexResamplerState * value) abstract;
virtual sint32 GetGroup() const abstract;
virtual void SetGroup(sint32 group) abstract;
@@ -74,12 +71,6 @@ namespace OpenRCT2 { namespace Audio
virtual void Play(IAudioSource * source, sint32 loop = 0) abstract;
virtual void UpdateOldVolume() abstract;
// virtual AudioFormat GetFormat() const abstract;
virtual size_t Read(void * dst, size_t len) abstract;
};
namespace AudioChannel
{
IAudioChannel * Create();
}
} }

View File

@@ -28,7 +28,7 @@ namespace OpenRCT2 { namespace Audio
{
virtual ~IAudioSource() = default;
virtual uint64 GetLength() abstract;
virtual uint64 GetLength() const abstract;
// virtual AudioFormat GetFormat() abstract;
virtual size_t Read(void * dst, uint64 offset, size_t len) abstract;
};

View File

@@ -24,7 +24,7 @@ namespace OpenRCT2 { namespace Audio
class NullAudioSource : public IAudioSource
{
public:
uint64 GetLength() override
uint64 GetLength() const override
{
return 0;
}