Skip to content

Commit

Permalink
feat: switch to exporting a factory method to gen the soundtouchnode
Browse files Browse the repository at this point in the history
BREAKING CHANGE: no longer exports SoundTouchNode directly
  • Loading branch information
cutterbl committed May 1, 2020
1 parent 13fd08b commit 13056c2
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 527 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,19 @@ const setupContext = function () {
};
```

The [AudioContext](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) [audioWorklet.addModule()](https://developer.mozilla.org/en-US/docs/Web/API/Worklet/addModule) method returns a Promise. The path
passed to this method is the path to the SoundTouchWorklet, available
from the build `dist/soundtouch-worklet.js`. Pathing to this file is
important, and your server must include a 'Content-Type' header of
`text/javascript` or `application/javascript` for the file to
run properly.
The [AudioContext](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) [audioWorklet.addModule()](https://developer.mozilla.org/en-US/docs/Web/API/Worklet/addModule) method returns a Promise. The path passed to this method is the path to the SoundTouchWorklet, available from the build `@soundtouchjs/audio-worklet/dist/soundtouch-worklet.js`. Pathing to this file is important, and your server must include a 'Content-Type' header of `text/javascript` or `application/javascript` for the file to run properly.

_**[NOTE]**: If you are using a bundler (webpack, rollup, etc) to
bundle your app, you may require a special 'loader' for worklets/
web workers._

## Setting Up the AudioWorkletNode (SoundTouchNode)

Once you have setup your worklet, and retrieved your raw (undecoded)
file for processing, you can now setup your SoundTouchNode.
Once you have setup your worklet, and retrieved your raw (undecoded) file for processing, you now need to create an instance of the SoundTouchNode. We provide a factory method for this, so that you can use polyfilled/ponyfilled WebAudio API classes if necessary.

```js
//top of the file
import { SoundTouchNode } from '@soundtouchjs/audio-context';
import createSoundTouchNode from '@soundtouchjs/audio-context';
//... and later

// called from our `loadSource()` method, after we've retrieved the
Expand All @@ -58,7 +52,7 @@ const setupSoundtouch = function () {
if (soundtouch) {
soundtouch.off();
}
soundtouch = new SoundTouchNode(audioCtx, buffer);
soundtouch = createSoundTouchNode(audioCtx, AudioWorkletNode, buffer);
soundtouch.on('initialized', onInitialized);
};
```
Expand Down
3 changes: 1 addition & 2 deletions configs/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/external-helpers"]
"presets": ["@babel/preset-env"]
}
12 changes: 10 additions & 2 deletions public/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
*/

// This is pulling SoundTouchJS from the local file system. See the README for proper usage.
import SoundTouchNode from './js/soundtouch-audio-node.js';
import createSoundTouchNode from './js/soundtouch-audio-node.js';

/**
* https://github.com/chrisguttandin/standardized-audio-context
* To see this working with the standaridized-audio-context ponyfill,
* uncomment these two lines
*/
//import sac from 'https://dev.jspm.io/npm:standardized-audio-context';
//const { AudioContext, AudioWorkletNode } = sac;

const loadBtn = document.getElementById('load');
const playBtn = document.getElementById('play');
Expand Down Expand Up @@ -92,7 +100,7 @@ const setupSoundtouch = function () {
if (soundtouch) {
soundtouch.off();
}
soundtouch = new SoundTouchNode(audioCtx, buffer);
soundtouch = createSoundTouchNode(audioCtx, AudioWorkletNode, buffer);
soundtouch.on('initialized', onInitialized);
};

Expand Down
6 changes: 3 additions & 3 deletions scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pkg from '../package.json';

export default [
{
input: path.join(__dirname, '../src/SoundTouchNode.js'),
input: path.join(__dirname, '../src/createSoundTouchNode.js'),
output: [
{
file: pkg.module,
Expand Down Expand Up @@ -35,7 +35,7 @@ export default [
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/\n`,
sourcemap: true,
sourcemap: false,
exports: 'named',
},
],
Expand All @@ -46,7 +46,7 @@ export default [
}),
eslint(),
babel({
babelHelpers: 'external',
babelHelpers: 'bundled',
configFile: path.resolve(__dirname, '../configs/babel.config.json'),
}),
cleanup(),
Expand Down

0 comments on commit 13056c2

Please sign in to comment.