Exemplo n.º 1
0
        public SoundBank(AudioEngine audioEngine, string filename)
        {
            if (audioEngine == null)
            {
                throw new ArgumentNullException("audioEngine");
            }
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }

            byte[]   buffer = TitleContainer.ReadAllBytes(filename);
            GCHandle pin    = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            FAudio.FACTAudioEngine_CreateSoundBank(
                audioEngine.handle,
                pin.AddrOfPinnedObject(),
                (uint)buffer.Length,
                0,
                0,
                out handle
                );

            pin.Free();
            buffer = null;

            engine        = audioEngine;
            selfReference = new WeakReference(this, true);
            dspSettings   = new FAudio.F3DAUDIO_DSP_SETTINGS();
            dspSettings.SrcChannelCount     = 1;
            dspSettings.DstChannelCount     = engine.channels;
            dspSettings.pMatrixCoefficients = Marshal.AllocHGlobal(
                4 *
                (int)dspSettings.SrcChannelCount *
                (int)dspSettings.DstChannelCount
                );
            engine.RegisterSoundBank(handle, selfReference);
            IsDisposed = false;
        }
Exemplo n.º 2
0
        public SoundBank(AudioEngine audioEngine, string filename)
        {
            if (audioEngine == null)
            {
                throw new ArgumentNullException("audioEngine");
            }
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }

            IntPtr bufferLen;
            IntPtr buffer = TitleContainer.ReadToPointer(filename, out bufferLen);

            FAudio.FACTAudioEngine_CreateSoundBank(
                audioEngine.handle,
                buffer,
                (uint)bufferLen,
                0,
                0,
                out handle
                );

            FNAPlatform.FreeFilePointer(buffer);

            engine        = audioEngine;
            selfReference = new WeakReference(this, true);
            dspSettings   = new FAudio.F3DAUDIO_DSP_SETTINGS();
            dspSettings.SrcChannelCount     = 1;
            dspSettings.DstChannelCount     = engine.channels;
            dspSettings.pMatrixCoefficients = Marshal.AllocHGlobal(
                4 *
                (int)dspSettings.SrcChannelCount *
                (int)dspSettings.DstChannelCount
                );
            engine.RegisterPointer(handle, selfReference);
            IsDisposed = false;
        }