Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.6.0: Looping sound issue #2244

Open
ivan-mogilko opened this issue Nov 28, 2023 · 7 comments
Open

3.6.0: Looping sound issue #2244

ivan-mogilko opened this issue Nov 28, 2023 · 7 comments
Labels
backend: sdl2 related to sdl2 library context: audio type: bug unexpected/erroneous behavior in the existing functionality

Comments

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Nov 28, 2023

Problem

There have already been a report about looping sound before (#501), but it was closed after considered to be a "false alarm", or not engine's issue.
EDIT: also it seems to be reported long before 3.6.0 was out, so it was not related to the new audio system.

But recently another user reported a problem with the looping sound again. I tested it, and confirm that it's indeed happening in 3.6.0+, while playing nicely in previous versions (3.5.1 and lower).

Here's the sound file in question:
VacuumNoise.zip

Here's a user's recording of playing this sound in 3.5.1.14:
Looping_sound_AGS_3-5-1-14.zip

Here's a user's recording of playing this sound in 3.6.0.53:
Looping_sound_AGS_3-6-0-0-53.zip

To Reproduce

Simply import into AGS, and play repeatedly on start or room enter, e.g.

aVacuumNoise.Play(eAudioPriorityNormal, eRepeat);

There's an obvious question of how to diagnose this problem. Theoretically I see few potential places where the mistake may take place:

  1. Sound decoding.
  2. Looping playback.
    2.1. Result of our "audio slot" work;
    2.2. Result of mojoAL playback.

My thought is to add a "sound debug" mode in the engine that would write decoded sound into a file, separately from the OpenAL playback. This will let see the soundwave of a decoded data itself.
As for playback, the good thing is that SDL supports "Direct-to-disk Audio" device, which will write the engine's audio output to "raw" file (format is 32-bit float PCM), which may then be imported to a sound editing program such as "Audacity". If that would not be enough, perhaps it may be possible to add our own output for data processed in "audio slot" before it's given to MojoAL.

NOTE: I assign this to 3.6.1 Milestone, but if a fix is found soon enough, then it may as well be backported to 3.6.0 batch and another patch released.

May or not be related to #1978.


UPDATE:
This is a SDL_Sound issue: icculus/SDL_sound#92

@ivan-mogilko ivan-mogilko added type: bug unexpected/erroneous behavior in the existing functionality context: audio labels Nov 28, 2023
@ivan-mogilko ivan-mogilko changed the title 3.6.0: Looping sound issue (2) 3.6.0: Looping sound issue Nov 28, 2023
@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Nov 30, 2023

After experimenting a bit I found that this is caused by the decoded sound being slightly longer than the original file.

To prove that I run an non-looping sound and wrote result of our SDLDecoder class into a file. Here's a raw wave data, which may be imported into a sound software as 32-bit float 44100 hz PCM:
test.zip

It has roughly 0.006 s of trailing silence, that is matching the length of gaps found in a game's audio output recorded by user.

(I shall add the ability to write such SDLDecoder or AudioCoreSlot output as an option to the engine, to simplify testing further similar cases.)

At this point it looks like the root of the problem is inside SDL_Sound library (or any SDL2 utils used by SDL_Sound).

EDIT: right, I forgot to note, that the input sound is 48 kHz, while it's being converted on playing to 44 kHz.
But the problem exists earlier, before converting the frequency.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Nov 30, 2023

UPD: looks like this is related how SDL_Sound loads the original 48 kHz file. It adds a small piece of silence in the end, which results in audible "gaps" when looping.
I converted original clip to 44 kHz and it looping without gaps.

For instance, Audacity loads the sound fine without appending anything.

@ericoporto
Copy link
Member

ericoporto commented Nov 30, 2023

If you can reproduce this using either SDL_Sound or mojoAL alone, its useful to report upstream.

Edit: is this related to #1696?

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 1, 2023

I had a misunderstanding, the problem exists before converting from 48 kHz to 44 kHz.
For some reason I had a false memory of SDLDecoder converting everything to 44 kHz, but it loads sound as-is if it's in the range of supported formats.
So in this case SDLDecoder actually loads a 48 kHz sound, already appending a small bit of silence in the end.

This may be seen if you import attached "test.raw" file in Audacity, providing matching specs: 32-bit float 48 kHz 2 channel PCM.
The opened sound wave is matching the original file VacuumNoise.ogg in everything except the tiny bit of silence in the end, about 0.005 to 0.006 seconds long.

This is before passing further into mojoal, so not related to the playback device at all.

EDIT: I shall make a test program that writes a result of Sound_Decode to file.

@ivan-mogilko
Copy link
Contributor Author

Opened an issue for SDL Sound:
icculus/SDL_sound#92

@ivan-mogilko ivan-mogilko added the backend: sdl2 related to sdl2 library label Dec 1, 2023
@ericoporto
Copy link
Member

ericoporto commented Mar 5, 2024

I think my PR there will be merged soon, in my tests it fixes the issue. (If you could test building my sdl_sound branch it would help making sure I haven't screwed anything)

@ericoporto
Copy link
Member

ericoporto commented Mar 5, 2024

Made a branch for testing (here) with the change that will build here: https://cirrus-ci.com/build/5161767643381760

Web version here: https://ericoporto.github.io/agsjs/sdl_sound_issue_92
(latest 3.6.1 release for comparison https://ericoporto.github.io/agsjs)

Here is the test game: LoopVaccum.ags.zip

From listening I can't honestly tell the difference...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: sdl2 related to sdl2 library context: audio type: bug unexpected/erroneous behavior in the existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants