electro-music.org   Dedicated to experimental electro-acoustic
and electronic music
 
 Front Page  |  Radio  |  Forum  |  Media  |  Playlists  |  Wiki
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
A simple ChucK question I can't find the answer to.
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Underwaterbob



Joined: Sep 03, 2008
Posts: 26
Location: Chungju, South Korea

PostPosted: Wed Sep 17, 2008 11:39 pm    Post subject: A simple ChucK question I can't find the answer to. Reply with quote  Mark this post and the followings unread

Are there any resources in ChucK that let me set oscillators to standard notes, not just numbered frequencies? I mean, if I want a middle C do I have to ChucK 256Hz to an oscillator or are typical notes defined somehow in ChucK?

I'm looking for something equivalent to the cpspch opcode in Csound that lets me use a standard, tempered musical scale, and microtones.
Back to top
View user's profile Send private message
jukka_k



Joined: Sep 17, 2008
Posts: 22
Location: Finland

PostPosted: Thu Sep 18, 2008 12:28 am    Post subject: Reply with quote  Mark this post and the followings unread

Not sure if my answer to your question is correct, I've used Std.mtof function for MIDI notes, like

Code:

60 => Std.mtof => f.freq;

for middle C

or

Code:

Std.rand2(60,88) => Std.mtof => f.freq;

to generate random MIDI notes between 60 and 88.

I've used ChucK one day so there are probably other ways to do job too !


-Jukka

Last edited by jukka_k on Thu Sep 18, 2008 3:27 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Thu Sep 18, 2008 2:43 am    Post subject: Reply with quote  Mark this post and the followings unread

Yes. using Std.mtof function will generate standard-tuning notes.

Std.mtof(60) gives out frequency of middle C
(and in chuck, we can chuck into a function also)

Code:
SinOsc s => dac;
for(int i; i < 13; i++)
{ i + 60 => Std.mtof => s.freq; 250::ms => now; }


this is just playing chromatically from middle C up to C in the next octave.

if you'd like to define a scale, try using an array: something like this:

[0, 2, 4, 5, 7, 9, 11] @=> int MajorScale[];
[0, 2, 3, 5, 7, 8, 11] @=> int HarmonicMinorScale[];

try with this:

Code:
[0, 2, 3, 5, 7, 8, 11] @=> int HarmonicMinorScale[];
60+12+2 => int Key; // let's play in key C + 2 semitones = key D
Flute s => dac;
for(int i; i < 7; i++)
{
    Key + HarmonicMinorScale[i] => Std.mtof => s.freq;
    .5 => s.noteOn;
    250::ms => now;
    .5 => s.noteOff;
    250::ms => now;
}


this plays the notes from D harmonic minor scale.
this can be adjusted more for further development / application.

enjoy.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
radarsat1



Joined: Mar 14, 2008
Posts: 85
Location: Montreal

PostPosted: Thu Sep 18, 2008 2:21 pm    Post subject: Reply with quote  Mark this post and the followings unread

this might be a good opportunity to mention something that i posted to the mailing list quite a long time ago but got few responses..

https://lists.cs.princeton.edu/pipermail/chuck-users/2007-August/001924.html

I'll just repost the text here:

Quote:
I've been making a few Chuck synths lately and have been wanting a way
to play them straight from the keyboard instead of having to attach a
MIDI device. I used to do this all the time with FastTracker back in
the DOS-ages.

Anyways, of course Chuck can get keyboard input, so all that was
missing was a mapping from the keyboard keys to MIDI note numbers.

Attached is a Chuck script that reads the keyboard and then generates
Events containing a note number. These are available through a public
class, so a separate Chuck script can wait for the events and spork
notes.

Note that it's not quite an up-to-scratch implementation of polyphony,
since there is only a single event structure that will get overwritten
by the next key press. Maybe I'll work on that next... (perhaps using
an array to store extra notes, but some timing calculations will need
to be made..)

Oh yes, and this is designed for a US keyboard, but feel free to
change the keymap. I figured it out from the kb.ck output.

So anyways, enjoy. Smile

ps., run concurrently:
$ chuck kbpiano.ck kbpiano_example.ck



kbpiano.ck:
Code:

// Script which maps keyboard events into piano keys, allowing you to
// play melodies on the computer keyboard, tracker-style.
// Works for US keyboards only, however the keymap can be easily changed.
// (Generated by examining output from Chuck's kb.ck example file.)

// This may need some work to support polyphony properly.  Specifically,
// the single Event will need an array of notes, and timing will have to
// be measured to detect chords.

// - Radarsat-1, 2007
//   radarsat1@gmail.com

KBHit kb;
false => int verbose;
5 => int octave;

class KeyEvent extends Event
{
    int note;
    float freq;
    string notename;
    int octave;
}

public class kbpiano
{
    static KeyEvent@ evt;
}

KeyEvent kevt @=> kbpiano.evt;

// Unused, but good for reference -- upper keyboard octave keycodes
[113, 50, 119, 51, 101, 114, 53, 116, 54, 121, 55, 117, 105, 57, 111,
48, 112, 91, 61, 93] @=> int upper[];

// Unused, but good for reference -- lower keyboard octave keycodes
[122, 115, 120, 100, 99, 118, 103, 98, 104, 110, 106, 109, 44, 108,
46, 59, 47] @=> int lower[];

[27, 91, 65] @=> int octup[];    // Cursor up
[27, 91, 66] @=> int octdown[];  // Cursor down

["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"] @=> string notes[];

[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, -1, 14, 16, 27, -1, 13,
15, -1, 18, 20, 22, -1, 25, -1, 15, -1, 30, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 29, -1, 31, -1, -1, -1, -1, 7, 4, 3, 16, -1,
6, 8, 24, 10, -1, 13, 11, 9, 26, 28, 12, 17, 1, 19, 23, 5, 14, 2, 21,
0, -1, -1, -1, -1, -1] @=> int keymap[];

fun void handle_octave()
{
    kb => now;
    kb.getchar() => int char;
    if ((char == octup[1]) || (char == octdown[1])) {
        kb => now;
        kb.getchar() => char;
        if (char == octup[2])
        {
            octave+1 => octave;
            if (octave > 8) 8 => octave;
        }
        else if ((char == octdown[2]))
        {
            octave-1 => octave;
            if (octave < 0) 0 => octave;
        }
        if (verbose)
            <<<"Octave:",octave>>>;
    }
}

while (true)
{
    kb => now;
    while (kb.more())
    {
        kb.getchar() => int char;
        if ((char == octup[0]) || (char == octdown[0])) {
            handle_octave();
        }
        else {
            keymap[char] => int note;
            if (note >= 0) {
                if (verbose)
                    <<<notes[note%12],octave>>>;
                note + (octave*12) => kevt.note;
                octave => kevt.octave;
                notes[note%12] => kevt.notename;
                Math.mtof(kevt.note) => kevt.freq;
                kevt.broadcast();
            }
        }
    }
}


kbpiano_example.ck:
Code:

// Example of using the kbpiano.ck script to map the computer keyboard
// to a piano, tracker-style.

// - Radarsat-1, 2007
//   radarsat1@gmail.com

<<<"Press keys on your keyboard to play the piano.\nUp and down cursor keys change octave.\n(US keyboards only, sorry.. feel free to edit the keymap!)">>>;

fun void mandolpluck(float freq)
{
    Mandolin mand => dac;

    freq => mand.freq;

    mand.noteOn(1);
    3::second => now;
}

while (true)
{
    kbpiano.evt => now;
   
    <<<kbpiano.evt.note, kbpiano.evt.notename,
    kbpiano.evt.octave, kbpiano.evt.freq>>>;

    spork ~ mandolpluck(kbpiano.evt.freq);
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 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
Log in
Username:     Password:      Log me on automatically each visit    


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2026 by electro-music.org