Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/x-visualizer

oscilloscope, spectrogram, spectrum, waveform audio visualizers
https://github.com/stagas/x-visualizer

Last synced: 14 days ago
JSON representation

oscilloscope, spectrogram, spectrum, waveform audio visualizers

Awesome Lists containing this project

README

        


x-visualizer

Oscilloscope, spectrogram, spectrum, waveform audio visualizers.



npm i x-visualizer

pnpm add x-visualizer

yarn add x-visualizer

## Examples

# web

    # view source example/web.tsx

    ```tsx
    /** @jsxImportSource sigl */
    import $ from 'sigl'

    import { VisualizerElement } from 'x-visualizer'

    const ctx = new AudioContext({ sampleRate: 44100, latencyHint: 'playback' })

    interface AppElement extends $.Element {}

    @$.element()
    class AppElement extends HTMLElement {
    input?: AudioNode
    Visualizer = $.element(VisualizerElement)
    visualizer?: VisualizerElement
    mounted($: AppElement['$']) {
    $.render(({ Visualizer, input }) => (



    {/*css*/ `
    div {
    width: 300px;
    height: 150px;
    }
    `}



    ))
    }
    }

    const App = $.element(AppElement)

    const fetchAudioBuffer = async (audio: AudioContext, url: string) => {
    const res = await fetch(url)
    const arrayBuffer = await res.arrayBuffer()
    const audioBuffer = await audio.decodeAudioData(arrayBuffer)
    return audioBuffer
    }

    let playing = false
    let source: AudioBufferSourceNode
    const toggle = async () => {
    window.onclick = null
    if (playing) {
    ctx.suspend()
    playing = false
    console.log('stopped')
    return
    }

    ctx.resume()
    playing = true
    if (source) return

    const audioBuffer = await fetchAudioBuffer(
    ctx,
    './example/alpha_molecule.ogg'
    )
    source = ctx.createBufferSource()
    source.buffer = audioBuffer
    source.loop = true
    source.connect(ctx.destination)
    source.start(0, 33)

    // for (let i = 0; i < 1; i++) {
    $.render(, document.body)
    console.log('rendered')
    // }

    // const osc = ctx.createOscillator()
    // osc.frequency.value = 40
    // osc.type = 'sine'
    // osc.start()
    // osc.connect(analyser)

    // const noise = ctx.createScriptProcessor(512, 1, 1)
    // noise.onaudioprocess = e => {
    // const output = e.outputBuffer.getChannelData(0)
    // for (let i = 0; i < output.length; i++)
    // output[i] = Math.random() * 2 - 1
    // }
    // noise.connect(analyser)

    // spectrogram.current!.analyser = analyser
    console.log('playing')
    // setTimeout(() => {
    // analyser.fftSize = 16384 * 2
    // waveform.current!.analyser = null
    // waveform.current!.analyser = analyser
    // }, 1000)
    }

    // window.onclick = toggle
    toggle()
    ```


## API

# VisualizerElement src/x-visualizer.tsx#L16

} & __module & {

# Boolean src/work/stagas/sigl/dist/types/index.d.ts#L9


    undefined | boolean

# Number src/work/stagas/sigl/dist/types/index.d.ts#L8

    undefined | number

# String src/work/stagas/sigl/dist/types/index.d.ts#L7

    undefined | string

}, "transition">> # analyser  =  false src/x-visualizer.tsx#L68

    false | AnalyserNode

# autoResize  =  true src/x-visualizer.tsx#L31

    boolean

# background  =  '#123' src/x-visualizer.tsx#L32

    string

# color  =  '#1ff' src/x-visualizer.tsx#L33

    string

# context src/work/stagas/sigl/dist/types/sigl.d.ts#L26 # cycle  =  ... src/x-visualizer.tsx#L48

    Fn<[ ], void>

# disabled  =  false src/x-visualizer.tsx#L29

    boolean

# dispatch src/work/stagas/sigl/dist/types/events.d.ts#L4

    Dispatch<# (name, detail, init)

      # name


        Event | Narrow<K, string>

      # detail # init

        CustomEventInit<any>


      <K, E>(name, detail, init)  =>


        any

> # height  =  50 src/x-visualizer.tsx#L34

    number

# host src/work/stagas/sigl/dist/types/sigl.d.ts#L24 # input src/x-visualizer.tsx#L67

    null | AudioNode

# kind  =  ... src/x-visualizer.tsx#L28 # onmounted # onunmounted # oscilloscope src/x-visualizer.tsx#L43

    OscilloscopeElement

# spectrogram src/x-visualizer.tsx#L44

    SpectrogramElement

# spectrum src/x-visualizer.tsx#L45

    SpectrumElement

# visualizer src/x-visualizer.tsx#L38

    OscilloscopeElement | SpectrogramElement | SpectrumElement | WaveformElement

# waveform src/x-visualizer.tsx#L46

    WaveformElement

# width  =  150 src/x-visualizer.tsx#L35

    number

# visualizers  =  ... src/x-visualizer.tsx#L17

    {


    # oscilloscope  =  ...


      Component<OscilloscopeElement, HTMLElement>

    # spectrogram  =  ...

      Component<SpectrogramElement, HTMLElement>

    # spectrum  =  ...

      Component<SpectrumElement, HTMLElement>

    # waveform  =  ...

      Component<WaveformElement, HTMLElement>

    }
# kinds src/x-visualizer.tsx#L24
# created(ctx)

created(ctx)  =>

    void
# mounted($) src/x-visualizer.tsx#L70

mounted($)  =>

    void
# on(name)

    # name


    on<K>(name)  =>


# toJSON() # VisualizerKind src/x-visualizer.tsx#L11

    "oscilloscope" | "spectrogram" | "spectrum" | "waveform"

## Credits

- [everyday-utils](https://npmjs.org/package/everyday-utils) by [stagas](https://github.com/stagas) – Everyday utilities
- [sigl](https://npmjs.org/package/sigl) by [stagas](https://github.com/stagas) – Web framework
- [x-oscilloscope](https://npmjs.org/package/x-oscilloscope) by [stagas](https://github.com/stagas) – Audio oscilloscope visualizer Web Component
- [x-spectrogram](https://npmjs.org/package/x-spectrogram) by [stagas](https://github.com/stagas) – Audio spectrogram Web Component.
- [x-spectrum](https://npmjs.org/package/x-spectrum) by [stagas](https://github.com/stagas) – Audio spectrum analyser Web Component
- [x-waveform](https://npmjs.org/package/x-waveform) by [stagas](https://github.com/stagas) – Audio waveform visualizer Web Component

## Contributing

[Fork](https://github.com/stagas/x-visualizer/fork) or [edit](https://github.dev/stagas/x-visualizer) and submit a PR.

All contributions are welcome!

## License

MIT © 2022 [stagas](https://github.com/stagas)