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

bring v2.0-wip into develop #17

Merged
merged 38 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0decac4
split PGE and MiniAudio into their own compile units
Moros1138 Sep 20, 2024
8df9c57
gut demo and PGEX ... we're starting from scratch for v2.0
Moros1138 Sep 20, 2024
4e5e1b1
add device
Moros1138 Sep 20, 2024
c1df57d
config and init device
Moros1138 Sep 20, 2024
20f6d46
device configuration constants
Moros1138 Sep 20, 2024
7127059
add, config, and init resource manager
Moros1138 Sep 20, 2024
ba95e71
add, config, and init engine
Moros1138 Sep 20, 2024
bb374e9
add first version of data_callback
Moros1138 Sep 20, 2024
99cfbed
add OnBeforeUserUpdate
Moros1138 Sep 20, 2024
686ddb3
add SoundFileBuffer, Sound and implementations
Moros1138 Sep 21, 2024
0dbbd23
add miniaudio uninitialization to ~MiniAudio()
Moros1138 Sep 21, 2024
97761e0
add map of sound file buffers and vector of sounds
Moros1138 Sep 21, 2024
9bc1f9a
add LoadSound and supporting private functions
Moros1138 Sep 21, 2024
7e88a39
add UnloadSound
Moros1138 Sep 21, 2024
09ac3aa
add Play,Stop,Pause, and Toggle playback functions
Moros1138 Sep 21, 2024
bef3f0f
add one time playback function and supporting automatic unloader
Moros1138 Sep 21, 2024
c68196e
update README.md
Moros1138 Sep 21, 2024
256fd8a
fleshout documentation and update demo
Moros1138 Sep 21, 2024
0bae0eb
remove spellcheck from output textarea
Moros1138 Sep 21, 2024
3473073
add and implement control, seek, and expression functions
Moros1138 Sep 21, 2024
d8510f3
reorganize supporting structs
Moros1138 Sep 21, 2024
bf9ec3b
add and implement waveforms
Moros1138 Sep 21, 2024
48b2275
add and implement noise generators
Moros1138 Sep 21, 2024
a0aa3f7
stop engine and device in destructor
Moros1138 Sep 21, 2024
eb03dab
update documentation for noise generator
Moros1138 Sep 21, 2024
ce00354
desparation
Moros1138 Sep 21, 2024
0ceaade
stupid windows!!!
Moros1138 Sep 21, 2024
9ab1795
change up workflows
Moros1138 Sep 21, 2024
b0ac33f
restore HAS_TERMINAL option
Moros1138 Sep 21, 2024
6fdeedf
add test option to linux build
Moros1138 Sep 21, 2024
0ec7020
use test config for linux workflow
Moros1138 Sep 21, 2024
e651674
silence msvc warnings in demo.cpp build
Moros1138 Sep 21, 2024
3871759
try to force clang
Moros1138 Sep 21, 2024
2face2e
let's give this a try
Moros1138 Sep 21, 2024
277b002
try update alternatives to gcc-13 and g++13
Moros1138 Sep 21, 2024
f679abe
switch back to gcc
Moros1138 Sep 21, 2024
245e8f3
change to ubuntu-24.04
Moros1138 Sep 21, 2024
593a97a
install zlib and libpng
Moros1138 Sep 21, 2024
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
83 changes: 83 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build

on:
pull_request:
branches:
- develop
- main

jobs:
emscripten:
name: Emscripten
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up Python (required for Emscripten)
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install Emscripten SDK
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
shell: bash

- name: Build
run: |
source emsdk/emsdk_env.sh
emcmake cmake . -B emscripten-build
cmake --build emscripten-build --config=Release
shell: bash

ubuntu:
name: Ubuntu
runs-on: ubuntu-24.04

steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Install zlib and libpng without interaction
run: |
sudo apt-get update
sudo apt-get install -y zlib1g-dev libpng-dev

- name: Set default gcc and g++ versions to latest
run: |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100

- name: Build
env:
CC: gcc
CXX: g++
run: |
cmake . -B build -DTEST=1
cmake --build build
shell: bash

windows:
name: Windows
runs-on: windows-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Build
run: |
cmake . -B build
cmake --build build


Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
- name: Build with Emscripten
run: |
source emsdk/emsdk_env.sh
emcmake cmake . -B emscripten-build
cmake --build emscripten-build --config=Release
emcmake cmake . -B emscripten-build -DCMAKE_BUILD_TYPE:String=Debug
cmake --build emscripten-build --config Debug
shell: bash

- name: Deploy Main Demo
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/emscripten-build.yml

This file was deleted.

34 changes: 23 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.10)

project(olcPGEX_MiniAudio)

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

if (UPDATE_GIT_SUBMODULES)
message(STATUS "Updating Git submodules...")
Expand Down Expand Up @@ -152,17 +155,23 @@ function(add_common_settings target)
######################################################################
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)

if (TEST)
target_compile_definitions(${target} PRIVATE -DOLC_PGE_HEADLESS)
endif()

# OpenGL
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
if (NOT TEST)
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)

# X11
find_package(X11 REQUIRED)
target_link_libraries(${target} X11::X11)
# X11
find_package(X11 REQUIRED)
target_link_libraries(${target} X11::X11)

include_directories(${X11_INCLUDE_DIRS})
include_directories(${X11_INCLUDE_DIRS})
endif()

