Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into slam-shake-tweak
  • Loading branch information
ASleepyCat committed Jul 18, 2020
2 parents 4ca3559 + a82ad2c commit 9fed86b
Show file tree
Hide file tree
Showing 89 changed files with 583 additions and 682 deletions.
9 changes: 8 additions & 1 deletion Audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ source_group("" FILES ${PCH_FILES})
enable_precompiled_headers("${AUDIO_SRC}" "${PCH_SRC}")

add_library(Audio ${AUDIO_SRC} ${PCH_FILES})
target_compile_features(Audio PUBLIC cxx_std_14)
target_compile_features(Audio PUBLIC cxx_std_17)
target_include_directories(Audio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(Audio PRIVATE
${SRCROOT}
${INCROOT}
${PCHROOT}
)

if(UNIX AND NOT APPLE)
target_compile_options(Audio PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-unused-value)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_options(Audio PUBLIC -Wno-maybe-uninitialized)
endif(CMAKE_BUILD_TYPE STREQUAL "Release")
endif(UNIX AND NOT APPLE)

# Dependencies
## Local Dependencies
target_link_libraries(Audio Shared)
Expand Down
1 change: 1 addition & 0 deletions Audio/include/Audio/DSP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PanDSP : public DSP
class BQFDSP : public DSP
{
public:
BQFDSP();
float b0 = 1.0f;
float b1 = 0.0f;
float b2 = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion Audio/src/AudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ Ref<AudioStream> AudioStream::Create(Audio* audio, const String& path, bool prel
{
Ref<AudioStream> impl = FindImplementation(audio, path, preload);
if(impl)
audio->GetImpl()->Register(impl.GetData());
audio->GetImpl()->Register(impl.get());
return impl;
}
2 changes: 1 addition & 1 deletion Audio/src/AudioStreamBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void AudioStreamBase::Process(float* out, uint32 numSamples)

if(m_samplePos > 0)
{
if(m_samplePos >= m_samplesTotal)
if((uint64)m_samplePos >= m_samplesTotal)
{
if(!m_ended)
{
Expand Down
8 changes: 4 additions & 4 deletions Audio/src/AudioStreamMa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"


AudioStreamMa::~AudioStreamMa()
{
Deregister();
Expand Down Expand Up @@ -93,7 +94,7 @@ int32 AudioStreamMa::DecodeData_Internal()
int actualRead = 0;
for (size_t i = 0; i < samplesPerRead; i++)
{
if (m_playbackPointer >= m_samplesTotal)
if (m_playbackPointer >= (int64)m_samplesTotal)
{
m_currentBufferSize = samplesPerRead;
m_remainingBufferData = samplesPerRead;
Expand All @@ -114,7 +115,7 @@ int32 AudioStreamMa::DecodeData_Internal()
float decodeBuffer[256];

int totalRead = ma_decoder_read_pcm_frames(&m_decoder, decodeBuffer, samplesPerRead);
for (size_t i = 0; i < totalRead; i++)
for (int i = 0; i < totalRead; i++)
{
m_readBuffer[0][i] = decodeBuffer[i * 2];
m_readBuffer[1][i] = decodeBuffer[i * 2 + 1];
Expand All @@ -141,7 +142,6 @@ Ref<AudioStream> AudioStreamMa::Create(class Audio* audio, const String& path, b
{
delete impl;
impl = nullptr;
return Ref<AudioStream>();
}
return Ref<AudioStream>(impl);
return Utility::CastRef<AudioStreamMa, AudioStream>(Ref<AudioStreamMa>(impl));
}
6 changes: 3 additions & 3 deletions Audio/src/AudioStreamMa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ class AudioStreamMa : public AudioStreamBase
int64 m_playbackPointer = 0;
uint64 m_dataPosition = 0;
const int sample_rate = 48000;
ma_decoder m_decoder;
ma_decoder m_decoder = { };
int m_byteRate;
protected:
AudioStreamMa() = default;
~AudioStreamMa();
bool Init(Audio* audio, const String& path, bool preload) override;
int32 GetStreamPosition_Internal() override;
int32 GetStreamRate_Internal() override;
Expand All @@ -23,5 +21,7 @@ class AudioStreamMa : public AudioStreamBase
float* GetPCM_Internal() override;
uint32 GetSampleRate_Internal() const override;
public:
AudioStreamMa() = default;
~AudioStreamMa();
static Ref<AudioStream> Create(class Audio* audio, const String& path, bool preload);
};
4 changes: 2 additions & 2 deletions Audio/src/AudioStreamMp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool AudioStreamMp3::Init(Audio* audio, const String& path, bool preload)
int totalSamples = 0;
while (r > 0)
{
for (size_t i = 0; i < r; i++)
for (int32 i = 0; i < r; i++)
{
m_pcm.Add(m_readBuffer[0][i]);
m_pcm.Add(m_readBuffer[1][i]);
Expand Down Expand Up @@ -218,7 +218,7 @@ int32 AudioStreamMp3::DecodeData_Internal()
m_playPos++;
continue;
}
else if (m_playPos >= m_samplesTotal)
else if ((uint64)m_playPos >= m_samplesTotal)
{
m_currentBufferSize = samplesPerRead;
m_remainingBufferData = samplesPerRead;
Expand Down
7 changes: 4 additions & 3 deletions Audio/src/AudioStreamMp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C"

class AudioStreamMp3 : public AudioStreamBase
{
mp3_decoder_t* m_decoder;
mp3_decoder_t* m_decoder = nullptr;
size_t m_mp3dataOffset = 0;
size_t m_mp3dataLength = 0;
int32 m_mp3samplePosition = 0;
Expand All @@ -23,8 +23,7 @@ class AudioStreamMp3 : public AudioStreamBase
int m_unsynchsafe(int in);
int m_toLittleEndian(int num);
protected:
AudioStreamMp3() = default;
~AudioStreamMp3();

bool Init(Audio* audio, const String& path, bool preload) override;
void SetPosition_Internal(int32 pos) override;
int32 GetStreamPosition_Internal() override;
Expand All @@ -33,5 +32,7 @@ class AudioStreamMp3 : public AudioStreamBase
float* GetPCM_Internal() override;
int32 DecodeData_Internal() override;
public:
AudioStreamMp3() = default;
~AudioStreamMp3();
static Ref<AudioStream> Create(Audio* audio, const String& path, bool preload);
};
6 changes: 3 additions & 3 deletions Audio/src/AudioStreamOgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ bool AudioStreamOgg::Init(Audio* audio, const String& path, bool preload)
{
if (m_info.channels == 2)
{
for (size_t i = 0; i < r; i++)
for (int i = 0; i < r; i++)
{
m_pcm.Add(readBuffer[0][i]);
m_pcm.Add(readBuffer[1][i]);
}
}
else if (m_info.channels == 1)
{
for (size_t i = 0; i < r; i++)
for (int i = 0; i < r; i++)
{
m_pcm.Add(readBuffer[0][i]);
m_pcm.Add(readBuffer[0][i]);
Expand Down Expand Up @@ -139,7 +139,7 @@ int32 AudioStreamOgg::DecodeData_Internal()
m_playPos++;
continue;
}
else if (m_playPos >= m_samplesTotal)
else if ((uint64)m_playPos >= m_samplesTotal)
{
m_currentBufferSize = m_bufferSize;
m_remainingBufferData = m_bufferSize;
Expand Down
7 changes: 4 additions & 3 deletions Audio/src/AudioStreamOgg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
class AudioStreamOgg : public AudioStreamBase
{
protected:
OggVorbis_File m_ovf = { 0 };
OggVorbis_File m_ovf;
vorbis_info m_info;
Vector<float> m_pcm;
int64 m_playPos;

AudioStreamOgg() = default;
~AudioStreamOgg();

bool Init(Audio* audio, const String& path, bool preload) override;
void SetPosition_Internal(int32 pos) override;
int32 GetStreamPosition_Internal() override;
Expand All @@ -25,5 +24,7 @@ class AudioStreamOgg : public AudioStreamBase
static int m_Seek(AudioStreamOgg* self, int64 offset, int whence);
static long m_Tell(AudioStreamOgg* self);
public:
AudioStreamOgg() = default;
~AudioStreamOgg();
static Ref<AudioStream> Create(class Audio* audio, const String& path, bool preload);
};
12 changes: 6 additions & 6 deletions Audio/src/AudioStreamWav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ bool AudioStreamWav::Init(Audio* audio, const String& path, bool preload)


//Decode to float
int pos = 0;
uint64 pos = 0;
m_pcm.resize(2 * m_samplesTotal * sizeof(float));
if (m_format.nFormat == 1)
{
Expand Down Expand Up @@ -191,10 +191,10 @@ bool AudioStreamWav::Init(Audio* audio, const String& path, bool preload)

while (pos < m_samplesTotal)
{
int newDecoded = m_decode_ms_adpcm(m_Internaldata, &decodedBuffer, pos);
uint32 newDecoded = m_decode_ms_adpcm(m_Internaldata, &decodedBuffer, pos);
pos += m_format.nBlockAlign;
int16* src = ((int16*)decodedBuffer.data());
for (size_t i = 0; i < newDecoded; i++)
for (uint32 i = 0; i < newDecoded; i++)
{
m_pcm[(2 * decoded) + (i * 2)] = (float)src[i * 2] / (float)0x7FFF;
m_pcm[(2 * decoded) + (i * 2) + 1] = (float)src[i * 2 + 1] / (float)0x7FFF;
Expand Down Expand Up @@ -335,7 +335,7 @@ int32 AudioStreamWav::DecodeData_Internal()
{
for (uint32 i = 0; i < samplesPerRead; i++)
{
if (m_playbackPointer >= m_samplesTotal)
if (m_playbackPointer >= (int64)m_samplesTotal)
{
m_currentBufferSize = samplesPerRead;
m_remainingBufferData = samplesPerRead;
Expand All @@ -352,7 +352,7 @@ int32 AudioStreamWav::DecodeData_Internal()
// Mix mono sample
for (uint32 i = 0; i < samplesPerRead; i++)
{
if (m_playbackPointer >= m_samplesTotal)
if (m_playbackPointer >= (int64)m_samplesTotal)
{
m_currentBufferSize = samplesPerRead;
m_remainingBufferData = samplesPerRead;
Expand Down Expand Up @@ -409,7 +409,7 @@ int32 AudioStreamWav::DecodeData_Internal()
m_playbackPointer++;
continue;
}
else if (m_playbackPointer >= m_samplesTotal)
else if (m_playbackPointer >= (int64)m_samplesTotal)
{
m_currentBufferSize = samplesPerRead;
m_remainingBufferData = samplesPerRead;
Expand Down
7 changes: 4 additions & 3 deletions Audio/src/AudioStreamWav.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ class AudioStreamWav : public AudioStreamBase
uint16 nBitsPerSample;
};
Buffer m_Internaldata;
WavFormat m_format = { 0 };
WavFormat m_format;
Vector<float> m_pcm;
int64 m_playbackPointer = 0;
uint64 m_dataPosition = 0;
uint32 m_decode_ms_adpcm(const Buffer& encoded, Buffer* decoded, uint64 pos);

protected:
AudioStreamWav() = default;
~AudioStreamWav();

bool Init(Audio* audio, const String& path, bool preload) override;
int32 GetStreamPosition_Internal() override;
int32 GetStreamRate_Internal() override;
Expand All @@ -47,5 +46,7 @@ class AudioStreamWav : public AudioStreamBase
float* GetPCM_Internal() override;
uint32 GetSampleRate_Internal() const override;
public:
AudioStreamWav() = default;
~AudioStreamWav();
static Ref<AudioStream> Create(class Audio* audio, const String& path, bool preload);
};
Loading

0 comments on commit 9fed86b

Please sign in to comment.