[sldev] Blowing wind

Aimee Trescothick aimee.trescothick at gmail.com
Tue Dec 8 11:53:10 PST 2009


Can anyone explain how the below piece of the existing code from the wind noise synthesizer has ever actually worked properly, with MIXBUFFERFORMAT_T defined as S16 and stride set to 4 bytes?

    U8 *cursamplep = (U8*)newbuffer;
...

    MIXBUFFERFORMAT_T sample;
...

    sample = llfloor(((F32)nextSample*32768.f*(1.0f - mCurrentPanGainR))+0.5f);
    *(MIXBUFFERFORMAT_T*)cursamplep = llclamp(sample, (MIXBUFFERFORMAT_T)-32768,
                                                  (MIXBUFFERFORMAT_T)32767);
    cursamplep += stride;

    sample = llfloor(((F32)nextSample*32768.f*mCurrentPanGainR)+0.5f);
    *(MIXBUFFERFORMAT_T*)cursamplep = llclamp(sample, (MIXBUFFERFORMAT_T)-32768,
                                                  (MIXBUFFERFORMAT_T)32767);
    cursamplep += stride;

On Windows and Linux MIXBUFFERFORMAT_T is defined as S16, and if the FMOD mixer mode is FSOUND_MIXER_QUALITY_FPU or FSOUND_MIXER_BLENDMODE, stride is set to 4 bytes, as these modes both use a 32-bit mix buffer.

But as far as I can see, that's just going to write signed 16-bit integers into the first two bytes of the 4-byte sample, skipping over the other two bytes, leaving them at whatever they were before (zero, as wind is the first thing that goes in the buffer after it is cleared).  When FMOD tries to read the 4-bytes back as either 32-bit signed integers (FSOUND_MIXER_BLENDMODE), or 32-bit float (FSOUND_MIXER_QUALITY_FPU) that's just going to go horribly wrong.

MIXBUFFERFORMAT_T is only defined as S32 on the Mac, on Windows and Linux it is S16 as one of FMOD's 16-bit MMX mixers is normally used. The only time I would imagine this situation occurs is on a PC without MMX (or when LL_VALGRIND is defined on Linux for testing, which specifically forces the mixer mode to FSOUND_MIXER_QUALITY_FPU).

If this has never worked anyway, it would seem to make sense to turn off the wind generator for these mixer modes to avoid making a horrible noise, drop the striding which will simplify things elsewhere, and just declare cursamplep as MIXBUFFERFORMAT_T in the first place, removing the need to typecast it ... or am I missing something?

(If you followed me this far you're doing better than I am :)

Aimee.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.secondlife.com/pipermail/sldev/attachments/20091208/3afcd927/attachment.htm 


More information about the SLDev mailing list