Exemple #1
0
        // NOTE : this function load regular delta packed sample data
        // TODO : need to do loading of AD = 4-bit ADPCM-compressed sample data
        public void readSampleDataFromStream(Stream stream)
        {
            sampleData.Clear();
            float ampDivider = ((type & 0x10) != 0) ? 0.000030517578125f /* 1/32768 */ : 0.0078125f /* 1/128 */;

            if (length > 0)
            {
                float oldValue = 0;
                for (uint i = 0; i < length; i++)
                {
                    float sampleValue;
                    sampleValue = ((type & 0x10) != 0) ? ModuleUtils.ReadSignedWordSwap(stream) : ModuleUtils.ReadSignedByte(stream);
                    oldValue   += sampleValue * ampDivider;
                    if (oldValue < -1)
                    {
                        oldValue += 2;
                    }
                    else if (oldValue > 1)
                    {
                        oldValue -= 2;
                    }
                    sampleData.Add(oldValue * ModuleConst.SOUND_AMP);
                }
            }
        }