Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Sounds playing at wrong speeds

superku
Registered User
Quote
2017-10-28 12:26:15

Hello!
I'm using irrKlang for my game running on the Gamestudio A8 engine (32 bit), written in lite-C. My irrKlang wrapper is written in C++ using Visual Studio Community 2015 (and irrKlang-lib-1.5.0-vs2015-32bit-mt). It's a Windows only game.
I create the sound engine like this:

createIrrKlangDevice(ESOD_AUTO_DETECT, 0, 0); // update function in 2nd thread

It picks DirectSound8 on my machine (Win 10 64bit).
Sounds are played as follows:

irrKuEngine->play2D(file, loop, true, true, ESM_AUTO_DETECT, false); // ogg files only, longer than a second

I have a slow motion/ focus ability which slows down (to 0.5 speed) most sounds as well (or speeds them up back to 1.0 again), using setPlaybackSpeed().


Oftentimes however, when a sound has been played at speed < 1.0, subsequent play2D calls of the same file will be played at some low speed erroneously (between 0.5 and 1.0 - always the same speed then though), although the focus speed has already been lerped back to 1 again (meaning it's started at and set to a playback speed of 1).
getPlaybackSpeed() returns 1.0 for those sounds.
They will be played at the wrong speed up until all instances of that sound (file) have stopped (isFinished-> drop), then the speed will be correct (1.0) again on the next call(s). EDIT: >I'm not using SoundSources for now.<
The problem happens on multiple/ different sound files, seemingly at random.

Can you reproduce and look into this? It may take only 10 or up to 100-200 play2D calls for the problem to appear. I hope it's not some internal DirectSound8 issue.

Thanks for reading.


niko
Moderator
Quote
2017-10-29 05:09:31

Interesting, that's strange, thanks for reporting. Will see what I can do. Could be a driver issue, btw, did you try to replace ESOD_AUTO_DETECT with ESOD_WIN_MM and see if this happens then still? If not, then this is a driver issue and not irrKlang's fault.

You could try to set the playback speed for every sound when starting a sound, maybe this would be a workaround.


superku
Registered User
Quote
2017-10-29 09:48:04

Thanks for the response!

Using ESOD_WIN_MM the bug does not occur and setting the playbackSpeed seems to work fine.
Sadly this driver seems to have its own issues, that is random crackling every now and then (like a sound that ends with non-zero amplitude), other strange noises and a delay on every sound that I play (by 200ms+).

When I compared the results of ESOD_WIN_MM and ESOD_DIRECT_SOUND(_8) I noticed something though: Using ESOD_DIRECT_SOUND(_8) the sound "breaks" during slow mo on playback start, not when I return to normal speed again. I play a sound on 0.5 speed for the first time it plays fine. The next play2D call of the same sound file may break (assuming that the previous sound is still playing) in the sense that it seems to take the previous sound instance's audio as the source, then apply the playback rate modifier on top of that (bringing it down to ~ 0.25 speed). When the game returns to normal speed, these instances will be sped up as well (from 0.25 to 0.5 I guess). Results for initial speeds between 0.5 and 1.0 are analogous.

You could try to set the playback speed for every sound when starting a sound, maybe this would be a workaround.

This is what I'm doing, just for the sake of completeness:
DLLFUNC ISound* irrKuPlay2D2(const char* file, bool loop, float volume, float pan, float speed)
{
ISound* sndResult = irrKuEngine->play2D(file, loop, true, true, ESM_AUTO_DETECT, false);
if (sndResult)
{
sndResult->setVolume(volume);
sndResult->setPan(pan);
sndResult->setPlaybackSpeed(speed);
sndResult->setIsPaused(false);
}
return sndResult;
}


I only had a quick look at DirectSound but can you please double check the appropriate/ corresponding play and buffer(.write?) code? Does it maybe clone the buffer if there's already an instance of that sound in an erroneous way under some circumstances (unlikely because of the randomness of the issue, I know - but still)?

Thanks again.


niko
Moderator
Quote
2017-10-31 07:37:19

Checked, code looks alright. That's really strange, especially since you are the first one to report such a problem (and a lot of apps and games are using irrklang). Are you sure that 'speed' parameter of yours is set correctly, always?

And when you are using that irrKuPlay2D2 function, it still does that? Really strange.


superku
Registered User
Quote
2017-11-01 11:51:20

Are you sure that 'speed' parameter of yours is set correctly, always?

Yes, sure. getPlaybackSpeed() returns the correct speed value as well.
I'm always only using the irrKuPlay2D2() function to play my sound effects. Despite all the drawbacks of using ESOD_WIN_MM the speed modulation works correctly with that driver.

I just noticed something else though (ESOD_DIRECT_SOUND_8):
When I play a sound file and there's no other instance of that sound effect running, getPlayPosition() and getPlayLength() return the correct values. However, subsequent play2D calls (all of them) will return -1 for getPlayPosition (but the correct length, and isFinished() still works for them). This continues until all instances of that sound file have stopped (meaning it can show -1 for all instances and no correct PlayPosition for any of them). Afterwards the first instance will show the correct PlayPosition again.
Using ESOD_WIN_MM getPlayPosition() returns the correct position for all instances.

//! returns the current play position of the sound in milliseconds.
/** \return Returns -1 if not implemented or possible for this sound for example
because it already has been stopped and freed internally or similar. */
virtual ik_u32 getPlayPosition() = 0;


What does that all mean for me and that issue?


niko
Moderator
Quote
2017-11-05 06:54:50

It looks like something in your DirectSound is broken. Not sure why. You could try if this also happens on another PC. If not, than you have probably a broken audio driver. Updating it might help.


superku
Registered User
Quote
2017-11-05 11:52:02

Reinstalled everything, same issue.
Made a small self contained example, tested it on various PCs. Same issue on all of them (Win 10, Win 8.1, Win 7).

How does the first (concurrent) sound (instance) differ from subsequent play calls (with DirectSound)?

EDIT: Tried different sound formats/ rates/ bits... as well, no luck.

EDIT 2: I've tried forceReloadAtNextUse() on sound.getSoundSource() (nothing changed) and compared data of its SoundSource itself.

DLLFUNC int irrKuGetSoundSourceData(ISound* snd, char* cname, int* istreamMode, int* channelCount, int* frameCount, int* sampleRate, int* sampleSize)
{
ISoundSource *source = snd->getSoundSource();
if (!source) return 0;

strcpy(cname,source->getName());
E_STREAM_MODE estreamMode = source->getStreamMode();
*istreamMode = (int)estreamMode;

SAudioStreamFormat format = source->getAudioFormat();
*channelCount = format.ChannelCount;
*frameCount = format.FrameCount;
*sampleRate = format.SampleRate;
*sampleSize = format.getSampleSize();

return 1;
}

No changes on the data as expected.

EDIT 3: Although it's probably clear and obvious that the error happens on play and not with the SoundSource, I've tried addSoundSourceFromMemory (copyMemory true/ false) as well.

EDIT 4: Could it be that no one else has reported this problem so far as I'm using the irrKlang-"lib-1.5.0-vs2015-32bit-mt" library you sent me (in January 2016)?


niko
Moderator
Quote
2017-11-06 12:29:48

Ah, maybe that might be the problem. If you are using the .dll version, then you don't get the problem?


superku
Registered User
Quote
2017-11-06 18:44:30

Sadly the issue remains. :( (DLL: 32bit-1.5.0, May 2014)

Is there any compiled example I could try? Or anything else that I could do?


niko
Moderator
Quote
2017-11-08 16:50:39

Really strange, yes, it could be that you spotted a bug which hasn't been reported yet. Will investigate, this will take a bit.


superku
Registered User
Quote
2017-11-08 21:19:34

Thanks a lot! Let me know if there's something I could test/ try for you.


superku
Registered User
Quote
2017-11-29 10:31:12

Have you had time to look into this issue yet?

Just tried my luck and used the 1.4.0b DLL instead, same result.


niko
Moderator
Quote
2017-11-29 19:15:37

No, sorry, not yet


superku
Registered User
Quote
2017-12-15 21:26:13

Just FYI:
Started to write my own DirectInput(8) implementation yesterday. I've probably done some things suboptimally at best but right now it's working (in a test project at least).
Sounds are created from memory. If there's an instance of a sound already I use DuplicateSoundBuffer() to create further instances - which I assume you are doing as well. This is working with various speeds and GetPosition() functions, sounds have never been distorted (so far).

Unless this starts to fail for me further on I have to conclude for now that this might be a bug in the irrKlang DirectSound8 implementation.


niko
Moderator
Quote
2018-01-29 10:58:15

Update: I was able to reproduce and fix this finally, this will be fixed in the next update.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internat?onal" (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