Skip to content

Commit f8e184d

Browse files
committed
Add initial codebase created as part of Google Summer of Code 2018
1 parent 92f24e2 commit f8e184d

File tree

81 files changed

+5162
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5162
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
*.jar

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
# processing-sound
2-
Audio library for Processing built with JSyn
1+
## Processing Sound library
32

4-
This library replaces the prior Processing Sound library (<https://github.com/processing/processing-sound-archive>). The API is 100% compatible, so all code written with the prior code base will work with the new version of the library.
3+
The new Sound library for Processing 3 provides a simple way to work with audio. It can play, analyze, and synthesize sound. The library comes with a collection of oscillators for basic wave forms, a variety of noise generators, and effects and filters to alter sound files and other generated sounds. The syntax is minimal to make it easy for beginners who want a straightforward way to add some sound to their Processing sketches!
4+
5+
### How to use
6+
7+
The easiest way to install the Sound library is through Processing's Contribution Manager. The library comes with many example sketches, the full online reference can be found [here](https://www.processing.org/reference/libraries/sound/). Please report bugs [https://github.com/processing/processing-sound/issues](here).
8+
9+
### How to build
10+
11+
1. `git clone [email protected]:processing/processing-sound.git`
12+
2. into the `library/` folder copy (or soft-link) your Processsing's `core.jar` (and, optionally, also your Android SDK's `android.jar`, API level 26 or higher). Other dependencies (in particular Phil Burk's [JSyn](http://www.softsynth.com/jsyn/) engine on which this library is based) are downloaded automatically.
13+
3. `ant dist` (or, alternatively, run build.xml from within Eclipse)
14+
15+
The resulting `processing-sound.zip` can be extracted into your Processing installation's `libraries/` folder.
16+
17+
### License
18+
19+
LGPL v2.1

build.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0"?>
2+
<project name="Processing Sound Library" default="build">
3+
4+
<property file="./build.properties" />
5+
6+
<path id="classpath">
7+
<fileset dir="..">
8+
<!-- look for Processing's core.jar in ../processing -->
9+
<!-- alternatively, this file can also be placed in -->
10+
<!-- the local library folder -->
11+
<include name="processing/core/library/core.jar" />
12+
</fileset>
13+
<fileset dir="library">
14+
<include name="*.jar" />
15+
</fileset>
16+
</path>
17+
18+
<target name="clean" description="Clean the build directories">
19+
<delete dir="bin" />
20+
<delete file="library/sound.jar" />
21+
</target>
22+
23+
<target name="checkandroid">
24+
<available file="library/android.jar" property="hasandroid" />
25+
</target>
26+
27+
<target name="android-deps" unless="hasandroid" description="Download an android.jar">
28+
<!-- this part of the Android SDK is required to build JSynAndroidAudioDeviceManager -->
29+
<!-- preferrably you should soft-link or copy the android.jar of your locally
30+
installed SDK into this project's library/ directory -->
31+
<get src="https://github.com/marianadangelo/android-platforms/raw/master/android-26/android.jar" dest="library/" usetimestamp="true" />
32+
</target>
33+
34+
<target name="deps" depends="checkandroid,android-deps" description="Get library dependencies">
35+
<mkdir dir="library" />
36+
<get src="http://www.softsynth.com/jsyn/developers/archives/jsyn-20171016.jar" dest="library/" usetimestamp="true" />
37+
<get src="https://github.com/kevinstadler/JavaMP3/releases/download/v1.0.2/javamp3-1.0.2.jar" dest="library/" usetimestamp="true" />
38+
</target>
39+
40+
<target name="compile" depends="deps" description="Compile sources">
41+
<mkdir dir="bin" />
42+
<javac source="1.8" target="1.8" srcdir="src" destdir="bin" encoding="UTF-8" includeAntRuntime="false" nowarn="true">
43+
<classpath refid="classpath" />
44+
</javac>
45+
</target>
46+
47+
<target name="javadoc">
48+
<javadoc bottom="Processing Sound" destdir="docs" verbose="false" doctitle="Javadocs: Processing Sound" public="true" windowtitle="Javadocs: Processing Sound" additionalparam="-notimestamp">
49+
<fileset dir="src" defaultexcludes="yes">
50+
<include name="**/*" />
51+
</fileset>
52+
<classpath refid="classpath" />
53+
</javadoc>
54+
</target>
55+
56+
<target name="build" depends="clean,compile" description="Build Sound library jar">
57+
<jar destfile="library/sound.jar">
58+
<fileset dir="bin" />
59+
</jar>
60+
</target>
61+
62+
<target name="dist" depends="build,javadoc">
63+
<zip destfile="../processing-sound.zip">
64+
<zipfileset dir="." prefix="sound">
65+
<exclude name=".*" />
66+
<exclude name="build.xml" />
67+
<exclude name="bin/**" />
68+
<exclude name="docs/**" />
69+
<exclude name="examples/**/application.*/**" />
70+
<exclude name="library/android.jar" />
71+
<exclude name="library/core.jar" />
72+
<exclude name="src/**" />
73+
</zipfileset>
74+
</zip>
75+
<!--copy file="library.properties"
76+
toFile="../processing-sound.txt" /-->
77+
</target>
78+
</project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* This sketch shows how to use the FFT class to analyze a stream
3+
* of sound. Change the number of bands to get more spectral bands
4+
* (at the expense of more coarse-grained time resolution of the spectrum).
5+
*/
6+
7+
import processing.sound.*;
8+
9+
// Declare the sound source and FFT analyzer variables
10+
SoundFile sample;
11+
FFT fft;
12+
13+
// Define how many FFT bands to use (this needs to be a power of two)
14+
int bands = 128;
15+
16+
// Define a smoothing factor which determines how much the spectrums of consecutive
17+
// points in time should be combined to create a smoother visualisation of the spectrum.
18+
// A smoothing factor of 1.0 means no smoothing (only the data from the newest analysis
19+
// is rendered), decrease the factor down towards 0.0 to have the visualisation update
20+
// more slowly, which is easier on the eye.
21+
float smoothingFactor = 0.2;
22+
23+
// Create a vector to store the smoothed spectrum data in
24+
float[] sum = new float[bands];
25+
26+
// Variables for drawing the spectrum:
27+
// Declare a scaling factor for adjusting the height of the rectangles
28+
int scale = 5;
29+
// Declare a drawing variable for calculating the width of the
30+
float barWidth;
31+
32+
public void setup() {
33+
size(640, 360);
34+
background(255);
35+
36+
// Calculate the width of the rects depending on how many bands we have
37+
barWidth = width/float(bands);
38+
39+
// Load and play a soundfile and loop it.
40+
sample = new SoundFile(this, "beat.aiff");
41+
sample.loop();
42+
43+
// Create the FFT analyzer and connect the playing soundfile to it.
44+
fft = new FFT(this, bands);
45+
fft.input(sample);
46+
}
47+
48+
public void draw() {
49+
// Set background color, noStroke and fill color
50+
background(125, 255, 125);
51+
fill(255, 0, 150);
52+
noStroke();
53+
54+
// Perform the analysis
55+
fft.analyze();
56+
57+
for (int i = 0; i < bands; i++) {
58+
// Smooth the FFT spectrum data by smoothing factor
59+
sum[i] += (fft.spectrum[i] - sum[i]) * smoothingFactor;
60+
61+
// Draw the rectangles, adjust their height using the scale factor
62+
rect(i*barWidth, height, barWidth, -sum[i]*height*scale);
63+
}
64+
}
678 KB
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* This sketch shows how to use the Amplitude class to analyze the changing
3+
* "loudness" of a stream of sound. In this case an audio sample is analyzed.
4+
*/
5+
6+
import processing.sound.*;
7+
8+
// Declare the processing sound variables
9+
SoundFile sample;
10+
Amplitude rms;
11+
12+
// Declare a smooth factor to smooth out sudden changes in amplitude.
13+
// With a smooth factor of 1, only the last measured amplitude is used for the
14+
// visualisation, which can lead to very abrupt changes. As you decrease the
15+
// smooth factor towards 0, the measured amplitudes are averaged across frames,
16+
// leading to more pleasant gradual changes
17+
float smoothingFactor = 0.25;
18+
19+
// Used for storing the smoothed amplitude value
20+
float sum;
21+
22+
public void setup() {
23+
size(640, 360);
24+
25+
//Load and play a soundfile and loop it
26+
sample = new SoundFile(this, "beat.aiff");
27+
sample.loop();
28+
29+
// Create and patch the rms tracker
30+
rms = new Amplitude(this);
31+
rms.input(sample);
32+
}
33+
34+
public void draw() {
35+
// Set background color, noStroke and fill color
36+
background(125, 255, 125);
37+
noStroke();
38+
fill(255, 0, 150);
39+
40+
// smooth the rms data by smoothing factor
41+
sum += (rms.analyze() - sum) * smoothingFactor;
42+
43+
// rms.analyze() return a value between 0 and 1. It's
44+
// scaled to height/2 and then multiplied by a fixed scale factor
45+
float rms_scaled = sum * (height/2) * 5;
46+
47+
// We draw a circle whose size is coupled to the audio analysis
48+
ellipse(width/2, height/2, rms_scaled, rms_scaled);
49+
}
678 KB
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* In this example, a WhiteNoise generator (equal amount of noise at all frequencies) is
3+
* passed through a BandPass filter. You can control both the central frequency
4+
* (left/right) as well as the bandwidth of the filter (up/down) with the mouse. The
5+
* position and size of the circle indicates how much of the noise's spectrum passes
6+
* through the filter, and at what frequency range.
7+
*/
8+
9+
import processing.sound.*;
10+
11+
WhiteNoise noise;
12+
BandPass filter;
13+
14+
void setup() {
15+
size(640, 360);
16+
17+
// Create the noise generator + Filter
18+
noise = new WhiteNoise(this);
19+
filter = new BandPass(this);
20+
21+
noise.play(0.5);
22+
filter.process(noise);
23+
}
24+
25+
void draw() {
26+
// Map the left/right mouse position to a cutoff frequency between 20 and 10000 Hz
27+
float frequency = map(mouseX, 0, width, 20, 10000);
28+
// And the vertical mouse position to the width of the band to be passed through
29+
float bandwidth = map(mouseY, 0, height, 1000, 100);
30+
31+
filter.freq(frequency);
32+
filter.bw(bandwidth);
33+
34+
// Draw a circle indicating the position + width of the frequency window
35+
// that is allowed to pass through
36+
background(125, 255, 125);
37+
noStroke();
38+
fill(255, 0, 150);
39+
ellipse(mouseX, height, 2*(height - mouseY), 2*(height - mouseY));
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* This is a simple WhiteNoise generator, run through a HighPass filter which only lets
3+
* the higher frequency components of the noise through. The cutoff frequency of the
4+
* filter can be controlled through the left/right position of the mouse.
5+
*/
6+
7+
import processing.sound.*;
8+
9+
WhiteNoise noise;
10+
HighPass highPass;
11+
12+
void setup() {
13+
size(640, 360);
14+
15+
// Create the noise generator + filter
16+
noise = new WhiteNoise(this);
17+
highPass = new HighPass(this);
18+
19+
noise.play(0.5);
20+
highPass.process(noise);
21+
}
22+
23+
void draw() {
24+
// Map the left/right mouse position to a cutoff frequency between 10 and 15000 Hz
25+
float cutoff = map(mouseX, 0, width, 10, 15000);
26+
highPass.freq(cutoff);
27+
28+
// Draw a circle indicating the position + width of the frequencies passed through
29+
background(125, 255, 125);
30+
noStroke();
31+
fill(255, 0, 150);
32+
ellipse(width, height, 2*(width - mouseX), 2*(width - mouseX));
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* This is a simple WhiteNoise generator, run through a LowPass filter which only lets
3+
* the lower frequency components of the noise through. The cutoff frequency of the
4+
* filter can be controlled through the left/right position of the mouse.
5+
*/
6+
7+
import processing.sound.*;
8+
9+
WhiteNoise noise;
10+
LowPass lowPass;
11+
12+
void setup() {
13+
size(640, 360);
14+
15+
// Create the noise generator + filter
16+
noise = new WhiteNoise(this);
17+
lowPass = new LowPass(this);
18+
19+
noise.play(0.5);
20+
lowPass.process(noise);
21+
}
22+
23+
void draw() {
24+
// Map the left/right mouse position to a cutoff frequency between 20 and 10000 Hz
25+
float cutoff = map(mouseX, 0, width, 20, 10000);
26+
lowPass.freq(cutoff);
27+
28+
// Draw a circle indicating the position + width of the frequencies passed through
29+
background(125, 255, 125);
30+
noStroke();
31+
fill(255, 0, 150);
32+
ellipse(0, height, 2*mouseX, 2*mouseX);
33+
}

0 commit comments

Comments
 (0)