Playing sounds in Turbo C++

This is a discussion on Playing sounds in Turbo C++ within the C++ Programming forums, part of the General Programming Boards category; Hello, I am a sophomore in highschool. I am making battleship as my final project and I need some help. ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    15

    Question Playing sounds in Turbo C++

    Hello, I am a sophomore in highschool. I am making battleship as my final project and I need some help. Would anyone be kind enough to tell me how(if possible) to play a .wav file? If that is not possible, is it possible to play a beep (the \a type) with a different frequency? If you need a special header file could you please post it? Thank you.

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    turbo c++, thats version 3.0, correct?
    which is dos based?


    if thats right, i dont think u can play wav files easily.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    15
    Yes, it is version 3.0, the DOS based version. I could also take advice for the Borland C++ compiler, I believe 5.0.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    i know msvc, if u include the windows.h header file has a function called PlaySound()
    i dunno if borland includes this.
    u might wanna try it out

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    15
    OK, so I include windows.h which I believe I have, and all I need to do is PlaySound(boom.wav) if it is in the same directory?

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    i think its best to put it PlaySound("boom.wav")
    but in microsoft's version, there are 2 other values u put it
    but check just to make sure the function is there

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    15
    OK, this is my code:

    Code:
       #include<windows.h>
       #include<conio.h>
    
        void main ()
                {
                 PlaySound(bomb.wav);
                 getch();
                 }

    And this is my error:

    Undefined symbol: bomb

    Do I somehow need to declare the .wav file?
    Last edited by Fifasoccer21234; 05-08-2003 at 12:18 PM.

  8. #8
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    use quotes please

  9. #9
    Registered User
    Join Date
    May 2003
    Posts
    15
    I checked the windows.h header file and the only code about sounds was:

    Code:
    /****** Sound support ******************************************************/
    
    #ifndef NOSOUND
    
    int     WINAPI OpenSound(void);
    void    WINAPI CloseSound(void);
    
    int     WINAPI StartSound(void);
    int     WINAPI StopSound(void);
    
    int     WINAPI SetVoiceQueueSize(int, int);
    int     WINAPI SetVoiceNote(int, int, int, int);
    int     WINAPI SetVoiceAccent(int, int, int, int, int);
    int     WINAPI SetVoiceEnvelope(int, int, int);
    int     WINAPI SetVoiceSound(int, DWORD, int);
    
    int     WINAPI SetVoiceThreshold(int, int);
    int FAR* WINAPI GetThresholdEvent(void);
    int     WINAPI GetThresholdStatus(void);
    
    int     WINAPI SetSoundNoise(int, int);
    Am I doing something wrong?

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    wow
    i think somehow u gotta include or use those functions...

    i cant help u too much on that, because i just use microsoft c++ and all i need is the function


    OH YEA

    see if u can also link this library file (or if u even have it)
    winmm.lib

    i know i had to include that when i complile
    dunno hwo to do it with borland th0

  11. #11
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    I'm not using Borland... but...

    I'm pretty sure that the new Borland compiler has a
    Sound(Frequency, Duration) function. The old one should have one too. Do you have a sound.h file? In true-DOS this would probably only work through the internal speaker

    Microsoft has a Beep(Frequency, Duration) function. But, it does different things depending on your hardware and operating system. As I recall, it only works "as-expected" with WinNT or WinXP and only if you don't have a sound card/external speakers... Weird!

    Those WINAPI sound functions that you found look like MIDI functions, which should work... if you can find the documentation... And if they are from the Turbo C++ compiler. If it's really a DOS compiler, it shouldn't have a windows.h file!

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    15
    What header file does the beep function require?

  13. #13
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Fifasoccer21234
    What header file does the beep function require?
    Check your compilers documentation, or simply do a search through the .h files in your include directory.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  14. #14
    Registered User
    Join Date
    May 2003
    Posts
    15
    Also, for the duration and frequency what are the units they are measured in? Could you perhaps give me a test section of code that uses the beep function in msvc 6.0?

  15. #15
    Registered User
    Join Date
    May 2003
    Posts
    15
    Do you mean search every .h file inside of each and every one? I don't see any sound or beep .h's

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I keep the sounds playing?
    By Queatrix in forum Windows Programming
    Replies: 0
    Last Post: 07-21-2007, 11:19 AM
  2. Playing sounds...
    By yaya in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2007, 07:57 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. playing sounds in a DOS program
    By Geo-Fry in forum C++ Programming
    Replies: 1
    Last Post: 03-18-2003, 07:29 PM
  5. playing sounds in a console window
    By elfjuice in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2002, 10:30 PM

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