Skip to content

Commit a1d7a3e

Browse files
authored
Merge pull request #50 from ircam-ismm/feature/offline-context-suspend
Attempting to get OfflineAudioContext.suspend to work
2 parents babd5bd + df44e9f commit a1d7a3e

21 files changed

+332
-156
lines changed

.github/workflows/build.yml

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,51 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14+
clippy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Install Rust toolchain
18+
uses: dtolnay/rust-toolchain@stable
19+
with:
20+
toolchain: stable
21+
components: clippy
22+
23+
- name: Install ALSA and Jack dependencies
24+
run: |
25+
sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev
26+
27+
- name: Check out repository
28+
uses: actions/checkout@v3
29+
30+
- name: Generate Cargo.lock
31+
run: cargo generate-lockfile
32+
33+
- name: Clippy
34+
run: cargo clippy --all-features -- -D warnings
35+
1436
build:
37+
needs: clippy
1538
if: "!contains(github.event.head_commit.message, 'skip ci')"
1639
strategy:
1740
fail-fast: false
1841
matrix:
1942
settings:
2043
# ---------------------------------------------------------
21-
# MAC (ok)
44+
# MAC
2245
# ---------------------------------------------------------
46+
2347
# Intel
2448
- host: macos-latest
2549
target: x86_64-apple-darwin
2650
architecture: x64
2751
build: |
2852
yarn build
2953
strip -x *.node
54+
3055
# ARM
3156
- host: macos-latest
3257
architecture: x64
33-
target: 'aarch64-apple-darwin'
58+
target: aarch64-apple-darwin
3459
build: |
3560
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
3661
export CC=$(xcrun -f clang);
@@ -41,88 +66,90 @@ jobs:
4166
strip -x *.node
4267
4368
# ---------------------------------------------------------
44-
# WINDOWS (ok)
69+
# WINDOWS
4570
# ---------------------------------------------------------
71+
4672
# Intel 64
4773
- host: windows-latest
4874
build: yarn build
4975
target: x86_64-pc-windows-msvc
5076
architecture: x64
77+
5178
# ARM64
5279
- host: windows-latest
5380
architecture: x64
5481
target: aarch64-pc-windows-msvc
5582
build: yarn build --target aarch64-pc-windows-msvc
56-
# Intel 32
57-
# - host: windows-latest
58-
# build: |
59-
# yarn build --target i686-pc-windows-msvc
60-
# # yarn test
61-
# target: i686-pc-windows-msvc
62-
# architecture: x86
6383

6484
# ---------------------------------------------------------
65-
# Linux requires libasound-dev which is a mess to do remotely
85+
# Linux requires libasound2-dev which is a mess to do remotely
6686
# in particular for RPi, do it locally and workaround...
6787
# ---------------------------------------------------------
6888

6989
name: stable - ${{ matrix.settings.target }} - node@16
7090
runs-on: ${{ matrix.settings.host }}
7191
steps:
72-
- uses: actions/checkout@v2
92+
- uses: actions/checkout@v4
7393
- name: Setup node
74-
uses: actions/setup-node@v2
94+
uses: actions/setup-node@v4
7595
with:
7696
node-version: 16
7797
check-latest: true
7898
cache: yarn
7999
architecture: ${{ matrix.settings.architecture }}
80-
- name: Install
81-
uses: actions-rs/toolchain@v1
100+
101+
- name: Setup Rust toolchain
102+
uses: dtolnay/rust-toolchain@stable
82103
with:
83-
profile: minimal
84-
override: true
85104
toolchain: stable
86-
target: ${{ matrix.settings.target }}
105+
targets: ${{ matrix.settings.target }}
106+
87107
- name: Generate Cargo.lock
88-
uses: actions-rs/cargo@v1
89-
with:
90-
command: generate-lockfile
108+
run: cargo generate-lockfile
109+
91110
- name: Cache cargo registry
92-
uses: actions/cache@v2
111+
uses: actions/cache@v3
93112
with:
94113
path: ~/.cargo/registry
95114
key: ${{ matrix.settings.target }}-node@16-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
115+
96116
- name: Cache cargo index
97-
uses: actions/cache@v2
117+
uses: actions/cache@v3
98118
with:
99119
path: ~/.cargo/git
100120
key: ${{ matrix.settings.target }}-node@16-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
121+
101122
- name: Cache NPM dependencies
102-
uses: actions/cache@v2
123+
uses: actions/cache@v3
103124
with:
104125
path: node_modules
105126
key: npm-cache-${{ matrix.settings.target }}-node@16-${{ hashFiles('yarn.lock') }}
127+
106128
- name: Pull latest image
107129
run: ${{ matrix.settings.docker }}
108130
env:
109131
DOCKER_REGISTRY_URL: ghcr.io
110132
if: ${{ matrix.settings.docker }}
133+
111134
- name: Setup toolchain
112135
run: ${{ matrix.settings.setup }}
113136
if: ${{ matrix.settings.setup }}
114137
shell: bash
138+
115139
- name: Install dependencies
116140
run: yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
141+
117142
- name: Build
118143
run: ${{ matrix.settings.build }}
119144
shell: bash
145+
120146
- name: Upload artifact
121-
uses: actions/upload-artifact@v2
147+
uses: actions/upload-artifact@v3
122148
with:
123149
name: bindings-${{ matrix.settings.target }}
124150
path: ${{ env.APP_NAME }}.*.node
125151
if-no-files-found: error
152+
126153
# publish:
127154
# name: Publish
128155
# runs-on: ubuntu-latest
@@ -144,7 +171,7 @@ jobs:
144171
# check-latest: true
145172
# cache: yarn
146173
# - name: Cache NPM dependencies
147-
# uses: actions/cache@v2
174+
# uses: actions/cache@v3
148175
# with:
149176
# path: node_modules
150177
# key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ Cargo.lock
133133

