Playing Sound In C++

Discussion in 'C++' started by techme, Mar 26, 2010.

  1. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    I would like to make a program that would allow the user to make music based on various inputs, including numbers.

    All my serching of the help system of c++ builder left me with no results on how to play a single sound, or how to tell the computer in one command (preferably) to play this instrument, this pitch, this duration and possibly some other parameters.

    As far as I remember some older computers and languages used to have a PLAY command which looked something like this: PLAY(x,y,z etc).

    Is something like that possible in C++? Searching the net it seems that the answer might be in calling a windows API to do that. But which API? Can anyone show me an example, some links or leads?

    thanks,

    mosnik

    PS I do not speak here of making professional music, but not of using standard BEEP function either...
     
  2. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I think that a long, long, long time ago you could "play" certain frequencies through the PC speaker or serial line, but it was terrible sounding and YOU had to "tune" the interface.

    Today I think it would be a lot easier to learn to use the API for the MIDI chip on your sound card. There is lots of music in midi files already on the internet.
     
  3. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    thanks for the leads, I will try around but something tells me that this is going to be a difficult task since direct manipulation of midi is a very specialised field, as fas as I know.
     
  4. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    http://ipankaj.net
  5. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for the lead, I followed it and got a bit scared of the size of the material! Anyway, for some time I will be studying it to see if I will be able to use it.



    Thanks again,
     
  6. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    hello techme,
    i have answer to your question

    There is one way which i know .YOu have to use a manipulator for it i.e. \a.

    cout<<"Beep sound \a";

    With the use og \a you can hear a sound YOu can give as many \a you want
     
  7. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    I've been playing around with beep - I know you said more than beep, not not professional -- so I think this may work; using beep(freq, time) you can set the frequency and length of time the beep is set - this gives limited control but it's easy.

    Cheers,
    Code:
    #include <iostream.h>
    #include <windows.h>
    
    void scale(void)
    { Beep(523,400); // 523 hertz (C5) for 400 milliseconds
     Beep(587,400);
     Beep(659,400);
     Beep(698,400);
     Beep(784,400);
     Beep(698,400);
     Beep(659,400);
     Beep(587,400);
     Beep(523,400);
    }
    
    
    int main()
    {
     
     scale();
     cout << "Scale completed.\n";
      
     return 0;
    }
     
  8. davidk

    davidk New Member

    Joined:
    Mar 25, 2010
    Messages:
    16
    Likes Received:
    1
    Trophy Points:
    0
    Home Page:
    http://www.firmdev.com/firm_framework
    If you are looking for really good stuff of how to deal with sound, consider Microsoft DirectSound. Please get DirectX sdk (use google to find it), install it and see examples of how to use DirectSound.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice