Skip to content

Commit

Permalink
Merge pull request #42 from ccrma/dev
Browse files Browse the repository at this point in the history
WebChucK v1.2.8
  • Loading branch information
terryzfeng authored Jul 25, 2024
2 parents de1ffc9 + ba643d7 commit 618fee8
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 25 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
# remote_user: ${{ secrets.SSH_USER }}
# remote_key: ${{ secrets.DEPLOY_KEY }}

# - name: Deploy dist to dev
# if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
# uses: burnett01/[email protected]
# with:
# switches: -avzr --delete --exclude=node_modules
# path: ./
# remote_path: ${{ secrets.DEV_WC_LOCATION }}
# remote_host: ${{ secrets.HOST }}
# remote_user: ${{ secrets.SSH_USER }}
# remote_key: ${{ secrets.DEPLOY_KEY }}
- name: Deploy dist to dev
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
uses: burnett01/[email protected]
with:
switches: -avzr --delete --exclude=node_modules
path: ./
remote_path: ${{ secrets.DEV_WC_LOCATION }}
remote_host: ${{ secrets.DEV_HOST }}
remote_user: ${{ secrets.DEV_SSH_USER }}
remote_key: ${{ secrets.DEV_DEPLOY_KEY }}
4 changes: 2 additions & 2 deletions dist/Chuck.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Chuck extends window.AudioWorkletNode {
* @example
* ```ts
* // Initialize ChucK with a list of files to preload
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.ck", virtualFilename: "filename.ck" }...]);
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.wav", virtualFilename: "filename.wav" }...]);
* ```
*
* @example
Expand All @@ -52,7 +52,7 @@ export default class Chuck extends window.AudioWorkletNode {
* theChuck = await Chuck.init([], undefined, undefined, "./src");
* ```
*
* @param filenamesToPreload Array of Files to preload into ChucK's filesystem `[{serverFilename: "./path/filename", virtualFilename: "filename"}...]`
* @param filenamesToPreload Array of auxiliary files to preload into ChucK's filesystem. These can be .wav files, .ck files, .etc. `[{serverFilename: "./path/filename.wav", virtualFilename: "filename.wav"}...]`
* @param audioContext Optional parameter if you want to use your own AudioContext. **Note**: If an AudioContext is passed in, you will need to connect the ChucK instance to your own destination.
* @param numOutChannels Optional custom number of output channels. Default is 2 channel stereo and the Web Audio API supports up to 32 channels.
* @param whereIsChuck Optional custom url to your WebChucK `src` folder containing `webchuck.js` and `webchuck.wasm`. By default, `whereIsChuck` is {@link https://chuck.stanford.edu/webchuck/src | here}.
Expand Down
5 changes: 3 additions & 2 deletions dist/Chuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Chuck extends window.AudioWorkletNode {
* @example
* ```ts
* // Initialize ChucK with a list of files to preload
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.ck", virtualFilename: "filename.ck" }...]);
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.wav", virtualFilename: "filename.wav" }...]);
* ```
*
* @example
Expand All @@ -82,7 +82,7 @@ export default class Chuck extends window.AudioWorkletNode {
* theChuck = await Chuck.init([], undefined, undefined, "./src");
* ```
*
* @param filenamesToPreload Array of Files to preload into ChucK's filesystem `[{serverFilename: "./path/filename", virtualFilename: "filename"}...]`
* @param filenamesToPreload Array of auxiliary files to preload into ChucK's filesystem. These can be .wav files, .ck files, .etc. `[{serverFilename: "./path/filename.wav", virtualFilename: "filename.wav"}...]`
* @param audioContext Optional parameter if you want to use your own AudioContext. **Note**: If an AudioContext is passed in, you will need to connect the ChucK instance to your own destination.
* @param numOutChannels Optional custom number of output channels. Default is 2 channel stereo and the Web Audio API supports up to 32 channels.
* @param whereIsChuck Optional custom url to your WebChucK `src` folder containing `webchuck.js` and `webchuck.wasm`. By default, `whereIsChuck` is {@link https://chuck.stanford.edu/webchuck/src | here}.
Expand All @@ -108,6 +108,7 @@ export default class Chuck extends window.AudioWorkletNode {
if (defaultAudioContext) {
chuck.connect(audioContext.destination); // default connection source
}
audioContext.destination.channelCount = numOutChannels;
await chuck.isReady.promise;
return chuck;
}
Expand Down
67 changes: 61 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<!-- Highlight.js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>

<!-- JSZip -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js" integrity="sha512-XMVd28F1oH/O71fzwBnV7HucLxVwtxf26XV8P4wPk26EDxuGZ91N8bsOttmnomcCD3CS5ZMRL50H0GgOHvegtg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>

<body>
Expand Down Expand Up @@ -216,14 +219,66 @@ <h4>NPM</h4>
1::second => now;
`);</code></pre>
</div>
<p>Note that many browsers do not let audio run without a user
interaction (e.g. button press). You can check for a suspended audio
context and resume like this:</p>
<p>Note that many browsers do not let audio run until there has been user
interaction (e.g. button press).</p>
<div>

<h4>Download Source</h4>
<p>Download ready-to-use compiled <a href="#" id="downloadZip">WebChucK source files</a> (JS + WASM) as a zip.</p>
<button type="button" class="btn btn-warning btn-md px-2 me-sm-3" id="downloadZipButton">Download</button>
<p>Unzip the file and place the entire <code>webchuck</code> directory into your project.</p>
<div>
<pre><code>if (theChuck.context.state === 'suspended') {
theChuck.context.resume();
}</code></pre>
<pre><code>// Import the webchuck bundle from `webchuck` directory
import { Chuck } from './webchuck/wc-bundle.js'

// Set src path to './webchuck/'
const theChuck = await Chuck.init([], undefined, undefined, './webchuck/');
</code></pre>
</div>
<script>
async function downloadSrc(event) {
event.preventDefault();

const zip = new JSZip();

const fileUrls = [
'./src/wc-bundle.js',
'./src/webchuck.js',
'./src/webchuck.wasm'
];

// Fetch each file and add it to the zip
for (const url of fileUrls) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch ${url}`);
}
if (url.endsWith(".js")) {
const content = await response.text();
zip.file(url.split('/').pop(), content);
} else {
const content = await response.arrayBuffer();
zip.file(url.split('/').pop(), content, { binary: true });
}
}

