Skip to content

Commit 770915a

Browse files
spholzflibitijibibo
authored andcommitted
Correctly calculate FAudio block alignment
This fixes music playback on FAudio 26.01. FAudio 26.01 added bounds checks to FAudioSourceVoice_SubmitSourceBuffer in 033498ab08f5a1349ed5723a47aaa87163654be6. The calculation of nBlockAlign is currently incorrect. nBlockAlign is set to the block size in bits, not in bytes, causing this new bounds check to trip. Similarly, the wav_length for sound effects is in bytes.
1 parent 33f275a commit 770915a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

desktop_version/src/Music.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class SoundTrack
137137
format.nSamplesPerSec = spec.freq;
138138
format.wFormatTag = FAUDIO_FORMAT_PCM;
139139
format.wBitsPerSample = SDL_AUDIO_BITSIZE(spec.format);
140-
format.nBlockAlign = format.nChannels * format.wBitsPerSample;
140+
format.nBlockAlign = format.nChannels * (format.wBitsPerSample / 8);
141141
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
142142
format.cbSize = 0;
143143
valid = true;
@@ -161,7 +161,7 @@ class SoundTrack
161161
format.wBitsPerSample = sizeof(float) * 8;
162162
format.nChannels = vorbis_info.channels;
163163
format.nSamplesPerSec = vorbis_info.sample_rate;
164-
format.nBlockAlign = format.nChannels * format.wBitsPerSample;
164+
format.nBlockAlign = format.nChannels * (format.wBitsPerSample / 8);
165165
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
166166
format.cbSize = 0;
167167

@@ -214,7 +214,7 @@ class SoundTrack
214214
}
215215
FAudioBuffer faudio_buffer = {
216216
FAUDIO_END_OF_STREAM, /* Flags */
217-
wav_length * 8, /* AudioBytes */
217+
wav_length, /* AudioBytes */
218218
wav_buffer, /* AudioData */
219219
0, /* playbegin */
220220
0, /* playlength */
@@ -266,7 +266,7 @@ class SoundTrack
266266
format.nSamplesPerSec = audio_rate;
267267
format.wFormatTag = FAUDIO_FORMAT_PCM;
268268
format.wBitsPerSample = 16;
269-
format.nBlockAlign = format.nChannels * format.wBitsPerSample;
269+
format.nBlockAlign = format.nChannels * (format.wBitsPerSample / 8);
270270
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
271271
format.cbSize = 0;
272272
voice_formats[i] = format;
@@ -399,7 +399,7 @@ class MusicTrack
399399
format.wBitsPerSample = sizeof(float) * 8;
400400
format.nChannels = vorbis_info.channels;
401401
format.nSamplesPerSec = vorbis_info.sample_rate;
402-
format.nBlockAlign = format.nChannels * format.wBitsPerSample;
402+
format.nBlockAlign = format.nChannels * (format.wBitsPerSample / 8);
403403
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
404404
format.cbSize = 0;
405405

0 commit comments

Comments
 (0)