SDL audio code

Pages: 1234
Aug 4, 2013 at 8:14am
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.
Aug 4, 2013 at 12:59pm
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.
Aug 6, 2013 at 10:08pm
closed account (NUj6URfi)
I got rid of the ifs. Please help.
Aug 7, 2013 at 12:30am
closed account (NUj6URfi)
Please?
Aug 7, 2013 at 10:11am
same problem here.... still not clear.... so please help me..
Aug 7, 2013 at 5:36pm
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 Aug 7, 2013 at 8:10pm
Aug 7, 2013 at 7:02pm
If Mix_OpenAudio fails, it returns -1.
EDIT: Fixed
Last edited on Aug 7, 2013 at 10:06pm
Aug 7, 2013 at 10:01pm
closed account (NUj6URfi)
cout doesn't appear on sdl windows.
Aug 7, 2013 at 10:06pm
I don't think that's a surprise to anybody.
Open a SDL window while keeping the console up.
Aug 7, 2013 at 11:15pm
closed account (NUj6URfi)
How?
Aug 7, 2013 at 11:59pm
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 Aug 8, 2013 at 12:23am
Aug 8, 2013 at 12:33am
closed account (NUj6URfi)
Where do you download openAL and can you post the code to load and play a wav file?
Aug 8, 2013 at 7:37am
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
Aug 8, 2013 at 11:05am
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 Aug 8, 2013 at 11:06am
Aug 8, 2013 at 9:25pm
closed account (NUj6URfi)
How do you use bass to load a .wav file?
Aug 8, 2013 at 9:32pm
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 Aug 8, 2013 at 10:14pm
Aug 8, 2013 at 9:56pm
closed account (NUj6URfi)
Bass_ChannelFree returns an error.
Aug 8, 2013 at 10:13pm
My mistake, change it with BASS_StreamFree.
Aug 9, 2013 at 12:34pm
closed account (N36fSL3A)
Remember, Bass isn't free for commercial use.
Aug 9, 2013 at 8:41pm
closed account (NUj6URfi)
I know.
Pages: 1234