SDL audio code

Pages: 1234
Make sure the Mix_OpenAudio returns 0 and Mix_LoadMUS (or whatever load function you use to load the wav file) doesn't return null.
closed account (NUj6URfi)
I tried that just now but my thing says that it couldn't convert to a bool and iso-c++ forbids pointers and something else.
closed account (NUj6URfi)
I got rid of the ifs. Please help.
closed account (NUj6URfi)
Please?
same problem here.... still not clear.... so please help me..
I mean something like this:

1
2
3
4
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
{
	std::cout << Mix_GetError() << std::endl;
}

1
2
3
4
5
music = (Mix_LoadMUS("Aw screw that.wav");
if (music == 0)
{
	std::cout << Mix_GetError() << std::endl;
}


EDIT: Fixed the mistake pointed out by EssGeEich.
Last edited on
If Mix_OpenAudio fails, it returns -1.
EDIT: Fixed
Last edited on
closed account (NUj6URfi)
cout doesn't appear on sdl windows.
I don't think that's a surprise to anybody.
Open a SDL window while keeping the console up.
closed account (NUj6URfi)
How?
closed account (N36fSL3A)
Did you disable the console? Look on Setting up SDL on <insert IDE/compiler here>" on lazyfoo.net, and omit the step where it says "disable the console".

Also, I highly recommend you to not use SDL_mixer. It's seriously crap, that's why I stopped using it. Use OpenAL for audio.
Last edited on
closed account (NUj6URfi)
Where do you download openAL and can you post the code to load and play a wav file?
Eeeh, OpenAL isn't even free software in latest versions.

Anyhow, .. SDL on Windows redirects all output to the files stdout.txt and stderr.txt so you have look in there to see the output. I think the files are deleted after the program has ended so I you have to read it while the program is running, or it might not be deleted if you end the program using std::exit(1);. http://en.cppreference.com/w/cpp/utility/program/exit

Alternatively you can read here how to enable console output.
http://sdl.beuc.net/sdl.wiki/FAQ_Console
I'm using Bass (Un4seen) since a couple of years, didn't have any troubles with it (It also supports Unicode filenames and loading from memory).

BASS is also available for the Win64, WinCE, iOS, Android, and ARM Linux platforms.


http://www.un4seen.com/bass.html
Last edited on
closed account (NUj6URfi)
How do you use bass to load a .wav file?
Basically (After you set your IDE up):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bass.h>

int main()
{
    HSTREAM your_audio_stream = BASS_StreamCreateFile(0,
        "path\\to\\your\\sound\\file",0,0,0); // load it
    if(your_audio_stream)
    {
        BASS_ChannelPlay(your_audio_stream,1); // play it
        while(BASS_ChannelIsActive(your_audio_stream) == BASS_ACTIVE_PLAYING)
        // is it still playing?
        {
            Sleep(0); // while the sound is playing, wait a bit.
        }
    }
    BASS_StreamFree(your_audio_stream); // we don't need you anymore
    BASS_Free();
    return 0;
}


Besides, if you go into the "c" folder, you have the examples.
The compiled examples are in the "c\bin" folder.
You also have a .chm guide file.
It also works with MP3 and OGGs.
If you plan on using plugins, you're able to play a wider variety of files (FLAC and WMA mainly).

I posted an example recently in another topic, but it was for layered windows.
This example features the Bass library.
/!\ This is an EXECUTABLE file! Please SCAN IT WITH AN ANTIVIRUS BEFORE RUNNING IT! /!\
https://dl.dropboxusercontent.com/u/83943521/Apps/layered.rar

The Bass features used in this examples are the loading and playing of a sound file (obviously) and also it gets me the spectrum of the currently playing sound at the currently playing place.

Cold circles = Basses playing
Hot circles = Highs playing

Another example featuring plugins is here:
/!\ This is an EXECUTABLE file! Please SCAN IT WITH AN ANTIVIRUS BEFORE RUNNING IT! /!\
https://dl.dropboxusercontent.com/u/83943521/Apps/CSP.rar
Last edited on
closed account (NUj6URfi)
Bass_ChannelFree returns an error.
My mistake, change it with BASS_StreamFree.
closed account (N36fSL3A)
Remember, Bass isn't free for commercial use.
closed account (NUj6URfi)
I know.
Pages: 1234