https://bugs.winehq.org/show_bug.cgi?id=42546
--- Comment #9 from Huw Davies huw@codeweavers.com --- (In reply to Ivan_83 from comment #8)
Stop playing around new_buflen in DSOUND_PrimaryOpen() and do it right once for long time.
Where it's set is essentially irrelevant, what matters is the correct value. While I agree the code is a mess as it stands, it doesn't seem too unreasonable to me to have the buffer allocation in a separate helper function.
Now, back to the actual discussion in hand. https://msdn.microsoft.com/en-us/library/windows/desktop/dd370866(v=vs.85).a... states that:
The size in bytes of an audio frame is calculated as the number of channels in the stream multiplied by the sample size per channel. For example, the frame size is four bytes for a stereo (2-channel) stream with 16-bit samples.
i.e. a frame contains nChannels samples. So if we're allocating memory for n frames stored as floats, we need n * nChannels * sizeof(float) bytes.