electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
ChucK MAUI Oscilloscope
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Wed Apr 02, 2008 1:08 am    Post subject: ChucK MAUI Oscilloscope
Subject description: It's a start at one anyway
Reply with quote  Mark this post and the followings unread

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...


Oscilloscope2_Image.jpg
 Description:
The oscilloscope in action
 Filesize:  47.16 KB
 Viewed:  4261 Time(s)

Oscilloscope2_Image.jpg



Oscilloscope2.ck
 Description:
The oscilloscope source code

Download
 Filename:  Oscilloscope2.ck
 Filesize:  1.89 KB
 Downloaded:  312 Time(s)


_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Wed Apr 02, 2008 1:32 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Wed Apr 02, 2008 2:10 am    Post subject: Reply with quote  Mark this post and the followings unread

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.

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use