134134
src-manual
135135
dummy.mjs
136+
137+
issues

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ src-manual
1616
target
1717
samples
1818
bin
19+
wpt
20+
tests
21+
issues
1922

2023
*.tgz
2124
*.bak

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.14.0 (06/12/2023)
2+
3+
- Update upstream create to [v0.38.0](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-0380-2023-12-03)
4+
- Implement AudioListener
5+
16
## v0.13.0 (08/11/2023)
27

38
- Update upstream crate to [v0.36.1](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-0361-2023-11-08)

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
authors = ["Benjamin Matuszewski <[email protected]>"]
33
edition = "2021"
44
name = "node-web-audio-api-rs"
5-
version = "0.13.0"
5+
version = "0.14.0"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[lib]
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
napi = {version="2.13", features=["napi6"]}
13+
napi = {version="2.13", features=["napi6", "tokio_rt"]}
1414
napi-derive = "2.13"
15-
web-audio-api = "0.38"
16-
# web-audio-api = { path = "../web-audio-api-rs" }
15+
# web-audio-api = "0.38"
16+
web-audio-api = { path = "../web-audio-api-rs" }
1717

1818
[target.'cfg(all(any(windows, unix), target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
1919
mimalloc = {version = "0.1"}
@@ -22,8 +22,8 @@ mimalloc = {version = "0.1"}
2222
napi-build = "1"
2323

2424
[profile.release]
25-
lto = "fat" # https://nnethercote.github.io/perf-book/build-configuration.html#link-time-optimization
26-
# debug = true
25+
lto = false
26+
debug = true
2727

2828
[features]
2929
jack = ["web-audio-api/cpal-jack"]

examples/offline.mjs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
import { AudioContext, OfflineAudioContext } from '../index.mjs';
22

3-
const offline = new OfflineAudioContext(1, 44100, 44100);
3+
const offline = new OfflineAudioContext(1, 48000, 48000);
44

5-
const osc = offline.createOscillator();
6-
osc.connect(offline.destination);
7-
osc.frequency.value = 220;
8-
osc.start(0);
9-
osc.stop(1);
5+
offline.suspend(128 / 48000).then(() => {
6+
console.log("suspend");
7+
8+
const osc = offline.createOscillator();
9+
osc.connect(offline.destination);
10+
osc.frequency.value = 220;
11+
osc.start(0);
12+
13+
console.log("resume");
14+
offline.resume();
15+
});
1016

1117
const buffer = await offline.startRendering();
18+
console.log("buffer duration:", buffer.duration);
19+
20+
// dirty check the audio buffer
21+
const channelData = buffer.getChannelData(0);
22+
23+
for (let i = 0; i < 48000; i++) {
24+
// before suspend the graph is empty
25+
if (i < 128) {
26+
if (channelData[i] !== 0) {
27+
throw new Error('should be zero')
28+
}
29+
// first sine sample is zero
30+
} else if (i === 128) {
31+
if (channelData[i] !== 0) {
32+
throw new Error('should be zero')
33+
}
34+
} else {
35+
// should ha ve a sine wave, hopefully without zero values :)
36+
if (channelData[i] === 0) {
37+
throw new Error(`should not be zero ${i}`);
38+
console.log(channelData[i])
39+
}
40+
}
41+
}
1242

1343
const latencyHint = process.env.WEB_AUDIO_LATENCY === 'playback' ? 'playback' : 'interactive';
1444
const online = new AudioContext({ latencyHint });
1545

1646
const src = online.createBufferSource();
47+
// src.loop = true;
1748
src.buffer = buffer;
49+
src.loop = true;
1850
src.connect(online.destination);
1951
src.start();
2052

21-
await new Promise(resolve => setTimeout(resolve, 1000));
53+
await new Promise(resolve => setTimeout(resolve, 2000));
2254

2355
await online.close();

0 commit comments

Comments
 (0)