FMOD.Sound.unlock C# (CSharp) Method

unlock() public method

public unlock ( IntPtr ptr1, IntPtr ptr2, uint len1, uint len2 ) : RESULT
ptr1 IntPtr
ptr2 IntPtr
len1 uint
len2 uint
return RESULT
        public RESULT unlock                  (IntPtr ptr1,  IntPtr ptr2, uint len1, uint len2)
        {
            return FMOD_Sound_Unlock(rawPtr, ptr1, ptr2, len1, len2);
        }
        public RESULT setDefaults             (float frequency, int priority)

Usage Example

Example #1
0
        private static uint GetSampleMinMax(int startSample, int sampleCount, Sound sound, int bitsPerSample, int audioChannels)
        {
            var bytesPerSample = (bitsPerSample >> 3) * audioChannels;

            var audioByte = startSample * bytesPerSample;
            var length = bytesPerSample * sampleCount;
            var ptr1 = IntPtr.Zero;
            var ptr2 = IntPtr.Zero;
            uint refLen1 = 0;
            uint refLen2 = 0;
            sound.@lock((uint) audioByte, (uint) length, ref ptr1, ref ptr2, ref refLen1, ref refLen2);

            var destination = new byte[length];
            Marshal.Copy(ptr1, destination, 0, length);

            audioByte = 0;
            var max = short.MinValue;
            var min = short.MaxValue;

            for (var currentSample = 0; currentSample < sampleCount; currentSample++) {
                for (var currentAudioChannel = 0; currentAudioChannel < audioChannels; currentAudioChannel++) {
                    var amplitude = (bitsPerSample == 16)
                        ? BitConverter.ToInt16(destination, audioByte + (currentAudioChannel * 2))
                        : (sbyte) destination[audioByte + currentAudioChannel];
                    max = Math.Max(max, amplitude);
                    min = Math.Min(min, amplitude);
                }
                audioByte += bytesPerSample;
            }

            sound.unlock(ptr1, ptr2, refLen1, refLen2);
            return (uint) ((max << 16) | ((ushort) min));
        }
Sound