Skip to content

Commit ffa9332

Browse files
authored
Merge pull request #17 from Moros1138/v2.0-work-in-progress
bring v2.0-wip into develop
2 parents 9a64c88 + 593a97a commit ffa9332

10 files changed

+832
-478
lines changed

.github/workflows/build.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
- main
8+
9+
jobs:
10+
emscripten:
11+
name: Emscripten
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout source code
16+
uses: actions/checkout@v4
17+
with:
18+
submodules: 'recursive'
19+
20+
- name: Set up Python (required for Emscripten)
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.x'
24+
25+
- name: Install Emscripten SDK
26+
run: |
27+
git clone https://github.com/emscripten-core/emsdk.git
28+
cd emsdk
29+
./emsdk install latest
30+
./emsdk activate latest
31+
source ./emsdk_env.sh
32+
shell: bash
33+
34+
- name: Build
35+
run: |
36+
source emsdk/emsdk_env.sh
37+
emcmake cmake . -B emscripten-build
38+
cmake --build emscripten-build --config=Release
39+
shell: bash
40+
41+
ubuntu:
42+
name: Ubuntu
43+
runs-on: ubuntu-24.04
44+
45+
steps:
46+
- name: Checkout source code
47+
uses: actions/checkout@v4
48+
with:
49+
submodules: 'recursive'
50+
51+
- name: Install zlib and libpng without interaction
52+
run: |
53+
sudo apt-get update
54+
sudo apt-get install -y zlib1g-dev libpng-dev
55+
56+
- name: Set default gcc and g++ versions to latest
57+
run: |
58+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100
59+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
60+
61+
- name: Build
62+
env:
63+
CC: gcc
64+
CXX: g++
65+
run: |
66+
cmake . -B build -DTEST=1
67+
cmake --build build
68+
shell: bash
69+
70+
windows:
71+
name: Windows
72+
runs-on: windows-latest
73+
steps:
74+
- name: Checkout source code
75+
uses: actions/checkout@v4
76+
with:
77+
submodules: 'recursive'
78+
- name: Build
79+
run: |
80+
cmake . -B build
81+
cmake --build build
82+
83+

.github/workflows/emscripten-deploy.yml .github/workflows/deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
- name: Build with Emscripten
3333
run: |
3434
source emsdk/emsdk_env.sh
35-
emcmake cmake . -B emscripten-build
36-
cmake --build emscripten-build --config=Release
35+
emcmake cmake . -B emscripten-build -DCMAKE_BUILD_TYPE:String=Debug
36+
cmake --build emscripten-build --config Debug
3737
shell: bash
3838

3939
- name: Deploy Main Demo

.github/workflows/emscripten-build.yml

-41
This file was deleted.

CMakeLists.txt

+23-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.10)
33

44
project(olcPGEX_MiniAudio)
55

6+
# Options you can set via command-line
7+
option(HAS_TERMINAL "Show a terminal window for STDOUT/STDERR" ON)
68
option(UPDATE_GIT_SUBMODULES "Update Git submodules" ON)
9+
option(TEST "Build In Test Mode" OFF)
710

811
if (UPDATE_GIT_SUBMODULES)
912
message(STATUS "Updating Git submodules...")
@@ -152,17 +155,23 @@ function(add_common_settings target)
152155
######################################################################
153156
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
154157

158+
if (TEST)
159+
target_compile_definitions(${target} PRIVATE -DOLC_PGE_HEADLESS)
160+
endif()
161+
155162
# OpenGL
156-
set(OpenGL_GL_PREFERENCE LEGACY)
157-
find_package(OpenGL REQUIRED)
158-
include_directories(${OpenGL_INCLUDE_DIRS})
159-
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
163+
if (NOT TEST)
164+
set(OpenGL_GL_PREFERENCE LEGACY)
165+
find_package(OpenGL REQUIRED)
166+
include_directories(${OpenGL_INCLUDE_DIRS})
167+
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
160168

161-
# X11
162-
find_package(X11 REQUIRED)
163-
target_link_libraries(${target} X11::X11)
169+
# X11
170+
find_package(X11 REQUIRED)
171+
target_link_libraries(${target} X11::X11)
164172

165-
include_directories(${X11_INCLUDE_DIRS})
173+
include_directories(${X11_INCLUDE_DIRS})
174+
endif()
166175

