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

Audio Library #30

Merged
merged 51 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2a98140
Started adding audio library
JohnDog3112 Aug 20, 2024
b70914a
Merge branch 'dev' into dev2
JohnDog3112 Aug 20, 2024
3db25cb
Working on implementing audio lib
JohnDog3112 Aug 22, 2024
3285635
Merge branch 'dev' into dev2
JohnDog3112 Aug 22, 2024
9443341
Merge branch 'dev' into dev2
JohnDog3112 Aug 23, 2024
a0dfd2c
Added Float32Array version of WASM memory buffer
JohnDog3112 Aug 26, 2024
36038f5
Added more audio API's
JohnDog3112 Aug 27, 2024
bcc0dc4
Merge branch 'dev' into dev2
JohnDog3112 Aug 27, 2024
0b675c7
Added twrGetAudioSamples
JohnDog3112 Aug 27, 2024
49e5a51
Reworked audio test cases
JohnDog3112 Aug 27, 2024
029e0d1
Added QuerySampleAudio test to tests-audio
JohnDog3112 Aug 28, 2024
98537bf
Added twrFreeAudioID and implemented it in the test cases
JohnDog3112 Aug 28, 2024
4238b18
Added QueryPlaybackLoadedAudio test
JohnDog3112 Aug 28, 2024
1f479c1
Added appendAudioSamples test
JohnDog3112 Aug 29, 2024
e3c475c
Added twrStopAudioPlayback
JohnDog3112 Aug 30, 2024
13896a6
Added volume and pan variations to twrPlayAudioNode
JohnDog3112 Aug 30, 2024
814c39d
Started adding synchrounous load audio
JohnDog3112 Sep 2, 2024
4137c4b
Missed a file in last commit
JohnDog3112 Sep 2, 2024
93e7c3f
Added synchronous load audio using callbacks/events
JohnDog3112 Sep 2, 2024
fc979f3
Made QueryPlaybackLoadedAudio and StopAudioPlaybackLoaded tests synch…
JohnDog3112 Sep 2, 2024
e2f421c
Switched tests-audio to use twrlibtimer
JohnDog3112 Sep 2, 2024
c2c79c0
Added test selection to tests-audio and made it so you can't run more…
JohnDog3112 Sep 2, 2024
1c96c77
Switched twrlibaudio to use decodeAudioData in favor of HTMLAudioElement
JohnDog3112 Sep 2, 2024
44fa14a
Added getMetadata to audio library
JohnDog3112 Sep 3, 2024
ca99897
Added playAudioRange to audiolib
JohnDog3112 Sep 3, 2024
9219720
Fixed minor issue with PlayAudioNodeRangeSampleRate test
JohnDog3112 Sep 3, 2024
9034221
Fixed tests-audio get_num_tests()
JohnDog3112 Sep 3, 2024
3783321
Added renamed twrPlayAudioNode and twrPlayAudioNodeRange to twrPlayPA…
JohnDog3112 Sep 3, 2024
4a77f40
Fixed typo in last commit
JohnDog3112 Sep 3, 2024
0e198e3
Made twrLibAudio function names more consistent
JohnDog3112 Sep 11, 2024
cf0a45c
Switched twrAudioGetSamples to use malloc instead of taking in a buffer
JohnDog3112 Sep 11, 2024
79fa17d
Added callback option to playAudioNode
JohnDog3112 Sep 11, 2024
9fa7a2a
renamed twrAudioLoadAsync to twrAudioLoadSync to better reflect what …
JohnDog3112 Sep 11, 2024
a44bac6
Added twrAudioPlaySync variants
JohnDog3112 Sep 11, 2024
1ec644e
Moved promise definition for internalAudioPlayRange
JohnDog3112 Sep 11, 2024
e427916
Added functions to change audio volume, pan, and sample_rate during p…
JohnDog3112 Sep 12, 2024
09de3aa
Changed twrAudio volume and pan arguments to take in doubles
JohnDog3112 Sep 12, 2024
c274aa5
Removed extra IWasmModule type union for async function
JohnDog3112 Sep 12, 2024
a2191ea
Changed twrAudioXXX to snake case: twr_audio_xxx
JohnDog3112 Sep 12, 2024
3431075
Added twrAudioReplaceSamples
JohnDog3112 Sep 12, 2024
a024dc3
Fixed type in import_name
JohnDog3112 Sep 13, 2024
feb404a
Merge remote-tracking branch 'upstream/dev' into dev2
JohnDog3112 Sep 18, 2024
3786b07
Updated audio library to latest dev
JohnDog3112 Sep 18, 2024
fd6cacb
Removed append and replace audio samples to simplify API
JohnDog3112 Sep 18, 2024
f426536
Added twrAudioPlayFile
JohnDog3112 Sep 19, 2024
7f0f8ad
Fixed some tests in tests-audio not working if they were the first te…
JohnDog3112 Sep 19, 2024
460fce6
Compacted twr_audio_play_range and twr_audio_play_range_sync function…
JohnDog3112 Sep 19, 2024
9aa5d28
Merge remote-tracking branch 'upstream/dev' into dev2
JohnDog3112 Sep 19, 2024
8b14ad0
Updated to latest dev
JohnDog3112 Sep 19, 2024
86c8a22
Added tests-audio to examples page and bundler
JohnDog3112 Sep 19, 2024
5cc81fc
Added functions to convert 8bit, 16bit, and 32bit PCM to the float st…
JohnDog3112 Sep 19, 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
4 changes: 4 additions & 0 deletions examples/buildall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ cd ../lib
$make clean
$make

