Пример #1
0
        public void readHeaderFromStream(Stream stream)
        {
            long startSamplePosition = stream.Position;

            sizeInBytes = ModuleUtils.ReadDWord(stream);
            loopStart   = ModuleUtils.ReadDWord(stream);
            loopLength  = ModuleUtils.ReadDWord(stream);
            byte vol = ModuleUtils.ReadByte(stream);

            volume             = (vol >= 64) ? 1.0f : (float)vol / 64.0f;
            finetune           = (sbyte)ModuleUtils.ReadSignedByte(stream);
            type               = ModuleUtils.ReadByte(stream);
            panning            = ModuleUtils.ReadByte(stream);
            relativeNoteNumber = (sbyte)ModuleUtils.ReadSignedByte(stream);
            packedType         = ModuleUtils.ReadByte(stream);
            name               = ModuleUtils.ReadString0(stream, 22);

            length   = ((type & 0x10) != 0) ? sizeInBytes >> 1 : sizeInBytes;
            loopType = (byte)(type & 0x03);
            is16Bits = (type & 0x10) != 0;


            loopStart  = is16Bits ? loopStart >> 1  : loopStart;
            loopLength = is16Bits ? loopLength >> 1 : loopLength;
            loopEnd    = loopStart + loopLength;
            loopEnd    = (loopEnd > length) ? length : loopEnd;
            loopStart  = (loopStart > length) ? length : loopStart;

            relativeNoteNumber = 0;
            //stream.Seek(startSamplePosition + 40, SeekOrigin.Begin);
        }
Пример #2
0
 public override void ReadSampleDataFromStream(Stream stream)
 {
     sampleData.Clear();
     if (length > 0)
     {
         for (int s = 0; s < length; s++)
         {
             float sampleValue = ModuleUtils.ReadSignedByte(stream) * 0.0078125f; // 0.0078125f = 1/128
             sampleData.Add(sampleValue * ModuleConst.SOUND_AMP);
         }
     }
 }
Пример #3
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);
                }
            }
        }