Skip to content

Commit

Permalink
Integration of PortAudio for sound output
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbradsmith authored May 10, 2024
1 parent 9d4210d commit df74b47
Show file tree
Hide file tree
Showing 17 changed files with 481 additions and 54 deletions.
102 changes: 72 additions & 30 deletions .github/workflows/build_nsfplay3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
run: make core_notext
- name: Build Minimal Core
run: make core_minimal
- name: Build No-Sound Cmd
run: make cmd_nosound
# Not testing this, to avoid these tests depending on wxWidgets
#- name: Build No-Sound NSFPlay
# run: make nsfplay_nosound

build-msvc:
name: Windows MSVC
Expand All @@ -33,19 +38,23 @@ jobs:
uses: actions/checkout@v4
- name: Setup MSVC
uses: microsoft/setup-msbuild@v2
- name: wxWidgets Cache Key
- name: Submodule Cache Keys
shell: pwsh
run: echo "WXHASH=$($(git submodule status wx) -replace '\s','')" >> $env:GITHUB_ENV
- name: Cache wxWidgets
id: cache-wx
run: |
echo "WXHASH=$($(git submodule status wx) -replace '\s','')" >> $env:GITHUB_ENV
echo "PAHASH=$($(git submodule status portaudio) -replace '\s','')" >> $env:GITHUB_ENV
- name: Cache Submodules
id: cache-sub
uses: actions/cache@v4
with:
path: |
wxlib/lib
wxlib/include
key: wx-msvc-${{ env.WXHASH }}
- name: Build wxWidgets
if: steps.cache-wx.outputs.cache-hit != 'true'
portaudiolib/vc64
portaudiolib/vc32
key: sub-msvc-${{ env.WXHASH }}-${{ env.PAHASH }}
- name: Build Submodules
if: steps.cache-sub.outputs.cache-hit != 'true'
shell: cmd
run: |
echo on
Expand All @@ -57,7 +66,10 @@ jobs:
cd ..
set WXB_NODEBUG=1
set WXB_NOPAUSE=1
wxlib.bat
call wxlib.bat
set PAB_NODEBUG=1
set PAB_NOPAUSE=1
call portaudiolib.bat
- name: Build 64-bit
run: msbuild nsfplay.sln -t:rebuild -property:Configuration=Release -property:Platform=x64
- name: Build 32-bit
Expand Down Expand Up @@ -98,36 +110,48 @@ jobs:
with:
msystem: UCRT64
install: git make mingw-w64-ucrt-x86_64-gcc mingw-w64-i686-gcc mingw-w64-ucrt-x86_64-cmake mingw-w64-i686-cmake
- name: wxWidgets Cache Key
- name: Submodule Cache Keys
shell: pwsh
run: echo "WXHASH=$($(git submodule status wx) -replace '\s','')" >> $env:GITHUB_ENV
- name: Cache wxWidgets
id: cache-wx
run: |
echo "WXHASH=$($(git submodule status wx) -replace '\s','')" >> $env:GITHUB_ENV
echo "PAHASH=$($(git submodule status portaudio) -replace '\s','')" >> $env:GITHUB_ENV
- name: Cache Submodules
id: cache-sub
uses: actions/cache@v4
with:
path: |
wxlib/lib
wxlib/include
key: wx-msys2-${{ env.WXHASH }}
- name: Build wxWidgets
if: steps.cache-wx.outputs.cache-hit != 'true'
portaudiolib/make64
portaudiolib/make32
key: sub-msys2-${{ env.WXHASH }}-${{ env.PAHASH }}
- name: Build Submodules
if: steps.cache-sub.outputs.cache-hit != 'true'
shell: msys2 {0}
run: |
export WXL_CMAKEDIR=make64
export PAOUT=portaudiolib/make64
export PACMAKE=../make64_cmake
make wxlib
make portaudiolib
export PATH="/mingw32/bin:$PATH"
export WXL_CMAKEDIR=make32
export PAOUT=portaudiolib/make32
export PACMAKE=../make32_cmake
make wxlib
make portaudiolib
- name: Make 64-bit
shell: msys2 {0}
run: |
export PAL_DIR=../portaudiolib/make64
export OUTDIR=output/make64 INTDIR=intermediate/make64
make cmd nsfplay
- name: Make 32-bit
shell: msys2 {0}
run: |
export PATH="/mingw32/bin:$PATH"
export WXL_LIBDIR=gcc_lib
export PAL_DIR=../portaudiolib/make32
export OUTDIR=output/make32 INTDIR=intermediate/make32
make cmd nsfplay winamp
- name: Prepare Artifacts
Expand Down Expand Up @@ -164,23 +188,27 @@ jobs:
- name: Setup Ubuntu
run: |
sudo apt-get update
sudo apt-get install git make gcc cmake libgtk-3-dev
- name: wxWidgets Cache Key
run: echo "WXHASH=$(git submodule status wx | tr -d '[:blank:]')" >> $GITHUB_ENV
- name: Cache wxWidgets
id: cache-wx
sudo apt-get install git make gcc cmake libgtk-3-dev libjack-dev libasound2-dev
- name: Submoudle Cache Keys
run: |
echo "WXHASH=$(git submodule status wx | tr -d '[:blank:]')" >> $GITHUB_ENV
echo "PAHASH=$(git submodule status portaudio | tr -d '[:blank:]')" >> $GITHUB_ENV
- name: Cache Submodules
id: cache-sub
uses: actions/cache@v4
with:
path: |
wxlib/make
wx/include
key: wx-ubuntu-${{ env.WXHASH }}
portaudiolib/make
key: sub-ubuntu-${{ env.WXHASH }}-${{ env.PAHASH }}
# Cache needs the source include because wx-config does not reference the cmake --install
# directories, only the source build for some reason?
- name: Build wxWidgets
if: steps.cache-wx.outputs.cache-hit != 'true'
- name: Build Submodules
if: steps.cache-sub.outputs.cache-hit != 'true'
run: |
make wxlib
make portaudiolib
rm -rf wxlib/make/libs
# Remove libs folder to keep cache smaller. It's just temporary build data.
- name: Make
Expand All @@ -206,27 +234,39 @@ jobs:
uses: actions/checkout@v4
- name: Setup MacOS
run: brew install imagemagick
- name: wxWidgets Cache Key
run: echo "WXHASH=$(git submodule status wx | tr -d '[:blank:]')" >> $GITHUB_ENV
- name: Cache wxWidgets
id: cache-wx
- name: Submodule Cache Keys
run: |
echo "WXHASH=$(git submodule status wx | tr -d '[:blank:]')" >> $GITHUB_ENV
echo "PAHASH=$(git submodule status portaudio | tr -d '[:blank:]')" >> $GITHUB_ENV
- name: Cache Submodules
id: cache-sub
uses: actions/cache@v4
with:
path: |
wxlibArm/make
wxlibIntel/make
wx/include
key: wx-macos-${{ env.WXHASH }}
- name: Build wxWidgets
if: steps.cache-wx.outputs.cache-hit != 'true'
portaudiolib/makeArm
portaudiolib/makeIntel
key: sub-macos-${{ env.WXHASH }}-${{ env.PAHASH }}
- name: Build Submodules
if: steps.cache-sub.outputs.cache-hit != 'true'
run: |
export CC=clang
export WXOUT=wxlibArm
export WXCONF_EXTRA="-DCMAKE_OSX_ARCHITECTURES=arm64"
export PAOUT=portaudiolib/makeArm
export PACMAKE=../makeArm_cmake
export PACONF_EXTRA="-DCMAKE_OSX_ARCHITECTURES=arm64"
make wxlib
make portaudiolib
export WXOUT=wxlibIntel
export WXCONF_EXTRA="-DCMAKE_OSX_ARCHITECTURES=x86_64"
export PAOUT=portaudiolib/makeIntel
export PACMAKE=../makeIntel_cmake
export PACONF_EXTRA="-DCMAKE_OSX_ARCHITECTURES=x86_64"
make wxlib
make portaudiolib
#rm -rf wxlibArm/make/libs
#rm -rf wxlibIntel/make/libs
- name: Make
Expand All @@ -235,11 +275,13 @@ jobs:
export CXXFLAGS_EXTRA="-target arm64-apple-macos11 -std=c++11"
export LDFLAGS_EXTRA="-target arm64-apple-macos11"
export WXL_DIR=../wxlibArm
export PAL_DIR=../portaudiolib/makeArm
export OUTDIR=output/makeArm INTDIR=intermediate/makeArm
make cmd nsfplay
export CXXFLAGS_EXTRA="-target x86_64-apple-macos10.13 -std=c++11"
export LDFLAGS_EXTRA="-target x86_64-apple-macos10.13"
export WXL_DIR=../wxlibIntel
export PAL_DIR=../portaudiolib/makeIntel
export OUTDIR=output/makeIntel INTDIR=intermediate/makeIntel
make cmd nsfplay
- name: Make Fat App
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
intermediate
output
wxlib
portaudiolib
secrets
*.user
.vs
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = wx
url = https://github.com/wxWidgets/wxWidgets.git
shallow = true
[submodule "portaudio"]
path = portaudio
url = https://github.com/PortAudio/portaudio.git
shallow = true
9 changes: 9 additions & 0 deletions cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const char* platform_getenv(const char* name); // note: return only valid until
FILE* platform_fopen(const char* path, const char* mode);
int platform_nonblock_getc();

