Index of every page on this site: llms.txt
All skills
Run it yourself

Software Mansion's best practices for audio in React Native using react-native-audio-api. Covers audio playback (buffer sources, oscillators, streaming), recording (file, callback, graph), audio effects (gain, filters, delay, convolver, panner, waveshaper), real-time analysis and visualization, audio worklets (custom synthesis, UIRuntime/AudioRuntime), system integration (sessions, interruptions, permissions), and testing. Trigger on: react-native-audio-api, AudioContext, AudioRecorder, AudioBuffer, AudioBufferSourceNode, AudioBufferQueueSourceNode, OscillatorNode, StreamerNode, GainNode, BiquadFilterNode, DelayNode, ConvolverNode, StereoPannerNode, WaveShaperNode, AnalyserNode, AudioParam, AudioManager, PlaybackNotificationManager, RecordingNotificationManager, WorkletNode, WorkletSourceNode, WorkletProcessingNode, audio playback, record audio, microphone, waveform, audio visualization, audio streaming, audio worklet, or any React Native feature that captures, processes, or emits sound.

Use this Skill: https://skilld.dev/gh/software-mansion-labs/skills/audio

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

effects-and-analysis.md

≈2.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Audio Effects and Analysis

Patterns for building audio effect chains and analyzing audio data in React Native using react-native-audio-api.

For core concepts, see audio.md. For playback sources, see playback.md.


Effect Nodes Overview

Effect nodes transform audio passing through them. Chain them between source and destination:

source.connect(effectA);
effectA.connect(effectB);
effectB.connect(audioContext.destination);

All effect nodes are created from AudioContext (or BaseAudioContext) factory methods.


GainNode

Controls volume. The most commonly used effect node.

const gain = audioContext.createGain();
gain.gain.setValueAtTime(0.5, audioContext.currentTime); // 50% volume

source.connect(gain);
gain.connect(audioContext.destination);

Fade In / Fade Out

// Fade in over 2 seconds
gain.gain.setValueAtTime(0, audioContext.currentTime);
gain.gain.linearRampToValueAtTime(1, audioContext.currentTime + 2);

// Fade out over 0.5 seconds
gain.gain.setValueAtTime(1, audioContext.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.5);
gain.gain.setValueAtTime(0, audioContext.currentTime + 0.51);

Gotcha: exponentialRampToValueAtTime cannot reach 0. Ramp to a tiny value (0.001), then set to 0.

ADSR Envelope

Use GainNode to shape how a sound's volume changes over time. This is essential for musical instruments and sound design.

function playNoteWithEnvelope(
  audioContext: AudioContext,
  buffer: AudioBuffer,
  attack: number,
  decay: number,
  sustain: number,
  release: number
) {
  const source = audioContext.createBufferSource();
  const envelope = audioContext.createGain();
  const now = audioContext.currentTime;

  source.buffer = buffer;
  source.connect(envelope);
  envelope.connect(audioContext.destination);

  // Attack: silence → peak
  envelope.gain.setValueAtTime(0.001, now);
  envelope.gain.exponentialRampToValueAtTime(1.0, now + attack);

  // Decay: peak → sustain level
  envelope.gain.exponentialRampToValueAtTime(sustain, now + attack + decay);

  source.start(now);

  return {
    release: () => {
      const releaseStart = audioContext.currentTime;
      // Release: current → silence
      envelope.gain.setValueAtTime(envelope.gain.value, releaseStart);
      envelope.gain.exponentialRampToValueAtTime(0.001, releaseStart + release);
      envelope.gain.setValueAtTime(0, releaseStart + release + 0.01);
      source.stop(releaseStart + release + 0.02);
    },
  };
}

For GainNode API details, webfetch the GainNode docs.


BiquadFilterNode

Implements common audio filters: lowpass, highpass, bandpass, notch, allpass, peaking, lowshelf, highshelf.

const filter = audioContext.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.value = 1000; // cutoff frequency in Hz
filter.Q.value = 1.0;         // quality factor

source.connect(filter);
filter.connect(audioContext.destination);

Common Filter Types

Type Effect
lowpass Passes frequencies below cutoff, attenuates above
highpass Passes frequencies above cutoff, attenuates below
bandpass Passes a range around the center frequency
notch Rejects a narrow band around the center frequency
peaking Boosts/cuts around the center frequency (parametric EQ)
lowshelf Boosts/cuts all frequencies below the shelf frequency
highshelf Boosts/cuts all frequencies above the shelf frequency

For BiquadFilterNode API details, webfetch the BiquadFilterNode docs.


DelayNode

Delays the audio signal by a specified time.

const delay = audioContext.createDelay(5.0); // max delay time in seconds
delay.delayTime.value = 0.3; // 300ms delay

source.connect(delay);
delay.connect(audioContext.destination);

Echo Effect

Create a feedback loop with a gain node to produce echo:

const delay = audioContext.createDelay(1.0);
const feedback = audioContext.createGain();

delay.delayTime.value = 0.4;
feedback.gain.value = 0.5; // each echo is 50% quieter

source.connect(delay);
delay.connect(feedback);
feedback.connect(delay); // feedback loop
delay.connect(audioContext.destination);
source.connect(audioContext.destination); // dry signal

For DelayNode API details, webfetch the DelayNode docs.


