public @lock ( uint offset, uint length, |
||
offset | uint | |
length | uint | |
ptr1 | ||
ptr2 | ||
len1 | uint | |
len2 | uint | |
return | RESULT |
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)); }