Thread: create sound in C++ programming...how???

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    15

    Question create sound in C++ programming...how???

    hi!
    How to output sound using C++ program?
    is there any function to output sound in C++ program??
    can anyone help me to solve my problem???

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Code:
    #include<unknownos.h>
    #include<whatcompiler.h>
    
    int main()
    {
       unknownos::Sound thebeeper;
       thebeeper.IdioticFreqSet(10000);
       thebeeper.StupidAmplitudeSet(10000);
       thebeeper.MakeSarcasticSound();
       whatcompiler::End();
       return PSCYCHICRETVAL;
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    um can that post be deleted its complete spam al you SHOULD have said is,


    what os,
    what compiler,


    we really can only give you some helpfull sites to certain codes that may or maynot even help you.



    ok well anyway as i recall there should be one in the faq
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043876931&id=1031248558

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    I'm going to assume you're using C++, of course, compiler, for the MOST part, it doesnt matter.....


    Lets see, I suggest you take a look into openGL or directX, either one is used very widely, and it would be suggested you learn both in the long run :d

  5. #5
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    DirectX or OpenGL just for a sound? I don't think so. I agree it would be good to learn in the long run but that library would not be a good choice if you're JUST going to use sound. Try this:
    Code:
    #include <windows.h>
    #include <mmsystem.h>
    
    int main()
    {
    PlaySound("sound.wav",NULL,SND_ASYNC|SND_FILENAME);
    return 0;
    }
    You also need to link the library by typing -lwinmm in the commands when calling compiler. winmm stands for Windows Multi-Media(winmm). So only if you're doing Windows programming should you use this.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  6. #6
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by jmd15
    DirectX or OpenGL just for a sound? I don't think so. I agree it would be good to learn in the long run but that library would not be a good choice if you're JUST going to use sound. Try this:
    Code:
    #include <windows.h>
    #include <mmsystem.h>
    
    int main()
    {
    PlaySound("sound.wav",NULL,SND_ASYNC|SND_FILENAME);
    return 0;
    }
    You also need to link the library by typing -lwinmm in the commands when calling compiler. winmm stands for Windows Multi-Media(winmm). So only if you're doing Windows programming should you use this.
    Would that work in a console app? It doesn't seem to work for me. I made sure to include the

    #pragma comment(lib,"winmm.lib"); and also tried it with "lwinmm.lib".

    I've also tried sndPlaySound() and all sorts of crap like that before...but never had any luck with it.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you just want to play a sound, try this:
    Code:
    cout << "\a";
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    That plays a beep, or whatever the Windows DEFAULT-SOUND is. Try

    Code:
    #include <pc.h>
    
    int main() {
        sound(100);
        return 0;
    }
    . . . And that should beep at 100 Hertz untill you reboot, or recompile with nosound() instead of sound(100)

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    With what compiler? DJGPP, and ...?

    Windows functions (or ANSII ones) are your best bet (unless you're using Linux).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Code:
    #include <windows.h>
    
    int main()
    {
        Beep(1568, 200);
        Beep(1568, 200);
        Beep(1568, 200);
        Beep(1245, 1000);
        Beep(1397, 200);
        Beep(1397, 200);
        Beep(1397, 200);
        Beep(1175, 1000);
        
        return 0;
    }

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    The OP didn't even stick around to read the first reply -
    Just a bunch of pointless speculation and noise.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to create a file association program?
    By eShain in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2006, 12:15 PM
  2. Project Lost Tomorrow recruiting Programmers and Sound Engineers
    By chewtoy in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 12-07-2005, 05:02 AM
  3. Cannot create MDI Client Win
    By JaWiB in forum Windows Programming
    Replies: 1
    Last Post: 10-31-2005, 10:05 PM
  4. Using PC Speaker and NOT the sound card in a console...
    By Trauts in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-09-2003, 08:52 PM
  5. how to create diffrent sound frequencies
    By ALLRIGHT in forum C Programming
    Replies: 1
    Last Post: 05-15-2002, 05:25 PM