ConvolverNode

Applies convolution reverb using an impulse response buffer. Great for adding room acoustics or spatial effects.

const convolver = audioContext.createConvolver();
convolver.buffer = impulseResponseBuffer; // an AudioBuffer with the IR

source.connect(convolver);
convolver.connect(audioContext.destination);

For ConvolverNode API details, webfetch the ConvolverNode docs.


StereoPannerNode

Positions audio in the stereo field.

const panner = audioContext.createStereoPanner();
panner.pan.value = -1; // full left (-1 to 1)

source.connect(panner);
panner.connect(audioContext.destination);

For StereoPannerNode API details, webfetch the StereoPannerNode docs.


WaveShaperNode

Applies non-linear distortion using a shaping curve.

const shaper = audioContext.createWaveShaper();
shaper.curve = makeDistortionCurve(400);
shaper.oversample = '4x'; // '2x' | '4x' | 'none'

source.connect(shaper);
shaper.connect(audioContext.destination);

For WaveShaperNode API details, webfetch the WaveShaperNode docs.


IIRFilterNode

Implements a general IIR (Infinite Impulse Response) filter when BiquadFilterNode types are insufficient.

const iir = audioContext.createIIRFilter(feedforward, feedback);

For IIRFilterNode API details, webfetch the IIRFilterNode docs.


AnalyserNode

Extracts time-domain and frequency-domain data from audio without modifying the signal. Essential for audio visualizations.

const analyser = audioContext.createAnalyser();
analyser.fftSize = 2048;           // power of 2, between 32 and 32768
analyser.smoothingTimeConstant = 0.8; // 0 (no smoothing) to 1 (heavy smoothing)

source.connect(analyser);
analyser.connect(audioContext.destination);

Extracting Data

// Frequency data (for spectrum visualizers, EQ displays)
const freqData = new Float32Array(analyser.frequencyBinCount);
analyser.getFloatFrequencyData(freqData); // values in dB

const freqBytes = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(freqBytes); // values 0-255

// Time-domain data (for waveform displays, oscilloscopes)
const timeData = new Float32Array(analyser.fftSize);
analyser.getFloatTimeDomainData(timeData); // values -1 to 1

const timeBytes = new Uint8Array(analyser.fftSize);
analyser.getByteTimeDomainData(timeBytes); // values 0-255 (127 = silence)

Properties

  • fftSize: Must be a power of 2 in [32, 32768]. Larger values give finer frequency resolution but more latency.
  • frequencyBinCount: Always fftSize / 2. Number of frequency data points.
  • minDecibels / maxDecibels: Range for byte frequency data mapping. Frequencies below minDecibels map to 0, above maxDecibels to 255.
  • smoothingTimeConstant: Averaging with previous frame. Higher = smoother transitions.

Audio Visualization with Reanimated

When passing audio data to Reanimated shared values for animation, mutate the existing typed array in place to avoid GC jank:

import { useSharedValue } from 'react-native-reanimated';

const FFT_SIZE = 256;
const amplitudes = useSharedValue(new Float32Array(FFT_SIZE / 2));

function updateVisualization() {
  const data = new Float32Array(analyser.frequencyBinCount);
  analyser.getFloatFrequencyData(data);

  amplitudes.modify((prev) => {
    for (let i = 0; i < prev.length; i++) {
      prev[i] = data[i];
    }
    return prev;
  });

  requestAnimationFrame(updateVisualization);
}

Why .modify()? Assigning amplitudes.value = new Float32Array(data) allocates and garbage-collects a new array at 60fps or higher, causing jank. .modify() mutates the existing allocation on the UI thread, skipping GC entirely.

Visualization with React State (Simple Approach)

For simpler visualizations where maximum performance is less critical:

const [freqs, setFreqs] = useState(new Uint8Array(FFT_SIZE / 2));

function draw() {
  const data = new Uint8Array(analyser.frequencyBinCount);
  analyser.getByteFrequencyData(data);
  setFreqs(data);
  requestAnimationFrame(draw);
}

This triggers React re-renders on every frame. For high-performance visualizations, prefer the Reanimated shared value approach above.


Building Effect Chains

Combine multiple effects in series:

const gain = audioContext.createGain();
const filter = audioContext.createBiquadFilter();
const delay = audioContext.createDelay(1.0);
const analyser = audioContext.createAnalyser();

// Source → filter → gain → delay → analyser → destination
source.connect(filter);
filter.connect(gain);
gain.connect(delay);
delay.connect(analyser);
analyser.connect(audioContext.destination);

Dry/Wet Mix

Route the original signal alongside the effected signal:

const dryGain = audioContext.createGain();
const wetGain = audioContext.createGain();

dryGain.gain.value = 0.7;
wetGain.gain.value = 0.3;

source.connect(dryGain);
source.connect(effect);
effect.connect(wetGain);

dryGain.connect(audioContext.destination);
wetGain.connect(audioContext.destination);

References

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides production-ready patterns and documentation for the react-native-audio-api by Software Mansion. It covers audio playback, recording, effects, and worklets. The skill is safe and follows best practices, though it is categorized as low severity due to the inherent attack surface associated with processing external audio data and microphone input, which is standard for audio-focused tools.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at 43cde80. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 8 months ago

README badge

README badge for software-mansion-labs/skills/audio