-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ee5eaf
commit 227bd21
Showing
13 changed files
with
341 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//------------------------------------------------------------------------------ | ||
// name: accelDemo.ck | ||
// desc: Accel-erometer WebChucK Demo (mobile only) | ||
// Use mobile accelerometer to control sound synthesis | ||
// NOTE: enable accelerometer in sensor settings | ||
// | ||
// Accel WebChucK Docs: | ||
// https://chuck.stanford.edu/webchuck/docs/classes/Accel.html | ||
// | ||
// author: Mike Mulshine | ||
//------------------------------------------------------------------------------ | ||
|
||
Accel ac; | ||
AccelMsg msg; | ||
|
||
0 => int device; | ||
|
||
// open accel | ||
if( !ac.openAccel( device ) ) me.exit(); | ||
<<< "accel '" + ac.name() + "' ready", "" >>>; | ||
|
||
<<< "only on mobile" >>>; | ||
|
||
SinOsc osc => Envelope gain => dac; | ||
Noise noise => LPF filter => gain; | ||
|
||
100 => float rootOscFreq; | ||
rootOscFreq => osc.freq; | ||
|
||
500 => float rootFilterFreq; | ||
rootFilterFreq => filter.freq; | ||
|
||
0.5 => filter.gain; | ||
|
||
10::ms => gain.duration; | ||
1.0 => gain.target; | ||
|
||
// infinite event loop | ||
while( true ) | ||
{ | ||
// wait on accel event | ||
ac => now; | ||
|
||
// get one or more messages | ||
while( ac.recv( msg ) ) | ||
{ | ||
// print accel values | ||
<<< msg.getAccelX() + " " + msg.getAccelY() + " " + msg.getAccelZ() >>>; | ||
// compute average acceleration | ||
(Math.fabs(msg.getAccelX()) + | ||
Math.fabs(msg.getAccelY()) + | ||
Math.fabs(msg.getAccelZ())) * 0.3333 => float avgAccel; | ||
|
||
// control synthesis/filter freq | ||
avgAccel * 10.0 => float dFreq; | ||
rootOscFreq + dFreq => osc.freq; | ||
rootFilterFreq + dFreq * 2.0 => filter.freq; | ||
// control gain | ||
avgAccel / 150.0 => float newGain; | ||
newGain => gain.target; | ||
} | ||
|
||
10::ms => now; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//------------------------------------------------------------------------------ | ||
// name: gyroDemo.ck | ||
// desc: Gyro-scope WebChucK Demo (mobile only) | ||
// Use mobile gyroscope to control audio playback | ||
// NOTE: enable gyroscope in sensor settings | ||
// | ||
// Gyro WebChucK Docs: | ||
// https://chuck.stanford.edu/webchuck/docs/classes/Gyro.html | ||
// | ||
// author: Mike Mulshine | ||
//------------------------------------------------------------------------------ | ||
|
||
Gyro gy; | ||
GyroMsg msg; | ||
|
||
0 => int device; | ||
|
||
// open gyro | ||
if( !gy.openGyro( device ) ) me.exit(); | ||
<<< "gyro '" + gy.name() + "' ready", "" >>>; | ||
|
||
<<< "only on mobile" >>>; | ||
|
||
SndBuf buf => Envelope gain => dac; | ||
buf.read("gyroloop.wav"); | ||
0 => buf.pos; | ||
1 => buf.loop; | ||
|
||
10::ms => gain.duration; | ||
1.0 => gain.target; | ||
|
||
function float clamp(float val, float min, float max) { | ||
if (val < min) return min; | ||
if (val > max) return max; | ||
return val; | ||
} | ||
|
||
// infinite event loop | ||
while( true ) | ||
{ | ||
// wait on gyro event | ||
gy => now; | ||
|
||
// get one or more messages | ||
while( gy.recv( msg ) ) | ||
{ | ||
// print gyro values | ||
<<< msg.getGyroX() + " " + msg.getGyroY() + " " + msg.getGyroZ() >>>; | ||
|
||
// normalize Y/Z gyro values to 0.0 to 1.0 | ||
Math.fabs(clamp(msg.getGyroY(), -90, 90)) / 90.0 => float gY; | ||
(clamp(msg.getGyroZ(), -90, 90) + 90.0) / 180.0 => float gZ; | ||
|
||
// control playback rate and envelope | ||
gY => gain.target; | ||
gZ * 2.0 => buf.rate; | ||
} | ||
|
||
10::ms => now; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.