Sponsored Content
Top Forums Programming PLaying a sound file with SDL - C++ Post 302449444 by hakermania on Monday 30th of August 2010 03:12:17 PM
Old 08-30-2010
Question PLaying a sound file with SDL - C++

How do I play a sound file with SDL?
I've downloaded the library files but SDL/SDL_mixer.h (that most of the tutorials include) doesn't exist. So, how do I install it?

As I said mixer.h doesn't exist but, If it is helpful, the default code is this:
Code:
#include "stdlib.h"
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"

int main(int argc, char *argv[])
{
        SDL_Surface *screen;
        Mix_Chunk *sound = NULL;
        int channel;
        int audio_rate = 22050;
        Uint16 audio_format = AUDIO_S16SYS;
        int audio_channels = 2;
        int audio_buffers = 4096;
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
                printf("Unable to initialize SDL: %s\n", SDL_GetError());
                return 1;
        }
        if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
                printf("Unable to initialize audio: %s\n", Mix_GetError());
                exit(1);
        }
        sound = Mix_LoadWAV("sound.wav");
        if(sound == NULL) {
                printf("Unable to load WAV file: %s\n", Mix_GetError());
        }
        screen = SDL_SetVideoMode(320, 240, 0, SDL_ANYFORMAT);
        if (screen == NULL) {
                printf("Unable to set video mode: %s\n", SDL_GetError());
                return 1;
        }
        channel = Mix_PlayChannel(-1, sound, 0);
        if(channel == -1) {
                printf("Unable to play WAV file: %s\n", Mix_GetError());
        }
        while(Mix_Playing(channel) != 0);
        Mix_FreeChunk(sound);
        Mix_CloseAudio();
        SDL_Quit();
        return 0;
}

Thanks for any replies....Smilie
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Insane question : Playing mp3 file from Sun Sparc

hi, i know this is crazy. but i can do this from linux in intel platform. just wonder can my Sun Solaris 8 sparc can do the same thing? (2 Replies)
Discussion started by: champion
2 Replies

2. UNIX for Dummies Questions & Answers

What is SDL?

I get a: Requirements: SDL when I'm browsing (www.happypenguin.org) for games. According to wikipedia SDL can be: where some are more likely than others. However, which one is it? I got an error because of SDL last time I tried and want to make it right before I try... (0 Replies)
Discussion started by: riwa
0 Replies

3. Programming

SDL doubt

Hi, I am working on SDL open-source API's on Debian Linux for my game development project. I am not sure whether posting SDL related queries here is correct. I would like to know what is the difference between: SDL_SetVideoMode() and SDL_VideoModeOK() functions (0 Replies)
Discussion started by: royalibrahim
0 Replies

4. UNIX for Dummies Questions & Answers

SDL error with the version

hi, i've just downloaded a test game to try compiling it with the gcc compiler in Solaris, the problem was that ./configure command return this error *** Could not run SDL test program, checking why... *** The test program compiled, but did not run. This usually means *** that the run-time linker... (0 Replies)
Discussion started by: freeware
0 Replies

5. Ubuntu

Playing wav-file sounds.

I would like to be able to shell out to the command line and play sounds. After installing "sox" I can now do this using the play command. Is there a way to stop the playing once it starts? (5 Replies)
Discussion started by: newyorkpaulie
5 Replies

6. Red Hat

playing sound in rhel5.1 ?

please any body tell me how to play sound using RealPlayer11 loaded in Rhel5.1? (1 Reply)
Discussion started by: rangaprem
1 Replies

7. Programming

SDL Image Filtering

Solved thanks for info!! (8 Replies)
Discussion started by: aLHaNz
8 Replies

8. Programming

Playing Video with MinGW and SDL

Hi All, I was wondering if someone could clarify the best way to display mpeg video with SDL in MinGW. After scouring the internet it seems there is not a lot of information regarding this subject (or at least not up to date) and libraries that are available for this purpose. Any help/... (1 Reply)
Discussion started by: robfwauk
1 Replies
SDL::Video(3)						User Contributed Perl Documentation					     SDL::Video(3)

NAME
SDL::Video - a SDL perl extension SYNOPSIS
$video = new SDL::Video ( -name => 'pr0n.mpg' ); DESCRIPTION
"SDL::Video" adds support for MPEG video to your SDL Perl application. Videos are objects bound to surfaces, whose playback is controled through the object's interface. METHODS o "SDL::Video::error()" returns any error messages associated with playback o "SDL::Video::audio(bool)" enables or disables audio playback, (on by default) o "SDL::Video::video(bool)" enables or disable video playback, (on by default) o "SDL::Video::loop(bool)" enables or disable playback looping (off by default) o "SDL::Video::volume(int)" set the volume as per the mixer volume o "SDL::Video:display(surface)" binds the clip to a display surface o "SDL::Video::scale([x,y]|[surface]|int)" scales the clip by either x,y factors, scales to the image dimensions, or a single scalar. o "SDL::Video::play()" plays the video clip, call "SDL::Video::display()" before playing o "SDL::Video::pause()" pauses video playback o "SDL::Video::stop()" stops video playback o "SDL::Video::rewind()" resets the clip to the beginning o "SDL::Video::seek(offset)" seeks to a particular byte offset o "SDL::Video::skip(time)" skips to a particular time o "SDL::Video::region(rect)" takes a SDL::Rect and defines the display area o "SDL::Video::frame(int)" renders a specific frame to the screen o "SDL::Video::info()" returns a new "SDL::MPEG" object reflecting the current status o "SDL::Video::status()" returns either SMPEG_PLAYING or SMPEG_STOPPED or SMPEG_ERROR AUTHOR
David J. Goehrig SEE ALSO
perl(1) SDL::Surface(3) SDL::MPEG(3) perl v5.12.1 2010-07-05 SDL::Video(3)
All times are GMT -4. The time now is 08:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy