Namby Pamby Magicians

    @soundworks/service-audio-buffer-loader

    0.0.1-alpha.0 • Public • Published

    @soundworks/service-checkin

    soundworks service dedicated at loading audio files and related JSON data, retrieving AudioBuffers

    Install

    npm install --save @soundworks/service-audio-buffer-loader

    Usage

    client

    registering the service

    // index.js
    import { Client } from '@soundworks/core/client';
    import serviceAudioBufferLoaderFactory from '@soundworks/service-audio-buffer-loader/client';
    
    const client = new Client();
    client.registerService('audio-buffer-loader', serviceAudioBufferLoaderFactory, {
      data: {
        audioFile: 'sounds/my-audio-file.mp3',
        relatedData: 'sounds/my-audio-file.json'
      }
    }, []);

    requiring the service

    // MyExperience.js
    import { Experience } from '@soundworks/core/client';
    
    class MyExperience extends Experience {
      constructor() {
        super();
        this.audioBufferLoader = this.require('audio-buffer-loader');
      }
    
      async start() {
        const buffer = this.audioBufferLoader.data.audioFile;
        const relatedData = this.audioBufferLoader.data.relatedData;
    
        // ...
        const newData = await this.audioBufferLoader.load({
          otherFile: 'sounds/other-file.wav',
        });
      }
    }

    options

    • data: description of the data to be loaded, can be any POJO, in each url pointing to a .wav, .mp3 or .json file will be replaced by the corresponding AudioBuffer or data object.
    • assetsDomain: prefix to be added to all urls

    server

    registering the service

    // index.js
    import { Server } from '@soundworks/core/server';
    import serviceAudioBufferLoaderFactory from '@soundworks/service-audio-buffer-loader/server';
    
    const server = new Server();
    server.registerService('audio-buffer-loader', serviceAudioBufferLoaderFactory, {}, []);

    requiring the service

    // MyExperience.js
    import { Experience } from '@soundworks/core/server';
    
    class MyExperience extends Experience {
      constructor() {
        super();
        this.audioBufferLoader = this.require('audio-buffer-loader');
      }
    }

    options

    License

    BSD-3-Clause

    Keywords

    none

    Install

    npm i @soundworks/service-audio-buffer-loader

    DownloadsWeekly Downloads

    2

    Version

    0.0.1-alpha.0

    License

    BSD-3-Clause

    Unpacked Size

    13.7 kB

    Total Files

    7

    Last publish

    Collaborators

    • b-ma