Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 53 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,51 @@ on:
workflow_dispatch:

jobs:
clippy:
runs-on: ubuntu-latest
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy

- name: Install ALSA and Jack dependencies
run: |
sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev

- name: Check out repository
uses: actions/checkout@v3

- name: Generate Cargo.lock
run: cargo generate-lockfile

- name: Clippy
run: cargo clippy --all-features -- -D warnings

build:
needs: clippy
if: "!contains(github.event.head_commit.message, 'skip ci')"
strategy:
fail-fast: false
matrix:
settings:
# ---------------------------------------------------------
# MAC (ok)
# MAC
# ---------------------------------------------------------

# Intel
- host: macos-latest
target: x86_64-apple-darwin
architecture: x64
build: |
yarn build
strip -x *.node

# ARM
- host: macos-latest
architecture: x64
target: 'aarch64-apple-darwin'
target: aarch64-apple-darwin
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
export CC=$(xcrun -f clang);
Expand All @@ -41,88 +66,90 @@ jobs:
strip -x *.node

# ---------------------------------------------------------
# WINDOWS (ok)
# WINDOWS
# ---------------------------------------------------------

# Intel 64
- host: windows-latest
build: yarn build
target: x86_64-pc-windows-msvc
architecture: x64

# ARM64
- host: windows-latest
architecture: x64
target: aarch64-pc-windows-msvc
build: yarn build --target aarch64-pc-windows-msvc
# Intel 32
# - host: windows-latest
# build: |
# yarn build --target i686-pc-windows-msvc
# # yarn test
# target: i686-pc-windows-msvc
# architecture: x86

# ---------------------------------------------------------
# Linux requires libasound-dev which is a mess to do remotely
# Linux requires libasound2-dev which is a mess to do remotely
# in particular for RPi, do it locally and workaround...
# ---------------------------------------------------------

name: stable - ${{ matrix.settings.target }} - node@16
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 16
check-latest: true
cache: yarn
architecture: ${{ matrix.settings.architecture }}
- name: Install
uses: actions-rs/toolchain@v1

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
override: true
toolchain: stable
target: ${{ matrix.settings.target }}
targets: ${{ matrix.settings.target }}

- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
with:
command: generate-lockfile
run: cargo generate-lockfile

- name: Cache cargo registry
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ matrix.settings.target }}-node@16-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ matrix.settings.target }}-node@16-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache NPM dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: node_modules
key: npm-cache-${{ matrix.settings.target }}-node@16-${{ hashFiles('yarn.lock') }}

- name: Pull latest image
run: ${{ matrix.settings.docker }}
env:
DOCKER_REGISTRY_URL: ghcr.io
if: ${{ matrix.settings.docker }}

- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
shell: bash

- name: Install dependencies
run: yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000

- name: Build
run: ${{ matrix.settings.build }}
shell: bash

- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: ${{ env.APP_NAME }}.*.node
if-no-files-found: error

# publish:
# name: Publish
# runs-on: ubuntu-latest
Expand All @@ -144,7 +171,7 @@ jobs:
# check-latest: true
# cache: yarn
# - name: Cache NPM dependencies
# uses: actions/cache@v2
# uses: actions/cache@v3
# with:
# path: node_modules
# key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@ Cargo.lock

src-manual
dummy.mjs

issues
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ src-manual
target
samples
bin
wpt
tests
issues

*.tgz
*.bak
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.14.0 (06/12/2023)

- Update upstream create to [v0.38.0](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-0380-2023-12-03)
- Implement AudioListener

## v0.13.0 (08/11/2023)

- Update upstream crate to [v0.36.1](https://github.com/orottier/web-audio-api-rs/blob/main/CHANGELOG.md#version-0361-2023-11-08)
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
authors = ["Benjamin Matuszewski <[email protected]>"]
edition = "2021"
name = "node-web-audio-api-rs"
version = "0.13.0"
version = "0.14.0"

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

[lib]
crate-type = ["cdylib"]

[dependencies]
napi = {version="2.13", features=["napi6"]}
napi = {version="2.13", features=["napi6", "tokio_rt"]}
napi-derive = "2.13"
web-audio-api = "0.38"
# web-audio-api = { path = "../web-audio-api-rs" }
# web-audio-api = "0.38"
web-audio-api = { path = "../web-audio-api-rs" }

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

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

[features]
jack = ["web-audio-api/cpal-jack"]
46 changes: 39 additions & 7 deletions examples/offline.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
import { AudioContext, OfflineAudioContext } from '../index.mjs';

const offline = new OfflineAudioContext(1, 44100, 44100);
const offline = new OfflineAudioContext(1, 48000, 48000);

const osc = offline.createOscillator();
osc.connect(offline.destination);
osc.frequency.value = 220;
osc.start(0);
osc.stop(1);
offline.suspend(128 / 48000).then(() => {
console.log("suspend");

const osc = offline.createOscillator();
osc.connect(offline.destination);
osc.frequency.value = 220;
osc.start(0);

console.log("resume");
offline.resume();
});

const buffer = await offline.startRendering();
console.log("buffer duration:", buffer.duration);

// dirty check the audio buffer
const channelData = buffer.getChannelData(0);

for (let i = 0; i < 48000; i++) {
// before suspend the graph is empty
if (i < 128) {
if (channelData[i] !== 0) {
throw new Error('should be zero')
}
// first sine sample is zero
} else if (i === 128) {
if (channelData[i] !== 0) {
throw new Error('should be zero')
}
} else {
// should ha ve a sine wave, hopefully without zero values :)
if (channelData[i] === 0) {
throw new Error(`should not be zero ${i}`);
console.log(channelData[i])
}
}
}

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

const src = online.createBufferSource();
// src.loop = true;
src.buffer = buffer;
src.loop = true;
src.connect(online.destination);
src.start();

await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise(resolve => setTimeout(resolve, 2000));

await online.close();
Loading