当前位置: 首页>>代码示例>>C#>>正文


C# BufferDescription.Dispose方法代码示例

本文整理汇总了C#中BufferDescription.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# BufferDescription.Dispose方法的具体用法?C# BufferDescription.Dispose怎么用?C# BufferDescription.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BufferDescription的用法示例。


在下文中一共展示了BufferDescription.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: setBufferAndWave

        private void setBufferAndWave(double lengthFactor)
        {
            var waveFormat = new WaveFormat();
            waveFormat.SamplesPerSecond = samplesPerSecond;
            waveFormat.Channels = 2;
            waveFormat.FormatTag = WaveFormatTag.Pcm;
            waveFormat.BitsPerSample = 16;
            waveFormat.BlockAlign = (short)(waveFormat.Channels * waveFormat.BitsPerSample / 8);
            waveFormat.AverageBytesPerSecond = waveFormat.BlockAlign * waveFormat.SamplesPerSecond;

            var bufferDesc = new BufferDescription(waveFormat);
            bufferDesc.DeferLocation = true;
            bufferDesc.Control3D = false;
            bufferDesc.ControlEffects = false;
            bufferDesc.ControlFrequency = true;
            bufferDesc.ControlPan = true;
            bufferDesc.ControlVolume = true;
            bufferDesc.GlobalFocus = true;
            bufferDesc.BufferBytes = Convert.ToInt32(lengthFactor * DitLengthSecond *
                waveFormat.AverageBytesPerSecond);

            if (buffer != null)
            {
                buffer.Stop();
                buffer.Dispose();
                buffer = null;
            }

            buffer = new SecondaryBuffer(bufferDesc, device);
            bufferDesc.Dispose();
            bufferDesc = null;
        }
开发者ID:tmokmss,项目名称:Morusu,代码行数:32,代码来源:DxBeemEmitter.cs

示例2: PlayThread

        private static void PlayThread(object osn)
        {
            EmulatorForm myform = (EmulatorForm)osn;

            SecondaryBuffer SecBuf;
            AutoResetEvent SecBufNotifyAtHalf = new AutoResetEvent(false);
            AutoResetEvent SecBufNotifyAtBeginning = new AutoResetEvent(false);
            
            int SamplingRate = (int)myform._samplingRate;
            int HoldThisManySamples = (int)(1 * SamplingRate);
            int BlockAlign = 2;
            int SecBufByteSize = HoldThisManySamples * BlockAlign;

            WaveFormat MyWaveFormat = new WaveFormat();

            // Set the format
            MyWaveFormat.AverageBytesPerSecond = (int)(myform._samplingRate * BlockAlign);
            MyWaveFormat.BitsPerSample = (short)16;
            MyWaveFormat.BlockAlign = (short)BlockAlign;
            MyWaveFormat.Channels = (short)1;
            MyWaveFormat.SamplesPerSecond = (int)myform._samplingRate;
            MyWaveFormat.FormatTag = WaveFormatTag.Pcm;

            BufferDescription MyDescription;

            // Set BufferDescription
            MyDescription = new BufferDescription();

            MyDescription.Format = MyWaveFormat;
            MyDescription.BufferBytes = HoldThisManySamples * BlockAlign;
            MyDescription.CanGetCurrentPosition = true;
            MyDescription.ControlPositionNotify = true;
            MyDescription.GlobalFocus = true;

            // Create the buffer
            SecBuf = new SecondaryBuffer(MyDescription,myform._directSoundDevice);

            Notify MyNotify;

            MyNotify = new Notify(SecBuf);

            BufferPositionNotify[] MyBufferPositions = new BufferPositionNotify[2];

            MyBufferPositions[0].Offset = 0;
            MyBufferPositions[0].EventNotifyHandle = SecBufNotifyAtBeginning.Handle;
            MyBufferPositions[1].Offset = (HoldThisManySamples / 2) * BlockAlign;
            MyBufferPositions[1].EventNotifyHandle = SecBufNotifyAtHalf.Handle;

            MyNotify.SetNotificationPositions(MyBufferPositions);

            WaitHandle[] SecBufWaitHandles = { SecBufNotifyAtBeginning, SecBufNotifyAtHalf };
            
            Int16[] buffer;

            buffer = myform._sn.GenerateSamples((uint)HoldThisManySamples, "");
            SecBuf.Write(0, buffer, LockFlag.None);
            SecBuf.Play(0, BufferPlayFlags.Looping);
            
            int SecBufNextWritePosition = 0;

            while (myform._bufferPlaying)
            {
                int WriteCount = 0,
                    PlayPosition = SecBuf.PlayPosition,
                    WritePosition = SecBuf.WritePosition;

                if (SecBufNextWritePosition < PlayPosition
                    && (WritePosition >= PlayPosition || WritePosition < SecBufNextWritePosition))
                    WriteCount = PlayPosition - SecBufNextWritePosition;
                else if (SecBufNextWritePosition > WritePosition
                    && WritePosition >= PlayPosition)
                    WriteCount = (SecBufByteSize - SecBufNextWritePosition) + PlayPosition;
               // System.Diagnostics.Debug.WriteLine("WC: "+WriteCount.ToString());
                if (WriteCount > 0)
                {
                    WriteCount = (int)Math.Min(WriteCount,1000);

                    buffer = myform._sn.GenerateSamples((uint)WriteCount/2, "");
                    
                    SecBuf.Write(
                        SecBufNextWritePosition,
                        buffer,
                        LockFlag.None);

                    SecBufNextWritePosition = (SecBufNextWritePosition + WriteCount) % SecBufByteSize;
                }
                else
                {
                    WaitHandle.WaitAny(SecBufWaitHandles, new TimeSpan(0, 0, 5), true);
                }
            }

            SecBuf.Dispose();
            MyDescription.Dispose();
            MyNotify.Dispose();

        }
开发者ID:nocoolnicksleft,项目名称:SN76477,代码行数:97,代码来源:EmulatorForm.cs


注:本文中的BufferDescription.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。