Пример #1
0
        public unsafe AudioBuffers(int count)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            //
            // AudioBufferList is a int + array of AudioBuffer (int + int + intptr).
            // However due to alignment, the array of AudioBuffer comes at position 8
            // in 64bit architectures, which is why we're using IntPtr.Size here
            // in order to calculate the total size / position of the AudioBuffer elements.
            //

            var size = IntPtr.Size + count * sizeof(AudioBuffer);

            address = Marshal.AllocHGlobal(size);
            owns    = true;

            Marshal.WriteInt32(address, 0, count);
            AudioBuffer *ptr = (AudioBuffer *)(((byte *)address) + IntPtr.Size);

            for (int i = 0; i < count; i++)
            {
                ptr->NumberChannels = 0;
                ptr->DataByteSize   = 0;
                ptr->Data           = IntPtr.Zero;
                ptr++;
            }
        }
Пример #2
0
        public unsafe AudioBuffers(int count)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            var size = sizeof(int) + count * sizeof(AudioBuffer);

            address = Marshal.AllocHGlobal(size);
            owns    = true;

            Marshal.WriteInt32(address, 0, count);
            AudioBuffer *ptr = (AudioBuffer *)(((byte *)address) + sizeof(int));

            for (int i = 0; i < count; i++)
            {
                ptr->NumberChannels = 0;
                ptr->DataByteSize   = 0;
                ptr->Data           = IntPtr.Zero;
                ptr++;
            }
        }