Platform
Resources
Pricing
Sign in
Get started
mengy
data janitor
Workspace
Fork
Published
By
mengy
Edited
Jul 15, 2021
1 fork
2 stars
1
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.
Try it for free
Learn more
Fork
View
Export
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
audioFile
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
audiobuffer
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nbSamples
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
step
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rawSamples
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nonZeroIndex
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nonZeroIndexEnd
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
samples
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
transform
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nbSpirals
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
width
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nbWindow
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
values
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
waveformLine
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
waveformBar
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lineRadial
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
areaRadial
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
xRadial
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yRadial
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yScale
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
margin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
audioContext
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML