Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Problem streaming ogg vorbis music after switching to Direct Sound device

mvhooren
Registered User
Quote
2014-06-04 11:24:25

We recently switched to using a Direct Sound device as our default sound device (we were using a WinMM device before, which caused other problems: http://www.ambiera.com/forum.php...

When playing music in our game we check every frame if the music has stopped playing using the ISound::isFinished() function, in which case we start a new track.

However, after switching to Direct Sound, isFinished returns true after only a few seconds of streaming, long before the song is done. Switching back to WinMM fixes this, but I'd rather not do that.

Our music is encoded as OGG Vorbis, variable bitrate, ~160Kbps, 2 channels, 44.1 KHz sampling rate and lossy compression.


mvhooren
Registered User
Quote
2014-06-04 13:53:05

I investigated a little further because only some of our music appeared to have this problem.
The difference was that the problem only occurs if the music is NOT set to loop.

However, since we require some of our music to not loop, we cannot solve it by simply setting everything to loop.


niko
Moderator
Quote
2014-06-04 19:52:13

Hm, that's strange. Maybe you could send me the file, and I'll have a look at that. Something like that hasn't been reported before.


mvhooren
Registered User
Quote
2014-06-05 12:27:04

While trying to create a repro case, I found a solution to the problem.
We don't use ESEO_MULTI_THREADED and we were updating the ISoundEngine too often from our own thread. (About 180x per second).

To reproduce the issue in the MusicPlayer sample:

Replace the createIrrKlangDevice call with:

SoundEngine = createIrrKlangDevice(ESOD_DIRECT_SOUND, 0);

So no ESEO_MULTI_THREADED.

Now add an update thread above main:

include <windows.h>

void irrklangThreadUpdateFunction(void*)
{
while (true)
{
SoundEngine->update();
Sleep(5);
}
}

below createIrrKlangDevice, add:
DWORD threadID = 0;
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)irrklangThreadUpdateFunction, NULL, 0, &threadID);

Now if you increase the Sleep duration to 10 or more, the music will play fine, but at about 8ms or lower things will break. (Works with the sample getout.ogg)
If you change the device to ESOD_WIN_MM, the music will play fine regardless of update speed.


mvhooren
Registered User
Quote
2014-06-05 12:34:20

Also, make sure the sound is not set to loop:
CurrentPlayingSound = SoundEngine->play2D(filename, false, false, true);


niko
Moderator
Quote
2014-06-06 05:38:54

Ah, thanks, that's interesting. Yes, the update function was supposed to be called 2 or 3 times a second. More often should work as well, but apparently, calling it that often breaks something. Will have a look at this, as workaround, simply try not to call that update function that often. (Add a counter, maybe)


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact