| Author |
Message |
Inventor

Joined: Oct 13, 2007 Posts: 1857 Location: Florida, USA
Audio files: 73
|
Posted: Wed Apr 02, 2008 1:08 am Post subject:
ChucK MAUI Oscilloscope Subject description: It's a start at one anyway |
 |
|
Since we have discussed this before and for the fun of all, I made a crude ChucK Oscilloscope. The scope image is (1 x 1/Phi)*x_max in size, forming a pleasant Golden Ratio screen proportion. It has an array of LEDs that turn blue to indicate a waveform being drawn. It has zero-crossing trigger. I find it fun to watch while listening to music. Just ChucK it up and talk, whistle, or play music on your speakers and the scope will listen on the mic and draw its drawings.
I did one with moving LEDs but they ghosted like wild, so its better this way. Have fun and don't worry if you're PC/Linux, MAUI is on the way...
| Description: |
| The oscilloscope in action |
|
| Filesize: |
47.16 KB |
| Viewed: |
846 Time(s) |

|
| Description: |
| The oscilloscope source code |
|
 Download |
| Filename: |
Oscilloscope2.ck |
| Filesize: |
1.89 KB |
| Downloaded: |
25 Time(s) |
_________________ For those about to ChucK, we salute you! - Ge Wang
Let's make noise for peace! - kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Wed Apr 02, 2008 1:32 am Post subject:
|
 |
|
Here's an oscilloscope working in the terminal (Outputs a big fat stream of ASCII, don't try to run this if your terminal cannot keep up with it):
| Code: | fun void oscilloscope(UGen @ in){ oscilloscope(in, 80, 24, 25::ms, -1.0, 1.0, 20::ms, 200::ms); }
//Waits for a positive zero crossing and prints the waveform
fun void oscilloscope(UGen @ in,int x_resolution, int y_resolution, dur x_max, float y_min, float y_max , dur min_duration, dur max_duration){
x_max/(x_resolution$float) => dur x_grid_size;
(y_max-y_min)/(y_resolution$float) => float y_grid_size;
float amplitude[x_resolution];
float deriv;
int index;
int capturing;
int mark[x_resolution];
in.last() => float prev;
string screen;
while(true){
true => capturing;
0 => index;
while( capturing ){
x_grid_size => now;
if(index < amplitude.cap() ) in.last() => amplitude[index];
index++;
if( (prev < 0.0 && in.last() > 0.0 && index::x_grid_size > min_duration) || index::x_grid_size > max_duration ) false => capturing;
in.last() => prev;
}
//for(index => int i; i < amplitude.cap(); i++) 0.0 => amplitude[i]; //Clear the tail from garbage
"" => screen;
for(0 => int y; y < y_resolution; y++){
for(0 => int x; x < x_resolution && x < index; x++){
if( Math.round((amplitude[x]-y_min)/y_grid_size) == y_resolution - y ){
amplitude[ (x+1)%amplitude.cap() ] - amplitude[x] => deriv;
//if( Std.fabs(deriv) > y_grid_size*2.0 ) "|" +=> screen;
//if( deriv < -y_grid_size ) "\\" +=> screen;
if( deriv < -y_grid_size ){ true => mark[x]; " " +=> screen; } //Drop down one row
else if( deriv > y_grid_size ) "/" +=> screen;
else "_" +=> screen;
}
else if( mark[x] ){ "\\" +=> screen; false => mark[x]; }
else " " +=> screen;
}
"\n" +=> screen;
}
<<<screen,"">>>;
}
}
//Let's try it:
SinOsc m => SinOsc c => dac;
100.0 => c.freq;
c.freq()*3.01 => m.freq;
c.freq()*1.0 => m.gain;
2 => c.sync;
oscilloscope(c);
minute => now; |
Screenshot:
| Code: | ___ ____ ____
_ \ _ \ _ \
/
/ \ / \ \
/ \ / \ /
\
\ \ / \
/
\_ \___ \_/
__
\ / \ /
\ \
/ /
\ / \ /
___ ___
_ _
\ / \ /
|
_________________ To boldly go where no man has bothered to go before. |
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 1857 Location: Florida, USA
Audio files: 73
|
Posted: Wed Apr 02, 2008 2:10 am Post subject:
|
 |
|
Sending out strings too fast causes memory leaks, but they'll have that fixed soon. I guess if you size your terminal window right you can get a clean display of it. I really like how you drew the sloped characters like that, I have thought about drawing such in ASCII art before, like this:
| Code: | ^ sin x
|
,|, 1 _....._
| ,=" "=.
| ," ". ,"
|," , "., , ,,"
"""".*""""""""""|""""""""""|."""""""""|""""""""".|"""">
." | ". ." __ x
," | "._ _," ||
,|, sm "-.....-"
| -1
|
. |
Or something like that. _________________ For those about to ChucK, we salute you! - Ge Wang
Let's make noise for peace! - kijjaz |
|
|
Back to top
|
|
 |
|