Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Port replayer to Linux #49

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
110a5ef
move stuff around so that it at least compiles on linux (but it's abs…
PoroCYon Aug 30, 2020
2ce9ca6
add inline assembly stuff (from earlier porting tries), enable optimi…
PoroCYon Aug 30, 2020
31885d1
factor out the actual platform-specific renderthread/player stuff
PoroCYon Aug 30, 2020
c068941
remove need for -fpermissive flag, optional foreground work stuff for…
PoroCYon Aug 30, 2020
d781da5
w00t the WAV writer works now
PoroCYon Aug 31, 2020
941f035
prerender player on linux (untested)
PoroCYon Aug 31, 2020
78a9e68
fix cmake error
PoroCYon Aug 31, 2020
8e3c7ad
fix more cmake errors
PoroCYon Aug 31, 2020
284eec2
aplay prerender works, tackling multithread now
PoroCYon Aug 31, 2020
b8cb3c3
aplay somewhat working, debugging misc issues now
PoroCYon Aug 31, 2020
f320448
asm maths issues debugging ep.1
PoroCYon Aug 31, 2020
0b5ebc6
asm maths issues debugging ep.2
PoroCYon Aug 31, 2020
3cc35a7
right, windows...
PoroCYon Aug 31, 2020
8743101
properly fix all aplay RT stuff
PoroCYon Aug 31, 2020
4831bfc
wow, an argument parser that's actually helpful!
PoroCYon Sep 1, 2020
1ca8809
proper thread stopping
PoroCYon Sep 1, 2020
b1bfd75
SDL backend
PoroCYon Sep 1, 2020
cd1a918
synchronous/non-threaded option
PoroCYon Sep 1, 2020
b39a67a
fix windows cmake once more
PoroCYon Sep 1, 2020
a8061ee
fix assembly maths functions
PoroCYon Sep 1, 2020
27d5277
factor out sample loading logic from Thunder and Specimen
PoroCYon Sep 3, 2020
38d1a95
it broke the Windows bulid
PoroCYon Sep 3, 2020
56344f6
psh, vst sources relying on the core to include all the dependency he…
PoroCYon Sep 3, 2020
bd872fb
more of the same
PoroCYon Sep 3, 2020
586aea0
and move some stuff back to the headers
PoroCYon Sep 3, 2020
876f0cb
oops please don't look at the previous commit
PoroCYon Sep 3, 2020
fabbe20
saving unfinished horror code for now
PoroCYon Sep 3, 2020
e31e269
oh no it's starting to work
PoroCYon Sep 3, 2020
f9a24b2
forgot the extra wavefmtex info
PoroCYon Sep 3, 2020
cd412c1
extremely ugly gm.dls stuff
PoroCYon Sep 3, 2020
0c17f77
and fix the bugs
PoroCYon Sep 3, 2020
c23e940
stuff
PoroCYon Sep 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Release/
Vsts/build/
Tests/PlayerTest/build/
build/
cmake-build/
Vst3.x/*
!Vst3.x/README
Data/data.aps
Expand Down
31 changes: 25 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,43 @@ project("WaveSabre")
cmake_minimum_required(VERSION 3.11)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(NOT WIN32)
# compo build defaults
option(ENABLE_PTHREADS "Use Pthreads for threading" OFF)
option(ENABLE_APLAY "Enable aplay(1) backend for audio playback" ON)
option(ENABLE_SDL2 "Enable SDL2_Audio backend for audio playback" OFF)
option(ENABLE_FFMPEG_GSM "Enable GSM 6.10 sample decoding using FFmpeg. Required for Thunder and Specimen." OFF)
option(ENABLE_EXTERNAL_GMDLS "Enable using a gm.dls file provided at runtime" OFF)
# for standalone playback, or playing back Windows-specific tracks, you
# probably want to enable all of the above options
endif()

if(MSVC)
# disable exceptions globally (will be added back for VSTs)
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()

set(VSTSDK3_DIR "./Vst3.x/" CACHE PATH "VSTSDK location")
if(WIN32)
set(VSTSDK3_DIR "./Vst3.x/" CACHE PATH "VSTSDK location")
endif()

# shared code
add_subdirectory(MSVCRT)
if(WIN32)
add_subdirectory(MSVCRT)
endif()
add_subdirectory(WaveSabreCore)
add_subdirectory(WaveSabrePlayerLib)

# binaries
add_subdirectory(Tests/PlayerTest)
if(WIN32)
add_subdirectory(Tests/PlayerTest)
endif()
add_subdirectory(WaveSabreStandAlonePlayer)

# VSTs
if(VSTSDK3_DIR)
add_subdirectory(WaveSabreVstLib)
add_subdirectory(Vsts)
if(WIN32)
if(VSTSDK3_DIR)
add_subdirectory(WaveSabreVstLib)
add_subdirectory(Vsts)
endif()
endif()
38 changes: 36 additions & 2 deletions WaveSabreCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_library(WaveSabreCore
include/WaveSabreCore/Leveller.h
include/WaveSabreCore/MxcsrFlagGuard.h
include/WaveSabreCore/ResampleBuffer.h
include/WaveSabreCore/SampleLoader.h
include/WaveSabreCore/SamplePlayer.h
include/WaveSabreCore/Scissor.h
include/WaveSabreCore/Slaughter.h
Expand Down Expand Up @@ -44,6 +45,7 @@ add_library(WaveSabreCore
src/Leveller.cpp
src/MxcsrFlagGuard.cpp
src/ResampleBuffer.cpp
src/SampleLoader.cpp
src/SamplePlayer.cpp
src/Scissor.cpp
src/Slaughter.cpp
Expand All @@ -52,9 +54,16 @@ add_library(WaveSabreCore
src/StateVariableFilter.cpp
src/SynthDevice.cpp
src/Thunder.cpp
src/Twister.cpp)
src/Twister.cpp
)

if(WIN32)
target_sources(WaveSabreCore PRIVATE
)

target_link_libraries(WaveSabreCore PUBLIC Msacm32.lib)
endif()

target_link_libraries(WaveSabreCore Msacm32.lib)
target_include_directories(WaveSabreCore PUBLIC include)

if(MSVC)
Expand All @@ -69,4 +78,29 @@ if(MSVC)
target_compile_options(WaveSabreCore PUBLIC
$<$<CONFIG:MinSizeRel>:/Zc:sizedDealloc->)
endif()
else()
# assuming GCC or clang for now

if(ENABLE_FFMPEG_GSM)
message(NOTICE "Enabling FFmpeg GSM 6.10 decoding")
target_compile_definitions(WaveSabreCore PRIVATE HAVE_FFMPEG_GSM=1)
else()
message(NOTICE "FFmpeg GSM 6.10 decoding disabled")
endif()

if(ENABLE_EXTERNAL_GMDLS)
message(NOTICE "Enabling gm.dls support")
target_compile_definitions(WaveSabreCore PRIVATE HAVE_EXTERNAL_GMDLS=1)
else()
message(NOTICE "External gm.dls loading disabled")
endif()

if(CMAKE_BUILD_TYPE EQUAL Debug)
target_compile_options(WaveSabreCore PUBLIC -g -Og)
else()
#set_property(TARGET WaveSabreCore PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
target_compile_options(WaveSabreCore
PUBLIC -O2 -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics
PRIVATE -ffast-math -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections)
endif()
endif()
58 changes: 58 additions & 0 deletions WaveSabreCore/include/WaveSabreCore/SampleLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef __WAVESABRECORE_SAMPLELOADER_H__
#define __WAVESABRECORE_SAMPLELOADER_H__

#if defined(WIN32) || defined(_WIN32)
#include <Windows.h>
#include <mmreg.h>

#ifdef UNICODE
#define _UNICODE
#endif
#include <MSAcm.h>
#else /* not WIN32 */
#include <stdint.h>

typedef struct __attribute__((__packed__)) tWAVEFORMATEX {
int16_t wFormatTag;
int16_t nChannels;
int32_t nSamplesPerSec;
int32_t nAvgBytesPerSec;
int16_t nBlockAlign;
int16_t wBitsPerSample;
int16_t cbSize;
} WAVEFORMATEX;
#endif /* WIN32 */

namespace WaveSabreCore
{
class SampleLoader
{
public:
static const int SampleRate = 44100;

struct LoadedSample {
char *chunkData;

char *waveFormatData;
int compressedSize, uncompressedSize;

char *compressedData;
float *sampleData;

int sampleLength;
};

static LoadedSample LoadSampleGSM(char *data, int compressedSize, int uncompressedSize, WAVEFORMATEX *waveFormat);

private:
#if defined(WIN32) || defined(_WIN32)
static BOOL __stdcall driverEnumCallback(HACMDRIVERID driverId, DWORD_PTR dwInstance, DWORD fdwSupport);
static BOOL __stdcall formatEnumCallback(HACMDRIVERID driverId, LPACMFORMATDETAILS formatDetails, DWORD_PTR dwInstance, DWORD fdwSupport);

static HACMDRIVERID driverId;
#endif

};
}

#endif
40 changes: 23 additions & 17 deletions WaveSabreCore/include/WaveSabreCore/Specimen.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
#include "SynthDevice.h"
#include "Envelope.h"
#include "StateVariableFilter.h"
#include "SampleLoader.h"
#include "SamplePlayer.h"

#include <Windows.h>
#include <mmreg.h>

#ifdef UNICODE
#define _UNICODE
#endif
#include <MSAcm.h>

namespace WaveSabreCore
{
class Specimen : public SynthDevice
{
public:
static const int SampleRate = SampleLoader::SampleRate;

enum class ParamIndices
{
AmpAttack,
Expand Down Expand Up @@ -59,8 +54,6 @@ namespace WaveSabreCore
NumParams,
};

static const int SampleRate = 44100;

Specimen();
virtual ~Specimen();

Expand All @@ -70,8 +63,26 @@ namespace WaveSabreCore
virtual void SetChunk(void *data, int size);
virtual int GetChunk(void **data);

void LoadSample(char *data, int compressedSize, int uncompressedSize, WAVEFORMATEX *waveFormat);

inline void LoadSample(char *compressedDataPtr, int compressedSize,
int uncompressedSize, WAVEFORMATEX *waveFormatPtr)
{
auto sample = SampleLoader::LoadSampleGSM(compressedDataPtr,
compressedSize, uncompressedSize, waveFormatPtr);

this->compressedSize = sample.compressedSize;
this->uncompressedSize = sample.uncompressedSize;

if (waveFormatData) delete [] waveFormatData;
waveFormatData = sample.waveFormatData;
if (compressedData) delete [] compressedData;
compressedData = sample.compressedData;
if (sampleData) delete [] sampleData;
sampleData = sample.sampleData;

sampleLength = sample.sampleLength;
sampleLoopStart = 0;
sampleLoopLength = sampleLength;
}
private:
class SpecimenVoice : public Voice
{
Expand Down Expand Up @@ -99,11 +110,6 @@ namespace WaveSabreCore
float velocity;
};

static BOOL __stdcall driverEnumCallback(HACMDRIVERID driverId, DWORD_PTR dwInstance, DWORD fdwSupport);
static BOOL __stdcall formatEnumCallback(HACMDRIVERID driverId, LPACMFORMATDETAILS formatDetails, DWORD_PTR dwInstance, DWORD fdwSupport);

static HACMDRIVERID driverId;

char *chunkData;

char *waveFormatData;
Expand Down
34 changes: 19 additions & 15 deletions WaveSabreCore/include/WaveSabreCore/Thunder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,39 @@
#define __WAVESABRECORE_THUNDER_H__

#include "SynthDevice.h"

#include <Windows.h>
#include <mmreg.h>

#ifdef UNICODE
#define _UNICODE
#endif
#include <MSAcm.h>
#include "SampleLoader.h"

namespace WaveSabreCore
{
class Thunder : public SynthDevice
{
public:
static const int SampleRate = 44100;
static const int SampleRate = SampleLoader::SampleRate;

Thunder();
virtual ~Thunder();

virtual void SetChunk(void *data, int size);
virtual int GetChunk(void **data);

void LoadSample(char *data, int compressedSize, int uncompressedSize, WAVEFORMATEX *waveFormat);
inline void LoadSample(char *compressedDataPtr, int compressedSize,
int uncompressedSize, WAVEFORMATEX *waveFormatPtr)
{
auto sample = SampleLoader::LoadSampleGSM(compressedDataPtr,
compressedSize, uncompressedSize, waveFormatPtr);

this->compressedSize = sample.compressedSize;
this->uncompressedSize = sample.uncompressedSize;

if (waveFormatData) delete [] waveFormatData;
waveFormatData = sample.waveFormatData;
if (compressedData) delete [] compressedData;
compressedData = sample.compressedData;
if (sampleData) delete [] sampleData;
sampleData = sample.sampleData;

sampleLength = sample.sampleLength;
}
private:
class ThunderVoice : public Voice
{
Expand All @@ -43,11 +52,6 @@ namespace WaveSabreCore
int samplePos;
};

static BOOL __stdcall driverEnumCallback(HACMDRIVERID driverId, DWORD_PTR dwInstance, DWORD fdwSupport);
static BOOL __stdcall formatEnumCallback(HACMDRIVERID driverId, LPACMFORMATDETAILS formatDetails, DWORD_PTR dwInstance, DWORD fdwSupport);

static HACMDRIVERID driverId;

char *chunkData;

char *waveFormatData;
Expand Down
2 changes: 1 addition & 1 deletion WaveSabreCore/include/WaveSabreCore/Twister.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace WaveSabreCore

ResampleBuffer leftBuffer;
ResampleBuffer rightBuffer;

StateVariableFilter lowCutFilter[2], highCutFilter[2];
};
}
Expand Down
13 changes: 11 additions & 2 deletions WaveSabreCore/src/Adultery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ namespace WaveSabreCore
if (sampleIndex >= 0)
{
auto gmDls = GmDls::Load();
if (gmDls == nullptr) {
sampleLength = 1;
sampleData = new float[sampleLength];
sampleData[0] = 0.0f;
sampleLoopStart = 0;
sampleLoopLength = 1;

break;
}

// Seek to wave pool chunk's data
auto ptr = gmDls + GmDls::WaveListOffset;
Expand Down Expand Up @@ -240,7 +249,7 @@ namespace WaveSabreCore
case ParamIndices::VoicesUnisono: return Helpers::UnisonoToParam(VoicesUnisono);
case ParamIndices::VoicesDetune: return VoicesDetune;
case ParamIndices::VoicesPan: return VoicesPan;

case ParamIndices::VoiceMode: return Helpers::VoiceModeToParam(GetVoiceMode());
case ParamIndices::SlideTime: return Slide;

Expand Down Expand Up @@ -319,7 +328,7 @@ namespace WaveSabreCore
modEnv.Sustain = adultery->modSustain;
modEnv.Release = adultery->modRelease;
modEnv.Trigger();

samplePlayer.SampleData = adultery->sampleData;
samplePlayer.SampleLength = adultery->sampleLength;
samplePlayer.SampleLoopStart = adultery->sampleLoopStart;
Expand Down
2 changes: 1 addition & 1 deletion WaveSabreCore/src/Cathedral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace WaveSabreCore
outL += combLeft[i].Process(input);
outR += combRight[i].Process(input);
}

// Feed through allpasses in series
for (int i = 0; i < numAllPasses; i++)
{
Expand Down
Loading