// sound output (sound.cpp)
const char* sound_error_text();
bool sound_setup();
void sound_shutdown();

// unit testing (unit_test.cpp)
int unit_test(const char* path);

Expand Down Expand Up @@ -434,6 +439,8 @@ int run()

// TODO the rest of this function is test code I am keeping as an example for later menus

//sound_setup();

// test of non blocking getc
printf("Q to quit...\n");
int kc = -1;
Expand All @@ -453,6 +460,8 @@ int run()
}
}

//sound_shutdown();

/*
// test info
printf("GROUPS:\n");
Expand Down
21 changes: 13 additions & 8 deletions cmd/cmd.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@
<PreprocessorDefinitions>DEBUG;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\include\;..\portaudiolib\vc32d\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(OutDir)nsfcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(OutDir)nsfcore.lib;portaudio.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\portaudiolib\vc32d\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -119,15 +120,16 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\include\;..\portaudiolib\vc32\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(OutDir)nsfcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(OutDir)nsfcore.lib;portaudio.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\portaudiolib\vc32\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -137,13 +139,14 @@
<PreprocessorDefinitions>DEBUG;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\include\;..\portaudiolib\vc64d\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(OutDir)nsfcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(OutDir)nsfcore.lib;portaudio.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\portaudiolib\vc64d\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -155,20 +158,22 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\include\;..\portaudiolib\vc64\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(OutDir)nsfcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(OutDir)nsfcore.lib;portaudio.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\portaudiolib\vc64\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="cmd.cpp" />
<ClCompile Include="platform.cpp" />
<ClCompile Include="sound.cpp" />
<ClCompile Include="unit_test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
1 change: 1 addition & 0 deletions cmd/cmd.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<ClCompile Include="cmd.cpp" />
<ClCompile Include="platform.cpp" />
<ClCompile Include="unit_test.cpp" />
<ClCompile Include="sound.cpp" />
</ItemGroup>
</Project>
16 changes: 15 additions & 1 deletion cmd/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@ DEPS = $(addprefix $(CMD_INTDIR)/,$(SRCS:.cpp=.d))
CORE = ../$(OUTDIR)/$(CORE_NAME)$(LIB_SUFFIX)
CXXFLAGS_ALL = $(CXXFLAGS) $(CXXFLAGS_EXTRA) $(INC_COMMON)
LDFLAGS_ALL = $(LDFLAGS) $(LDFLAGS_EXTRA) $(LDFLAGS_CMD)
LIBS =

# NOSOUND=1 builds with no audio output (WAV out only)

NOSOUND ?= 0

ifeq ($(NOSOUND),1)
CXXFLAGS_ALL += -DNSF_NOSOUND=1
else
CXXFLAGS_ALL += $(PAL_CXXFLAGS)
LIBS += $(PAL_LIBS)
endif

# target build

$(TARGET): $(OBJS) $(CORE) | $(dir $(TARGET))
$(CXX) -o $(TARGET) $(LDFLAGS_ALL) $(OBJS) $(CORE)
$(CXX) -o $(TARGET) $(LDFLAGS_ALL) $(OBJS) $(CORE) $(LIBS)
$(STRIP_DEBUG)

$(CMD_INTDIR)/%.d: %.cpp | $(CMD_INTDIR)/
Expand Down
Loading

0 comments on commit df74b47

Please sign in to comment.