Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Audio error
- - By danikaze Date 2011-11-03 18:27 Edited 2011-11-04 10:11

I think this is a quite weird error since I haven't seen anything about it in the forum, but this is what I get... ^^'

I get an error when creating a new Song or Sample. No matter the file is .mp3 or .wav it crashes.

I uploaded an image so you can see the error clearly.

As you can see in the code, the file exists and crashes when trying Gosu::Song(f).

So... does anybody know anything about it?
Parent - - By jlnr (dev) Date 2011-11-03 20:37
There are many variations of WAV files. Can you try to save it again with e.g. Audacity as a 22kHz PCM WAV file? Those seem to be the most common.
Parent - - By danikaze Date 2011-11-04 01:19
Tried! And didn't work either.

I also tried with mp3, but nothing works...

May I include any library besides gosu libs?
Parent - - By jlnr (dev) Date 2011-11-04 10:51
Oh right, you need libsndfile.dll to be next to your EXE file. It ships with Gosu. That may just be it. :)

MP3 is not supported, by the way. (
Parent - - By RunnerPack Date 2011-11-05 06:12
Did you go here, jlnr?

I don't know if it changes anything as far as adding support to libgosu, I just thought the "no royalties for less than 5000 units sold" thing was interesting...
Parent - - By jlnr (dev) Date 2011-11-05 12:21
Yeah, it is still annoying to have to think about it, just like FMOD before. :/

AAC seems to be a more relaxed choice if you want a format that works across all four platforms (iOS included):

Otherwise, OGG is good enough even for OGG haters like me. :) (Contributions are still welcome.)
Parent - By danikaze Date 2011-11-07 15:23
I was thinking about using ogg in the proyect, I will consider aac too.
Anyway, I was using a .wav for testing the code...
Parent - - By danikaze Date 2011-11-06 00:34

After adding the library the song loads, but it doesn't play.

_song.reset(DNEW Gosu::Song(filename.string()));

but I can't hear anything, and the Windows 7 volume mixer doesn't show anything either about my app using sound.

One more thing: if I try to stop the song:
it hangs.

And yes, playing() returns true...
Parent - - By jlnr (dev) Date 2011-11-06 11:37
Hmmm, can you show some more code? Or upload the music file?
Parent - - By danikaze Date 2011-11-06 16:02

I uploaded the wav file.

About the code, there's no much to show, but I tested a little more:

if(boost::filesystem::exists(absolutePath() + L"data/bgm/m.wav"))
  cout << "a";
  Gosu::Song s(absolutePath() + L"data/bgm/m.wav");
  cout << "b";;
  cout << "c";
cout << "-done" << endl;

The output was... "abc" but not "-done".
Attachment: m.wav (3840k)
Parent - - By jlnr (dev) Date 2011-11-07 11:33
But this cannot work because it will play the song only while the computer is printing "c", so, about 2ms? :) What if you add Gosu::sleep(100) after the call?
Parent - - By danikaze Date 2011-11-07 14:46
Does it means that a song can't play in the background?
Or how it works?

Anyway, adding a sleep(100) after the play() call doesn't change anything :(
Parent - - By jlnr (dev) Date 2011-11-07 15:04
It can, but not if you destroy it right after calling play(). :) If you use a Window, then you can use a scoped_ptr (or the new unique_ptr or anything else) to load and play it. Gosu::Window internally continues feeding the Song with new data.
Parent - - By danikaze Date 2011-11-07 15:21
yeah, it's true!

But anyway, I tested it before using a pointer and I got the problem of the stop() and it dosn't sound.

Here's the fixed code:

global variable:
Gosu::Song *song;

In the Window constructor:

song = new Gosu::Song(absolutePath() + L"data/bgm/m.wav");    // this is ok

In the Window update()

if(input().down(Gosu::kbA) && !song->playing())
  cout << "play" << endl;      // prints "play" ok
  song->play();          // but doesn't sound anything
if(input().down(Gosu::kbZ) && song)
  cout << "stop" << endl;      // prints "stop" ok
  cout << "delete" << endl;      // this line is never reached
  delete song;
  song = NULL;
Parent - - By jlnr (dev) Date 2011-11-07 17:27
If this line is never reached, then what happens? Do you get any exception or error message?
Parent - - By danikaze Date 2011-11-08 16:49
it just hang on song->stop()... no error displayed.

EDIT: Now it displayed "delete", but it hangs on delete song; ... kinda weird...
Parent - - By Maverick Date 2011-11-08 22:03
Does any of this change when you use boost::shared_ptr<Gosu::Song> song instead?
Parent - By danikaze Date 2011-11-10 19:37
No, nothing changes. Actually, the 1st test where I saw the error was using shared_ptr...
Parent - - By jlnr (dev) Date 2011-11-09 13:08
For some reason, I cannot load the file on OS X either. (Constructor fails) Saving it as AAC/M4A from Audacity works for me. Is the same true on Windows?

I used to have a table for supported audio formats in the wiki (automated) but I hoped sndfile & AudioToolkit could digest everything by now :S
Parent - - By danikaze Date 2011-11-10 19:38
I saved it as AAC/M4A too with audacity and didn't work.
Could you upload your working file? I'll try it. Maybe it's problem of Audacity format saving.
Parent - - By jlnr (dev) Date 2011-11-10 20:43
Actually, it's no wonder that it didn't work. AAC is probably only supported on OS X.

So here's what I'm doing. On all platforms, I use my own code with libogg & libvorbis to play OGG files. On OS X, I use the system's AudioToolKit to play everything else. On Linux and Windows, I use libsndfile.

If the AAC doesn't work, it just means libsndfile doesn't support AAC, no big surprise. If the OGG file doesn't work, then things are really weird because we should be having the same results. :S I have attached both.
Attachment: m.m4a (289k)
Attachment: m.ogg (302k)
Parent - - By danikaze Date 2011-11-10 21:37

m4a give me an error loading the file (unhandled exception: std::runtime_error).
ogg loads but don't play (no error but no sound) and still hangs on stop().

So, it's no my Audacity... maybe something on Windows 7?
Parent - - By Maverick Date 2011-11-10 22:30
I haven't had a problem playing music on Windows 7.

Do you have the right DLLs located in the folder too? They could be mis-matched and out-dated...
Parent - - By danikaze Date 2011-11-10 22:41
Uhm... I had the right Dlls in the right folder, but anyway I copied them again (and replaced) and now it works...
probably it was what you said: outdated libraries.

Aaaahg, I hate this stupid-errors with easy solutions but hard to find!

Parent - By Maverick Date 2011-11-10 23:23
No probs.
Parent - - By danikaze Date 2011-11-13 00:39
By the way, on "Release" compilation there's no problem, but on "Debug" one, the program hangs freeing the Gosu::Song object.

I think this was already posted, but I want to be sure it's a known bug ;)
Parent - - By jlnr (dev) Date 2011-11-13 01:47
So in Debug, it hangs even with the updated DLLs? So far, I have only heard about Gosu using the wrong DLL on Windows 7, and I still have to read the article about how Windows 7 chooses DLL files.
Parent - - By danikaze Date 2011-11-13 15:40 Edited 2011-11-13 16:13
I'll try it in Windows Vista tomorrow and tell you then.

BTW, I got another error, loading a Song with loop = true  (only in Debug, in Release is ok).
When the song finished and is going to be played again from the beginning I got this:

Assertion failed: section == 0, file C: \Documents and Settings\Julian Raschke\Desktop\gosu\GosuImpl/Audio/OggFile.hpp, line 94
Parent - - By jlnr (dev) Date 2011-11-13 22:42
Agh, I thought I'd removed that assertion already. I'll try to sneak it into the next release. I was being overly cautious there.
Parent - - By danikaze Date 2011-11-14 00:37
well, don't worry, it's not a big fault ;)
And I think nobody will release games in Debug mode :P
Parent - - By Maverick Date 2011-11-14 02:00
Challenge Accepted
Parent - By danikaze Date 2011-11-14 13:53
Up Topic Gosu / Gosu Exchange / Audio error

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill