npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-audio-engine

v0.0.6

Published

Engine to assemble Web Audio graphs using React

Downloads

5

Readme

React Audio Engine

Integração de React com Web Audio API.

:warning: Versionamento

Durante a versão 0.x.x, todas as breaking changes serão tratadas como minor e as demais mudanças como patch. A partir da versão 1.0.0, o versionamento seguirá normalmente seguindo a documentação em https://semver.org/.

Instalação

NPM: https://www.npmjs.com/package/react-audio-engine

Desenvolvimento

Setup

pnpm install

Demo

pnpm start:dev

Especificação

Stage

Raiz da árvore de áudio. Todas as cenas de áudio devem estar contidas em um Stage.

import { ATOM, ReactATOM, Scene } from 'react-audio-engine'

const stage = new ATOM.Stage();

ReactATOM.render(<Scene {...props} />, stage);

Scene

Responsável pela criação e gerenciamento dos contextos de áudio. Todos os demais módulos devem estar contidos em uma cena.

import { Scene, Track, Gain, BufferSource } from 'react-audio-engine'

function MyScene(props: { masterGain: number, buffer: ArrayBuffer }) {
  return (
    <Scene sampleRate={88200} latencyHint={Scene.LatencyCategory.PLAYBACK}>
      <Track>
        <BufferSource buffer={props.buffer}>
        <Gain level={props.masterGain}/>
      </Track>
    </Scene>
  )
}

Record

Semelhante à Scene, mas renderiza o áudio em memória o mais rapidamente possível.

import { Scene, Record, Track } from 'react-audio-engine'

function MyScene(props: { tracks: Track.Props[]; isSaving: boolean }) {
  const RecordOrScene = isSaving ? Record : Scene;

  return (
    <RecordOrScene>
      {props.tracks.map(<Track {...props}>...</Track>)}
    </RecordOrScene>
  );
}

Element

Responsável por renderizar os nós de áudio nativos. É uma classe abstrata cujo comportamento é implementado por todos os nós de áudio.

Os nós que concretizam Element são:

Track

Conduz o sinal de áudio serialmente atráves dos módulos filhos. Sua entrada é a entrada do primeiro módulo filho e sua saída é a saída do último módulo filho.


Mixer

Combina o sinal de áudio paralelamente através dos módulos filhos. Sua a entrada é a combinação das entradas dos módulos filhos e sua saída é a combinação da saída dos módulos filhos.


Branch

Ramifica o sinal de áudio em um fluxo serial alternativo através dos módulos filhos cujo destino diverge do fluxo original (tendo BaseAudioContext.destination como destino se não fornecido explicitamente). É o comportamento implementado por todos os elementos.

Helpers

AudioView

Componente utilizado para facilitar a renderização de elementos de GUI e WebAudio de forma unificada, compartilhando o estado entre o áudio e a view. Possui dois métodos abstratos:

  • renderAudio: utilizado para renderizar os elementos de áudio.
  • renderView: utilizado para renderizar os elementos de GUI.

Se fornecido um stage via contexto, o componente usará o mesmo para renderizar o áudio. Senão, um stage será criado.

import React from 'react'
import ReactDOM from 'react-dom'
import { ATOM, AudioView, Scene } from 'react-audio-engine'

type Props = {}

interface State {
  sampleRate: number
}

class AppAudioView extends AudioView<Props, State> {
  renderAudio() {
    return (
      <Scene sampleRate={this.state.sampleRate}>
        ...
      </Scene>
    )
  }

  renderView() {
    return (
      <input
        value={this.state.sampleRate}
        onChange={event => this.setState({ sampleRate: Number(event.target.value) })}
      />
    )
  }
}

const stage = new ATOM.stage()
const root = document.getElementById('root')

ReactDOM.render(
  <AudioView.Context.Provider value={stage}>
    <AppAudioView/>
  </AudioView.Context.Provider>,
  root
)