# Threads
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -228,7 +237,8 @@ endfunction()
add_executable(
demo
demo/demo.cpp
demo/common.cpp
demo/olcPGEX_MiniAudio.cpp
demo/olcPixelGameEngine.cpp
olcPGEX_MiniAudio.h
third_party/olcPixelGameEngine/olcPixelGameEngine.h
third_party/miniaudio/miniaudio.h
Expand All @@ -237,7 +247,8 @@ add_executable(
add_executable(
demo_synthesis
demo/demo_synthesis.cpp
demo/common.cpp
demo/olcPGEX_MiniAudio.cpp
demo/olcPixelGameEngine.cpp
olcPGEX_MiniAudio.h
third_party/olcPixelGameEngine/olcPixelGameEngine.h
third_party/miniaudio/miniaudio.h
Expand All @@ -246,7 +257,8 @@ add_executable(
add_executable(
demo_waveform
demo/demo_waveform.cpp
demo/common.cpp
demo/olcPGEX_MiniAudio.cpp
demo/olcPixelGameEngine.cpp
olcPGEX_MiniAudio.h
third_party/olcPixelGameEngine/olcPixelGameEngine.h
third_party/miniaudio/miniaudio.h
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Cross-Platform, out-of-the-box. Easily use in your Linux, Windows, MacOS, and Em
### Loading Features
* Loads WAV files
* Loads MP3 files
* Use ``olc::ResourcePack`` (as of v2.0)

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

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

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

*** Advanced Features, for those who want to use more of miniaudio
### Advanced Features, for those who want to use more of miniaudio
* Get a pointer to the ma_device
* Get a pointer to the ma_engine
* Get a pointer to the ma_resource_manager (as of v2.0)
* Get pointers to waveforms and sounds

# Usage
Expand Down
76 changes: 48 additions & 28 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ class Demo : public olc::PixelGameEngine
}

public:

bool OnUserCreate() override
{
// Load a sample from a file, currently decodes WAV and MP3
// files, out-of-the-box without further coding or configuration.
// returns a sample ID (int), for future control calls.
/**
* load a sample from a file. currently decodes WAV and MP3
* files without further coding or configuration.
*
* returns a sample ID (int), for control and expression calls.
*/
song1 = ma.LoadSound("assets/sounds/song1.mp3");

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

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

if(GetKey(olc::SPACE).bPressed)
{
// Toggle takes a sample ID (int) and either starts playback or pauses playback
// depending on whether the sample is currently playing, or not.
/**
* Toggle takes a sample ID (int) and either
* starts playback or pauses playback depending
* on whether the sample is currently playing or not.
*/
ma.Toggle(song1);
}

Expand Down Expand Up @@ -84,33 +91,46 @@ class Demo : public olc::PixelGameEngine
distance = 0.0f;
}

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

// Set pan, takes a sample ID (int), and a float
// -1.0 to 1.0 where 0 is center
pan = std::clamp(pan, -1.0f, 1.0f);

/**
* SetPan takes a sample ID (int) and a float
* -1.0f to 1.0f where 0 is center.
*/
pan = std::clamp(pan, -1.0f, 1.0f);
ma.SetPan(song1, pan);

// Set pitch, takes a sample ID (int), and a float
// 1.0 is normal pitch
/**
* SetPitch takes a sample ID (int) and a float
* 1.0f is normal pitch.
*/
pitch = std::clamp(pitch, 0.0f, 2.0f);
ma.SetPitch(song1, pitch);

// Set volume, takes a sample ID (int), and a float
// 0.0 to 1.0 where 1.0 is full volume
/**
* SetVolume takes a sample ID (int) and a float
* 0.0f to 1.0f where 1.0f is full volume.
*/
volume = std::clamp(volume, 0.0f, 1.0f);
ma.SetVolume(song1, volume);

// Gets the current playback position in the provided sample ID (int),
// returns float 0.0 to 1.0, nearer 1.0 is near the end
/**
* GetCursorFloat takes a sample ID (int) and returns
* a float 0.0f to 1.0f, nearer to 1.0f is nearer the end.
*/
seek = ma.GetCursorFloat(song1);

// Gets the current playback position in the provided sample ID (int),
// returns unsigned long long in milliseconds
cursor=ma.GetCursorMilliseconds(song1);
/**
* GetCursorMilliseconds takes a sample ID (int) and returns
* the current playback position, in milliseconds.
*/
cursor = ma.GetCursorMilliseconds(song1);

// Draw Instructions and Indicators
Clear(olc::BLACK);
Expand All @@ -129,7 +149,7 @@ class Demo : public olc::PixelGameEngine
"\n"
"Distance <" + std::to_string(distance) + "> Left, Right\n"
"\n"
"One-Off Sounds <" + std::to_string(ma.GetOneOffSounds().size()) + "> S\n" \
"One-Off Sounds <" + std::to_string(ma.GetOneOffCount()) + "> S\n" \
"\n" \
"BackgroundPlay <" + ((backgroundPlay) ? "On": "Off") + "> K1\n",
olc::WHITE, {0.5f, 0.5f});
Expand Down Expand Up @@ -173,7 +193,7 @@ class Demo : public olc::PixelGameEngine
float volume = 1.0f;
float distance = 0.0f;
bool backgroundPlay = false;
unsigned long long cursor = 0ull;
ma_uint64 cursor = 0ull;

};

Expand Down
2 changes: 2 additions & 0 deletions demo/olcPGEX_MiniAudio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"
3 changes: 0 additions & 3 deletions demo/common.cpp → demo/olcPixelGameEngine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"
Loading