When grabbing the samples from a sound file, the engine squashes everything down to 44100hz mono and returns that instead, even if it's originally something else e.g. 48000hz stereo. This causes a mismatch between SoundFile.Rate / .Channels and the actual returned sample data.
To Reproduce
Grab a 48000hz stereo track, it illustrates the problem better. I've attached two files, one mp3 and one wav of some random royalty free jingle
Paste this code in a game
[ConCmd.Client]
public static async void soundtest( string file )
{
var soundFile = SoundFile.Load( file );
Assert.NotNull( soundFile );
var loaded = await soundFile.LoadAsync();
Assert.True( loaded );
var samples = await soundFile.GetSamplesAsync();
var soundOrigin = Sound.FromScreen( "core.soundscape_2d" );
var soundStream = soundOrigin.CreateStream( soundFile.Rate, soundFile.Channels );
soundStream.WriteData( samples.AsSpan() );
await GameTask.DelaySeconds( soundFile.Duration );
soundStream.Delete();
soundOrigin.Stop();
}
Start the game, run soundtest <path/to/dumbjangle.vsnd> in console
Hear it be pitched up when it shouldn't be due to bad data
Expected behavior
It should return the sound samples as-is, especially no forced mixing down from stereo to mono. That being said though, letting the developer choose options like resampling and mixing to mono might be useful/convenient in some cases, so if that's possible to add as an option that'd be nice.
Describe the bug
When grabbing the samples from a sound file, the engine squashes everything down to 44100hz mono and returns that instead, even if it's originally something else e.g. 48000hz stereo. This causes a mismatch between SoundFile.Rate / .Channels and the actual returned sample data.
To Reproduce
Paste this code in a game
soundtest <path/to/dumbjangle.vsnd>
in consoleExpected behavior
It should return the sound samples as-is, especially no forced mixing down from stereo to mono. That being said though, letting the developer choose options like resampling and mixing to mono might be useful/convenient in some cases, so if that's possible to add as an option that'd be nice.
Media/Files
sounds.zip
Additional context
Build b0aa68