CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2006
    Posts
    8

    Question What is the code to play a .wav file in visual c++?

    I am currently working on a TUI program that will be able to play a .wav file on the input "play". I have the TUI all set up, however, I lack the code to accualy play the file. Could someone please help me? I dont need the "browse button" type of code, or the parameter type of code, like used in dos, although those would be the most useful to me because of the nature of the project, as that will be my next step. I dont really care how pretty it is, as it will end up being the sound engine of a game that I am working on. Any help is appricated. ^ ^

  2. #2
    Join Date
    Oct 2000
    Location
    India
    Posts
    4,620

    Thumbs up Re: What is the code to play a .wav file in visual c++?

    Hi,

    Quote from one of my previous posts

    Check out the MSDN documentation for sndplaysound and PlaySound too. But, remember that those commands can only play wave files within 100 KB or so. ( The largest wave file that can fit in the available memory ) For playing wave files more than 100 KB , i would recommend you to use the MCI Structures.

    Secondly, whenever you use mmsystem.h , remember to add WinMM.lib to your link settings.
    1) Use ::SndPlaySound for small wav files
    2) Use the PlaySound function for larger wav files
    3) Try the MCI Control MCISendMessage function
    to do a little complicated things like
    recording,rewinding,fast forward etc,etc.
    All luck and have a great day.

    Regards,
    V.Girish

    Visit www.geocities.com/contactgirish for Source code, Tutorials, FAQs and Downloads.

  3. #3
    Join Date
    May 2005
    Posts
    4,954

    Re: What is the code to play a .wav file in visual c++?

    The simple way is to use ::PlaySound().

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: What is the code to play a .wav file in visual c++?

    search for FMOD on google =] the best sound lib on the world

  5. #5
    Join Date
    Aug 2006
    Posts
    8

    Thumbs up Re: What is the code to play a .wav file in visual c++?

    kk, thanks. Ill try, although if ill be able to tell if the TUI isnt working or the code. ^ ^ (looks into feauture) more troubleshooting...

  6. #6
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: What is the code to play a .wav file in visual c++?

    Quote Originally Posted by thinkgeek182
    I am currently working on a TUI program that will be able to play a .wav file on the input "play". I have the TUI all set up, however, I lack the code to accualy play the file. Could someone please help me? I dont need the "browse button" type of code, or the parameter type of code, like used in dos, although those would be the most useful to me because of the nature of the project, as that will be my next step. I dont really care how pretty it is, as it will end up being the sound engine of a game that I am working on. Any help is appricated. ^ ^
    Why Not you Simply use Microsoft Provide method for this.
    Like MCIWndPlay .Just open <vfw.h> File on your system everything is there in the File.have a look on this

    Thanx

  7. #7
    Join Date
    Aug 2006
    Posts
    8

    Re: What is the code to play a .wav file in visual c++?

    Ok, Im using dev c++ for one thing, and Ive seen a lot of code that requires header files that I dont have. here is my current program, I know that it could use a little fixing up, I havent been able to compile it yet, but, whatever:

    #include <iostream>
    using namespace std;
    int main()
    {
    char input[10];//the number in the brackets is the number of charicters that the char can represent. in this case, it is ten
    char path[150];//the number in the brackets is the number of charicters that the char can represent. in this case, it is 150
    //general instructions, showed when TUI and app is starting up
    cout << "This program is supposed to play a .wav file. If, for some reason, this application is not working, move whole file including the .wav file. That should fix the problem. If not, input 'help.'/n/n";
    //this cout command gives the basic instructions and warnings of the program
    cout <<"controlls: 'play' == play .wav file";
    cout <<"/n 'help' == bring up help dialog";
    cout <<"/n 'stop' == stop playing .wav file";
    cout <<"/n 'close' == close dialog window";
    cout <<"/n WARNING, YOU MAY NOT INPUT ANY MORE THAN 5 CHARICTORS UNLESS PROMPTED WITH 'Path:' THiS WILL RESAULT IN MEMORY ERROR!";
    cout <<"/n Input path to .wav file, in format without the quotes:";
    cout <<"/n PATH:";
    cin >> path ;//sets the value for the char "path";
    while (input != "close");//this creates the nessisary 'while' loop to run the TUI. untill the char 'input' has a value of close, it will keep looping.
    {
    cin >> input;
    //play input for TUI
    if (input == "play");
    (
    bool PlaySound(
    LPCSTR
    HMODULE
    DWORD
    );
    //this is supposed to call for the charictor 'path' which is defined in the first cin command


    )
    //help input for TUI
    else if input == "help";
    (
    cout << "controlls: 'play' == play .wav file" <<;//basic input for the
    cout <<"\n 'help' == bring up help dialog";
    cout <<"\n 'stop' == stop playing .wav file";
    cout <<"\n 'close' == close dialog window";
    cout <<"\n .wav file player";
    cin >> input ;
    )

    else if input == "stop";
    (
    // code to stop the .wav file form playing and return to the TUI undetermined.
    )
    }



    return 0;
    }

    any help is appricated.

  8. #8
    Join Date
    Oct 2000
    Location
    India
    Posts
    4,620

    Thumbs up Re: What is the code to play a .wav file in visual c++?

    Hi,

    You definitely need to take a look at DirectShow. A tutorial is available at
    http://www.geocities.com/contactgirish/DirectShow.html

    By including DirectX, your overhead is going to increase, but you have a lot
    of additional functionality for free like playing a sound file (most of the
    recognized sound file formats), pausing playback, stopping the playback,
    seeking, fast forward, rewind, setting the play speed etc., (i.e.) all
    functionality available in a media player.

    If you take a look at the tutorial, u can see that a single line of code can
    handle most of your functionality. Since DirectShow is COM based, you
    should have no problem to include it in your dev. environment. Hope this
    helps.

    p.s. One more thing. Always bear in mind that for commercial apps, once u
    show the customer something, he's always going to need more By
    incorporating DirectShow in your app, you can be sure of handling all
    the various functionalities needed for playback.
    Last edited by VGirish; August 4th, 2006 at 12:52 AM.
    All luck and have a great day.

    Regards,
    V.Girish

    Visit www.geocities.com/contactgirish for Source code, Tutorials, FAQs and Downloads.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured