Skip to content

Commit bdd2a02

Browse files
authored
Add Sound library Waveform analyzer documentation
Contributed by @mhamilt
1 parent 868fa13 commit bdd2a02

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

content/api_en/LIB_sound/Waveform.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>Waveform</name>
5+
6+
<category>Sound</category>
7+
8+
<subcategory>Analyzer</subcategory>
9+
10+
<usage>Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
import processing.sound.*;
16+
17+
SoundFile sample;
18+
Waveform waveform;
19+
20+
int samples = 100;
21+
22+
public void setup()
23+
{
24+
size(640, 360);
25+
background(255);
26+
27+
sample = new SoundFile(this, "beat.aiff");
28+
sample.loop();
29+
30+
waveform = new Waveform(this, samples);
31+
waveform.input(sample);
32+
}
33+
34+
public void draw()
35+
{
36+
background(0);
37+
stroke(255);
38+
strokeWeight(2);
39+
noFill();
40+
41+
42+
waveform.analyze();
43+
44+
beginShape();
45+
for(int i = 0; i < samples; i++)
46+
{
47+
vertex(
48+
map(i, 0, samples, 0, width),
49+
map(waveform.data[i], -1, 1, 0, height)
50+
);
51+
}
52+
endShape();
53+
}
54+
]]></code>
55+
</example>
56+
57+
<description><![CDATA[
58+
This is a Waveform analyzer. It returns the waveform of the of an audio stream the moment it is queried with the analyze() method.
59+
]]></description>
60+
61+
<syntax>
62+
</syntax>
63+
64+
<parameters>
65+
66+
</parameters>
67+
68+
<method>
69+
<mname>input()</mname>
70+
<mdescription>Define the audio input for the analyzer</mdescription>
71+
</method>
72+
73+
<method>
74+
<mname>analyze()</mname>
75+
<mdescription>Gets the last nsamples captured from the connected input sound source, writes them
76+
into this Waveform's `data` array, and returns it.</mdescription>
77+
</method>
78+
79+
<method>
80+
<mname>stop()</mname>
81+
<mdescription>Stop the analyzer</mdescription>
82+
</method>
83+
84+
<method>
85+
<mname>data</mname>
86+
<mdescription>`float[]` of length nsamples, with the sample amplitudes between `-1` and `1`</mdescription>
87+
</method>
88+
89+
<constructor>
90+
Waveform(<c>parent</c>)
91+
</constructor>
92+
93+
<cparameter>
94+
<clabel>parent</clabel>
95+
<cdescription>PApplet: typically use "this"</cdescription>
96+
</cparameter>
97+
98+
<returns></returns>
99+
100+
<related>
101+
</related>
102+
103+
<type>Object</type>
104+
105+
<partof>Library</partof>
106+
107+
</root>

0 commit comments

Comments
 (0)