167176
# Threads
168177
find_package(Threads REQUIRED)
@@ -228,7 +237,8 @@ endfunction()
228237
add_executable(
229238
demo
230239
demo/demo.cpp
231-
demo/common.cpp
240+
demo/olcPGEX_MiniAudio.cpp
241+
demo/olcPixelGameEngine.cpp
232242
olcPGEX_MiniAudio.h
233243
third_party/olcPixelGameEngine/olcPixelGameEngine.h
234244
third_party/miniaudio/miniaudio.h
@@ -237,7 +247,8 @@ add_executable(
237247
add_executable(
238248
demo_synthesis
239249
demo/demo_synthesis.cpp
240-
demo/common.cpp
250+
demo/olcPGEX_MiniAudio.cpp
251+
demo/olcPixelGameEngine.cpp
241252
olcPGEX_MiniAudio.h
242253
third_party/olcPixelGameEngine/olcPixelGameEngine.h
243254
third_party/miniaudio/miniaudio.h
@@ -246,7 +257,8 @@ add_executable(
246257
add_executable(
247258
demo_waveform
248259
demo/demo_waveform.cpp
249-
demo/common.cpp
260+
demo/olcPGEX_MiniAudio.cpp
261+
demo/olcPixelGameEngine.cpp
250262
olcPGEX_MiniAudio.h
251263
third_party/olcPixelGameEngine/olcPixelGameEngine.h
252264
third_party/miniaudio/miniaudio.h

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Cross-Platform, out-of-the-box. Easily use in your Linux, Windows, MacOS, and Em
2626
### Loading Features
2727
* Loads WAV files
2828
* Loads MP3 files
29+
* Use ``olc::ResourcePack`` (as of v2.0)
2930

3031
### Configuration Features
3132
* Background Playback
@@ -50,19 +51,20 @@ Cross-Platform, out-of-the-box. Easily use in your Linux, Windows, MacOS, and Em
5051
* Get the current position in the sample, in milliseconds.
5152
* Get the current position in the sample, as float 0.0f is start, 1.0f is end.
5253

53-
### Waveform Features
54+
### Waveform Features (as of v1.7)
5455
* Create sine, square, sawtooth, and triangle waves.
5556
* Load and play multiple waveform channels at the same time.
5657
* Modify waveform amplitudes, frequencies, and types in realtime.
5758

58-
### Noise Generation Features
59+
### Noise Generation Features (as of v1.7)
5960
* Set a callback function to send and play raw audio data for potential sound synthesis.
6061
* Send raw data for both left and right stereo channels.
6162
* Track passage of audio frame time for oscillators / time-sensitive applications.
6263

63-
*** Advanced Features, for those who want to use more of miniaudio
64+
### Advanced Features, for those who want to use more of miniaudio
6465
* Get a pointer to the ma_device
6566
* Get a pointer to the ma_engine
67+
* Get a pointer to the ma_resource_manager (as of v2.0)
6668
* Get pointers to waveforms and sounds
6769

6870
# Usage

demo/demo.cpp

+48-28
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ class Demo : public olc::PixelGameEngine
1212
}
1313

1414
public:
15-
1615
bool OnUserCreate() override
1716
{
18-
// Load a sample from a file, currently decodes WAV and MP3
19-
// files, out-of-the-box without further coding or configuration.
20-
// returns a sample ID (int), for future control calls.
17+
/**
18+
* load a sample from a file. currently decodes WAV and MP3
19+
* files without further coding or configuration.
20+
*
21+
* returns a sample ID (int), for control and expression calls.
22+
*/
2123
song1 = ma.LoadSound("assets/sounds/song1.mp3");
2224

23-
// This is here to demonstrate how the adventurous can exploit other features of miniaudio
24-
// that hasn't been abstracted by the PGEX.
25-
//
26-
// see how we get a pointer of the song1 sound?
27-
ma_sound_set_position(ma.GetSounds()[song1], 0.0f, 0.0f, 0.0f);
28-
std::cout << "This demo was built with the latest workflow.\n";
25+
/**
26+
* this is here to demonstrate how the adventurous can
27+
* exploit other features of miniaudio that hasn't been
28+
* abstracted by the PGEX
29+
*
30+
* Here you get a pointer to a sample's ma_sound.
31+
*/
32+
ma_sound_set_position(ma.GetSound(song1), 0.0f, 0.0f, 0.0f);
2933
return true;
3034
}
3135

@@ -46,8 +50,11 @@ class Demo : public olc::PixelGameEngine
4650

4751
if(GetKey(olc::SPACE).bPressed)
4852
{
49-
// Toggle takes a sample ID (int) and either starts playback or pauses playback
50-
// depending on whether the sample is currently playing, or not.
53+
/**
54+
* Toggle takes a sample ID (int) and either
55+
* starts playback or pauses playback depending
56+
* on whether the sample is currently playing or not.
57+
*/
5158
ma.Toggle(song1);
5259
}
5360

@@ -84,33 +91,46 @@ class Demo : public olc::PixelGameEngine
8491
distance = 0.0f;
8592
}
8693

87-
// This is here to demonstrate how the adventurous can exploit other features of miniaudio
88-
// that hasn't been abstracted by the PGEX.
94+
/**
95+
* this is here to demosntrate how the adventurous can exploit other
96+
* features of miniaudio that haven't been abstracted by the PGEX.
97+
*/
8998
distance = std::clamp(distance, 0.0f, 100.0f);
9099
ma_engine_listener_set_position(ma.GetEngine(), 0, 0.0f, distance, 0.0f);
91100

92-
// Set pan, takes a sample ID (int), and a float
93-
// -1.0 to 1.0 where 0 is center
94-
pan = std::clamp(pan, -1.0f, 1.0f);
101+
102+
/**
103+
* SetPan takes a sample ID (int) and a float
104+
* -1.0f to 1.0f where 0 is center.
105+
*/
106+
pan = std::clamp(pan, -1.0f, 1.0f);
95107
ma.SetPan(song1, pan);
96108

97-
// Set pitch, takes a sample ID (int), and a float
98-
// 1.0 is normal pitch
109+
/**
110+
* SetPitch takes a sample ID (int) and a float
111+
* 1.0f is normal pitch.
112+
*/
99113
pitch = std::clamp(pitch, 0.0f, 2.0f);
100114
ma.SetPitch(song1, pitch);
101115

102-
// Set volume, takes a sample ID (int), and a float
103-
// 0.0 to 1.0 where 1.0 is full volume
116+
/**
117+
* SetVolume takes a sample ID (int) and a float
118+
* 0.0f to 1.0f where 1.0f is full volume.
119+
*/
104120
volume = std::clamp(volume, 0.0f, 1.0f);
105121
ma.SetVolume(song1, volume);
106122

107-
// Gets the current playback position in the provided sample ID (int),
108-
// returns float 0.0 to 1.0, nearer 1.0 is near the end
123+
/**
124+
* GetCursorFloat takes a sample ID (int) and returns
125+
* a float 0.0f to 1.0f, nearer to 1.0f is nearer the end.
126+
*/
109127
seek = ma.GetCursorFloat(song1);
110128

111-
// Gets the current playback position in the provided sample ID (int),
112-
// returns unsigned long long in milliseconds
113-
cursor=ma.GetCursorMilliseconds(song1);
129+
/**
130+
* GetCursorMilliseconds takes a sample ID (int) and returns
131+
* the current playback position, in milliseconds.
132+
*/
133+
cursor = ma.GetCursorMilliseconds(song1);
114134

115135
// Draw Instructions and Indicators
116136
Clear(olc::BLACK);
@@ -129,7 +149,7 @@ class Demo : public olc::PixelGameEngine
129149
"\n"
130150
"Distance <" + std::to_string(distance) + "> Left, Right\n"
131151
"\n"
132-
"One-Off Sounds <" + std::to_string(ma.GetOneOffSounds().size()) + "> S\n" \
152+
"One-Off Sounds <" + std::to_string(ma.GetOneOffCount()) + "> S\n" \
133153
"\n" \
134154
"BackgroundPlay <" + ((backgroundPlay) ? "On": "Off") + "> K1\n",
135155
olc::WHITE, {0.5f, 0.5f});
@@ -173,7 +193,7 @@ class Demo : public olc::PixelGameEngine
173193
float volume = 1.0f;
174194
float distance = 0.0f;
175195
bool backgroundPlay = false;
176-
unsigned long long cursor = 0ull;
196+
ma_uint64 cursor = 0ull;
177197

178198
};
179199

demo/olcPGEX_MiniAudio.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define OLC_PGEX_MINIAUDIO
2+
#include "olcPGEX_MiniAudio.h"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
#define OLC_PGE_APPLICATION
22
#include "olcPixelGameEngine.h"
3-
4-
#define OLC_PGEX_MINIAUDIO
5-
#include "olcPGEX_MiniAudio.h"

0 commit comments

Comments
 (0)