cd ../tests-audio
$make clean
$make



2 changes: 2 additions & 0 deletions examples/buildbundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ cp multi-io/*.wasm dist/multi-io/
cp tests-d2d/*.wasm dist/tests-d2d
cp tests-d2d/*.jpg dist/tests-d2d
cp lib/*.wasm dist/lib/
cp tests-audio/*.wasm dist/tests-audio
cp tests-audio/*.mp3 dist/tests-audio
3 changes: 3 additions & 0 deletions examples/cleanall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ $make clean
cd ../tests-d2d
$make clean

cd ../tests-audio
$make clean

cd ..


Expand Down
5 changes: 5 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ <h1>WebAssembly C/C++ Examples<br>Using twr-wasm</h1>
<td>Unit tests for Draw 2D canvas console</td>
<td><a href="tests-d2d/index.html">run</a><br><a href="tests-d2d/index.html#async">run async</a></td>
</tr>
<tr>
<td>tests-audio</td>
<td>Unit tests for Audio Library. WARNING: Turn volume all the way down before running as some of the test sounds are very loud.</td>
<td><a href="tests-audio/index.html">run</a><br><a href="tests-audio/index.html#async">run async</a></td>
</tr>
</table>


Expand Down
32 changes: 32 additions & 0 deletions examples/tests-audio/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CC := clang
TWRCFLAGS := --target=wasm32 -nostdinc -nostdlib -isystem ../../include
CPPLIB := ../twr-cpp
CFLAGS := -c -Wall -O3 $(TWRCFLAGS) -I $(CPPLIB)
CFLAGS_DEBUG := -c -Wall -g -O0 $(TWRCFLAGS) -I $(CPPLIB)



.PHONY: default

default: tests-audio.wasm tests-audio-a.wasm clearIODiv.js

clearIODiv.js: index.html clearIODiv.ts
tsc

tests-audio.o: tests-audio.c
$(CC) $(CFLAGS) $< -o $@

tests-audio-a.o: tests-audio.c
$(CC) $(CFLAGS) $< -o $@ -DASYNC

tests-audio.wasm: tests-audio.o
wasm-ld tests-audio.o ../../lib-c/twr.a -o tests-audio.wasm \
--no-entry --initial-memory=4063232 --max-memory=4063232 \

tests-audio-a.wasm: tests-audio-a.o
wasm-ld tests-audio-a.o ../../lib-c/twr.a -o tests-audio-a.wasm \
--no-entry --shared-memory --no-check-features --initial-memory=4063232 --max-memory=4063232 \

clean:
rm -f *.o
rm -f *.wasm
29 changes: 29 additions & 0 deletions examples/tests-audio/clearIODiv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {IWasmModule, IWasmModuleAsync, twrLibrary, keyEventToCodePoint, TLibImports, twrLibraryInstanceRegistry} from "twr-wasm"

// Libraries use default export
export default class clearIODivLib extends twrLibrary {
id: number;

imports:TLibImports = {
clearIODiv: {},
};

// every library should have this line
libSourcePath = new URL(import.meta.url).pathname;

constructor() {
// all library constructors should start with these two lines
super();
this.id=twrLibraryInstanceRegistry.register(this);
}

clearIODiv(mod: IWasmModule|IWasmModuleAsync) {
const ioDiv = document.getElementById("twr_iodiv");
if (!ioDiv) throw new Error("clearIODiv couldn't find twr_iodiv!");

ioDiv.innerText = "";
}

}


Binary file added examples/tests-audio/croud.mp3
Binary file not shown.
81 changes: 81 additions & 0 deletions examples/tests-audio/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<title>Audio Tests</title>

<script type="importmap">
{
"imports": {
"twr-wasm": "../../lib-js/index.js"
}
}
</script>
</head>
<body>
<select id="test_select"></select>
<button id="test_button">Test</button>
<button id="test_all_button">Test All</button>
<div id="twr_iodiv"></div>
<canvas id="twr_d2dcanvas" width="600" height="600"></canvas>

<script type="module">
"use strict";
let test_select = document.getElementById("test_select");
let test_button = document.getElementById("test_button");
let test_all_button = document.getElementById("test_all_button");
let io = document.getElementById("twr_iodiv");

import {twrWasmModule, twrWasmModuleAsync} from "twr-wasm";
import clearIODivLib from "./out/clearIODiv.js";

// const timerLibInit = new timerLib();
const clearIODivLibInit = new clearIODivLib;

const is_async = window.location.hash=="#async";

const mod = is_async ? new twrWasmModuleAsync() : new twrWasmModule();
await mod.loadWasm(is_async ? "./tests-audio-a.wasm" : "./tests-audio.wasm");

const numTests = await mod.callC(["getNumTests"]);
console.log("tests: ", numTests);
for (let i = 0; i < numTests; i++) {
let option = document.createElement("OPTION");
const testName = mod.getString(await mod.callC(["getTestName", i]));
option.innerText = testName;
option.value = testName;
test_select.appendChild(option);
}

test_all_button.onclick = async () => {
await mod.callC(["testAll"]);
};

test_button.onclick = async () => {
await mod.callC(["testCase", test_select.selectedIndex]);
}

// const numTests = await mod.callC(["get_num_tests"])
// for (let i = 0; i < numTests; i++) {
// let option = document.createElement("OPTION");
// const testName = mod.getString(await mod.callC(["get_test_name", i]));
// option.innerText = testName;
// option.value = testName;
// test_select.appendChild(option);
// }

// await mod.callC(["test_all"]);

// test_all_button.onclick = async () => {
// io.innerHTML = "";
// await mod.callC(["test_all"]);
// };

// test_button.onclick = async () => {
// io.innerHTML = "";
// await mod.callC(["test_specific", test_select.selectedIndex]);
// }


</script>
</body>
</html>
9 changes: 9 additions & 0 deletions examples/tests-audio/out/clearIODiv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IWasmModule, IWasmModuleAsync, twrLibrary, TLibImports } from "twr-wasm";
export default class clearIODivLib extends twrLibrary {
id: number;
imports: TLibImports;
libSourcePath: string;
constructor();
clearIODiv(mod: IWasmModule | IWasmModuleAsync): void;
}
//# sourceMappingURL=clearIODiv.d.ts.map
6 changes: 6 additions & 0 deletions examples/tests-audio/out/timerLib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IWasmModule, IWasmModuleAsync, twrLibrary, TLibImports } from "twr-wasm";
export default class timerLib extends twrLibrary {
imports: TLibImports;
setTimeout(mod: IWasmModule | IWasmModuleAsync, eventID: number, time: number, args: number): void;
}
//# sourceMappingURL=timerLib.d.ts.map
11 changes: 11 additions & 0 deletions examples/tests-audio/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@parcel/resolver-default": {
"packageExports": true
},
"alias": {
"twr-wasm": "../../lib-js/index.js"
},
"dependencies": {
"twr-wasm": "^2.0.0"
}
}
Binary file added examples/tests-audio/ping.mp3
Binary file not shown.
Loading