https://github.com/stagas/x-oscilloscope
Audio oscilloscope visualizer Web Component.
https://github.com/stagas/x-oscilloscope
custom-element dsp oscilloscope ui visualizer web-component webaudio
Last synced: 8 months ago
JSON representation
Audio oscilloscope visualizer Web Component.
- Host: GitHub
- URL: https://github.com/stagas/x-oscilloscope
- Owner: stagas
- License: mit
- Created: 2022-03-26T18:56:33.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-01T14:25:44.000Z (almost 4 years ago)
- Last Synced: 2025-03-25T11:21:47.759Z (over 1 year ago)
- Topics: custom-element, dsp, oscilloscope, ui, visualizer, web-component, webaudio
- Language: TypeScript
- Homepage:
- Size: 6.8 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
x-oscilloscope
Audio oscilloscope visualizer Web Component
npm i x-oscilloscope
pnpm add x-oscilloscope
yarn add x-oscilloscope
## Examples
# web
Try it live
#view source example/web.ts
```ts
import { fetchAudioBuffer } from 'webaudio-tools'
import { OscilloscopeElement } from 'x-oscilloscope'
customElements.define('x-oscilloscope', OscilloscopeElement)
document.body.innerHTML = `
`
const ctx = new AudioContext({ sampleRate: 44100, latencyHint: 0.08 })
const analyser = ctx.createAnalyser()
analyser.fftSize = 8192
analyser.smoothingTimeConstant = 0
analyser.maxDecibels = 0
analyser.minDecibels = -100
// @ts-ignore
const url = new URL('alpha_molecule.ogg', import.meta.url).toString()
fetchAudioBuffer(ctx, url).then(audioBuffer => {
const source = ctx.createBufferSource()
source.buffer = audioBuffer
source.loop = true
source.connect(ctx.destination)
source.start(0, 83)
source.connect(analyser)
;(document.querySelector('x-oscilloscope') as OscilloscopeElement).analyser =
analyser
})
window.onclick = () => ctx.state !== 'running' ? ctx.resume() : ctx.suspend()
if (ctx.state !== 'running')
document.body.appendChild(new Text('click to start/stop'))
// requestAnimationFrame <- for shoty
```
## API
# OscilloscopeElement src/x-oscilloscope.tsx#L10
# constructor()
# new OscilloscopeElement()
$ src/work/stagas/sigl/dist/types/sigl.d.ts#L25 Context<OscilloscopeElement & JsxContext<OscilloscopeElement> & Omit<{
# ctor
Class<T>
<T>(ctor) =>
CleanClass<T>
ctx <T>(ctx) =>
Wrapper<T>
# 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">> # Plot = ... src/x-oscilloscope.tsx#L20 Component<PlotElement, HTMLElement>
analyser src/x-oscilloscope.tsx#L18 AnalyserNode
analyserData src/x-oscilloscope.tsx#L19 Float32Array
autoResize = true src/x-oscilloscope.tsx#L11 boolean
background = '#123' src/x-oscilloscope.tsx#L14 string
color = '#1ff' src/x-oscilloscope.tsx#L15 string
context src/work/stagas/sigl/dist/types/sigl.d.ts#L26 ContextClass<OscilloscopeElement & JsxContext<OscilloscopeElement> & Omit<{
# ctor
Class<T>
<T>(ctor) =>
CleanClass<T>
ctx <T>(ctx) =>
Wrapper<T>
# 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">> dispatch src/work/stagas/sigl/dist/types/events.d.ts#L4 Dispatch<# (name, detail, init)
divider = 1 src/x-oscilloscope.tsx#L16 number
draw src/x-oscilloscope.tsx#L23 # ()
() =>
- void
height = 50 src/x-oscilloscope.tsx#L13 number
host src/work/stagas/sigl/dist/types/sigl.d.ts#L24 # loop src/x-oscilloscope.tsx#L24 {
# start()
start() =>
- void
stop()
stop() =>
- void
onmounted EventHandler<OscilloscopeElement, CustomEvent<any>>
onunmounted EventHandler<OscilloscopeElement, CustomEvent<any>>
plotData = ... src/x-oscilloscope.tsx#L21 Float32Array
stabilizer = ... src/x-oscilloscope.tsx#L22 Stabilizer
width = 150 src/x-oscilloscope.tsx#L12 number
created(ctx) # ctx
Context<OscilloscopeElement & JsxContext<OscilloscopeElement> & Omit<{
# ctor
Class<T>
<T>(ctor) =>
CleanClass<T>
ctx <T>(ctx) =>
Wrapper<T>
# 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">> created(ctx) =>
- void
mounted($) src/x-oscilloscope.tsx#L41 # $
Context<OscilloscopeElement & JsxContext<OscilloscopeElement> & Omit<{
# ctor
Class<T>
<T>(ctor) =>
CleanClass<T>
ctx <T>(ctx) =>
Wrapper<T>
# 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">> mounted($) =>
- void
on(name) # name
on<K>(name) =>
On<Fn<[ EventHandler<OscilloscopeElement, LifecycleEvents & object [K]> ], Off>>
start() – Start displaying the spectrum. src/x-oscilloscope.tsx#L31
start() =>
- void
stop() – Stop displaying the spectrum. src/x-oscilloscope.tsx#L37
stop() =>
- void
toJSON()
toJSON() =>
Pick<OscilloscopeElement, keyof OscilloscopeElement>
## Credits
- [sigl](https://npmjs.org/package/sigl) by [stagas](https://github.com/stagas) – Web framework
- [x-plot](https://npmjs.org/package/x-plot) by [stagas](https://github.com/stagas) – A Web Component that plots zoomable and pannable waveforms.
## Contributing
[Fork](https://github.com/stagas/x-oscilloscope/fork) or [edit](https://github.dev/stagas/x-oscilloscope) and submit a PR.
All contributions are welcome!
## License
MIT © 2022 [stagas](https://github.com/stagas)