Playing WAV in c++

This is a discussion on Playing WAV in c++ within the C++ Programming forums, part of the General Programming Boards category; What is worng with this code? Code: #include <windows.h> #include <mmsystem.h> int main() { PlaySound("test.wav",NULL,SND_ASYNC|SND_FILENAME); Sleep(1000); return 0; } [Linker ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    28

    Playing WAV in c++

    What is worng with this code?


    Code:
    #include <windows.h>
    #include <mmsystem.h>
    
    int main()
    {
        PlaySound("test.wav",NULL,SND_ASYNC|SND_FILENAME);
        Sleep(1000);
        return 0;
    }
    [Linker error] undefined reference to `PlaySoundA@12'

    ld returned 1 exit status

    C:\Documents and Settings\SmokeMind\Desktop\Music\Makefile.win [Build Error] [Project1.exe] Error 1

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Try adding the Winmm.lib library

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    28
    #include <Winmm.lib>

    I did it like this but in Dev c++ says No such file or direktory??

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    20
    #pragma comment(lib, "Winmm.lib")

    that should work

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    28
    [Linker error] undefined reference to `PlaySoundA@12'

    ld returned 1 exit status

    C:\Documents and Settings\SmokeMind\Desktop\Music\Makefile.win [Build Error] [Project1.exe] Error 1
    Still the same message.
    Last edited by Smoki; 01-29-2006 at 03:59 PM.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Project -> project options -> parameters -> add library or object
    it should be in the lib folder: libwinmm.a

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    28
    Thanx it works. But is there any way of playing Mp3-s because the wav-s are sooo huge files comparing to mp3. Or is there any way to make wav-s but not that big files?

  8. #8
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    http://www.riverpast.com/en/prod/waveatmp3/index.php

    wave-mp3 and mp3-wave, is free.
    Though the quality will become less good.

  9. #9
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Try FMOD for MP3s. I like this simple tutorial.
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 07-30-2003, 03:04 PM
  2. Wav edit programmation for dos with DJGPP
    By sprudhom in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-17-2003, 07:35 AM
  3. playing wav or midi files
    By smokeybear in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2002, 11:39 AM
  4. Playing a wav file in C language
    By tvkswamy in forum C Programming
    Replies: 1
    Last Post: 09-13-2001, 10:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21