Thread: musical notes using sound()

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    musical notes using sound()

    where can I find info on using the sound() and delay() to produce musical notes?

  2. #2
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Are you wanting to know how to use them, or how you can use them to make musical notes?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I want to know how to use them to make musical notes.

  4. #4
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    ok. sound() will always go until it is stopped. you stop sound() with nosound(). But if you put them right under another you will get no sound:

    /////
    sound();
    nosound();
    //////

    but if you put delay() between them, the sound will last longer.

    ////
    sound(600);
    delay(1000);
    nosound();
    /////
    this will play a semi-high pitch sound for one second.
    It is best if you create a function for it:
    //////
    int music(int pitch, int time)
    {
    sound(pitch);
    delay(time);
    nosound();
    return(0);
    }
    /////
    so then you can use it like this:

    /////
    int main()
    {
    music(600,1000);
    return 0;
    }
    ////

    which will produce the same sound.
    Simple enough?

  5. #5
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    So does anyone know the frequencies of musical notes?

    Additionally, does anyone know if it is possible to overlay one frequency of sound with another?

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Yes, but I was looking for a table of some sort that listed all that information for all of the notes(C,C#,A,etc). I've been studying another language called Turing. It has a function called play() that accepts a string. So play("AB>C<") would play normal A,B, and a high pitch Middle C.

  7. #7
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    There is a problem in doing this. A is 440 Hz and every other incarnation of A (in other octaves) is 440 * a power of 2 (880, 1760, etc). This also works in the other direction (220, 110, etc). This applies to every note, therefore the problem is that a semitone (distance between 2 adjecent notes) is different for each adjecent pair. It is in fact logarithmic. Unless you can find some sort of table you are going to have trouble.
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I've found a table on this page:
    http://www.phy.mtu.edu/~suits/notefreqs.html

    But the frequencys contains decimals. So how would I use that with sound()?

  9. #9
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Well round them off, silly!
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sound lags in multi-thread version
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 08-27-2008, 11:54 AM
  2. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. DirectSound - multiple sounds
    By Magos in forum Game Programming
    Replies: 9
    Last Post: 03-03-2004, 04:33 PM
  5. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 03:34 PM