// Generate the zip file and trigger the download
zip.generateAsync({ type: 'blob' }).then(function(content) {
const a = document.createElement('a');
a.href = URL.createObjectURL(content);
a.download = 'webchuck.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}).catch(function(err) {
console.error('Failed to generate zip', err);
});
}

document.getElementById('downloadZip').addEventListener('click', downloadSrc);
document.getElementById('downloadZipButton').addEventListener('click', downloadSrc);
</script>
<p>Note: All files must be served in order for WebChucK to run locally.</p>

<h2 id="documentation">Documentation</h2>
<p>Getting Started Documentation Guide: <a href="./docs">here</a> </p>
Expand Down
5 changes: 3 additions & 2 deletions src/Chuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class Chuck extends window.AudioWorkletNode {
* @example
* ```ts
* // Initialize ChucK with a list of files to preload
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.ck", virtualFilename: "filename.ck" }...]);
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.wav", virtualFilename: "filename.wav" }...]);
* ```
*
* @example
Expand All @@ -102,7 +102,7 @@ export default class Chuck extends window.AudioWorkletNode {
* theChuck = await Chuck.init([], undefined, undefined, "./src");
* ```
*
* @param filenamesToPreload Array of Files to preload into ChucK's filesystem `[{serverFilename: "./path/filename", virtualFilename: "filename"}...]`
* @param filenamesToPreload Array of auxiliary files to preload into ChucK's filesystem. These can be .wav files, .ck files, .etc. `[{serverFilename: "./path/filename.wav", virtualFilename: "filename.wav"}...]`
* @param audioContext Optional parameter if you want to use your own AudioContext. **Note**: If an AudioContext is passed in, you will need to connect the ChucK instance to your own destination.
* @param numOutChannels Optional custom number of output channels. Default is 2 channel stereo and the Web Audio API supports up to 32 channels.
* @param whereIsChuck Optional custom url to your WebChucK `src` folder containing `webchuck.js` and `webchuck.wasm`. By default, `whereIsChuck` is {@link https://chuck.stanford.edu/webchuck/src | here}.
Expand Down Expand Up @@ -139,6 +139,7 @@ export default class Chuck extends window.AudioWorkletNode {
if (defaultAudioContext) {
chuck.connect(audioContext.destination); // default connection source
}
audioContext.destination.channelCount = numOutChannels;

await chuck.isReady.promise;
return chuck;
Expand Down
5 changes: 3 additions & 2 deletions src/wc-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Chuck extends window.AudioWorkletNode {
* @example
* ```ts
* // Initialize ChucK with a list of files to preload
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.ck", virtualFilename: "filename.ck" }...]);
* theChuck = await Chuck.init([{ serverFilename: "./path/filename.wav", virtualFilename: "filename.wav" }...]);
* ```
*
* @example
Expand All @@ -244,7 +244,7 @@ class Chuck extends window.AudioWorkletNode {
* theChuck = await Chuck.init([], undefined, undefined, "./src");
* ```
*
* @param filenamesToPreload Array of Files to preload into ChucK's filesystem `[{serverFilename: "./path/filename", virtualFilename: "filename"}...]`
* @param filenamesToPreload Array of auxiliary files to preload into ChucK's filesystem. These can be .wav files, .ck files, .etc. `[{serverFilename: "./path/filename.wav", virtualFilename: "filename.wav"}...]`
* @param audioContext Optional parameter if you want to use your own AudioContext. **Note**: If an AudioContext is passed in, you will need to connect the ChucK instance to your own destination.
* @param numOutChannels Optional custom number of output channels. Default is 2 channel stereo and the Web Audio API supports up to 32 channels.
* @param whereIsChuck Optional custom url to your WebChucK `src` folder containing `webchuck.js` and `webchuck.wasm`. By default, `whereIsChuck` is {@link https://chuck.stanford.edu/webchuck/src | here}.
Expand All @@ -270,6 +270,7 @@ class Chuck extends window.AudioWorkletNode {
if (defaultAudioContext) {
chuck.connect(audioContext.destination); // default connection source
}
audioContext.destination.channelCount = numOutChannels;
await chuck.isReady.promise;
return chuck;
}
Expand Down
2 changes: 1 addition & 1 deletion src/webchuck.js

Large diffs are not rendered by default.

Binary file modified src/webchuck.wasm
Binary file not shown.
Binary file modified test/testFiles/ABSaturator.chug.wasm
Binary file not shown.

0 comments on commit 618fee8

Please sign in to comment.