Published
Edited
Jul 15, 2021
1 fork
2 stars
Insert cell
md`# Spiral Waveform`
Insert cell
viewof audioFile = fileInput({
initialUrl: await FileAttachment("frere-jacque.mp3").url()
})
Insert cell
audioFile
Insert cell
Insert cell
audiobuffer.getChannelData(0).length
Insert cell
Insert cell
step = Math.floor(audiobuffer.getChannelData(0).length / nbSamples);
Insert cell
Insert cell
nonZeroIndex = rawSamples.findIndex(d => d !==0)
Insert cell
nonZeroIndexEnd = [...rawSamples].reverse().findIndex(d => d !==0)
Insert cell
samples = rawSamples.slice(nonZeroIndex, rawSamples.length -22).map(d => Math.abs(d))
Insert cell
transform = (numbers) => {
return Math.sqrt(Math.abs(numbers))
}
Insert cell
Insert cell
Insert cell
width=1200
Insert cell
viewof nbWindow = slider({
title: 'number of windows',
value: 10,
step: 10,
min: 10,
max: 100,
})
Insert cell
import {movingAverage} from "@d3/moving-average"
Insert cell
values = movingAverage(samples,nbWindow)
Insert cell
Insert cell
Insert cell
samples
Insert cell
md`## Utils`
Insert cell
lineRadial = d3.lineRadial()
.defined(d => !isNaN(d))
.angle((d,i) => xRadial(i))
.radius((d,i) => yRadial(i) + yScale(d))
Insert cell
areaRadial = d3.areaRadial()
.defined(d => !isNaN(d))
.angle((d,i) => xRadial(i))
.innerRadius((d,i) => yRadial(i) - yScale(d))
.outerRadius((d,i) => yRadial(i) + yScale(d))
// .radius((d,i) => yRadial(i) + yScale(d))
Insert cell
xRadial = d3.scaleLinear()
.domain([0, samples.length])
.range([0, 2 * Math.PI * nbSpirals])
Insert cell
yRadial = d3.scaleLinear()
.domain([0, samples.length])
.range([width/4, (width - margin * 2)/2])
Insert cell
yScale = d3.scaleLinear()
.domain(d3.extent(values))
.range([0, 40])
Insert cell
viewof margin = slider({
title: 'margin',
value: 10,
step: 4,
min: 0,
max: 40
})
Insert cell
audioContext = new (window.AudioContext || window.webkitAudioContext)();
Insert cell
md`## Libraries`
Insert cell
import { slider, checkbox } from '@jashkenas/inputs'
Insert cell
import {fileInput} from "@mbostock/file-input"
Insert cell
d3 = require("d3@6")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more