Thread: Playing sound in C programs??

  1. #1
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472

    Question Playing sound in C programs??

    Hi Everyone!

    This is my first post on this great BBS.

    Is there any way to play .WAV (or any other extension) file(s) within my C programs?? i mean without having to open a media player to play that WAV file(s)..



    Thanks in Advance..
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is there any way to play .WAV (or any other extension) file(s) within my C programs??
    Yes. But with the information you've given it's impossible to tell you how.
    My best code is written with the delete key.

  3. #3
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    What kind of info do you need?? im just looking for a standard method (a function maybe?) that allows me to run audio files within any program. Or atleast point me to a tutorial that shows me how.

    I've searched for it but all what i found was for VB and some other languages..
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    there is no standard way to do it. The only sound functionality that is built into C is a system beep. You will have to look for a library or api that you like to play sound.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Under Windows it will be nearly impossible to program a sound engine. One thing you can do though is fire up DirectX and DirectSound and use DirectSound for playing WAVs.

    But if you want to code your own you will have to be in pure DOS - Windows does not like it when you program the DMA controller and service hardware interrupts. It will really screw your code up and cause it to fail giving you the false impressions that your code is broken. I've encountered this before. In Windows my sound engine died and in pure DOS it worked perfectly.

    Proceed at your own risk.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    naa it's so simple !!!!!!!!!

    http://msdn.microsoft.com/library/de...dplaysound.asp

    en example :

    sndPlaySound("C:\\WINDOWS\\Help\\Tours\\WindowsMed iaPlayer\\Audio\\Wav\\wmpaud5.wav", SND_ASYNC);

    remember the system pause coz u need time to play the sound

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Couldn't he just use SDL?
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    sndPlaySound(" C:\\WINDOWS\\Help\\Tours\\WindowsMediaPlayer\\Audi
    o\\Wav\\wmpaud5.wav", SND_ASYNC);
    Is fine for one sound. Not good from within DirectX and not good for programs that need robust sound systems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  2. How do I keep the sounds playing?
    By Queatrix in forum Windows Programming
    Replies: 0
    Last Post: 07-21-2007, 10:19 AM
  3. Play multipul sounds at once.
    By Queatrix in forum C++ Programming
    Replies: 6
    Last Post: 09-19-2006, 10:57 PM
  4. Playing sound files...
    By Yuri in forum C++ Programming
    Replies: 24
    Last Post: 05-27-2006, 05:22 AM
  5. Beats-Per-Minute in .wav file
    By loobian in forum C++ Programming
    Replies: 7
    Last Post: 12-16-2003, 10:05 PM