コード例 #1
0
        public void Reset()
        {
            isPlaying = false;
            buffer.Dispose();
            sourceVoice.FlushSourceBuffers();
            buffer = null;
            sourceVoice.Dispose();
            sourceVoice = null;
            masteringVoice.Dispose();
            masteringVoice = null;

            masteringVoice = new MasteringVoice(device, waveFormat.Channels, waveFormat.SamplesPerSecond);

            sourceVoice = new SourceVoice(device, waveFormat, VoiceFlags.None);
            // sourceVoice.BufferStart += new System.EventHandler<ContextEventArgs>(sourceVoice_BufferStart);

            sourceVoice.Volume = 0.5f;
            buffer             = new AudioBuffer();
            buffer.AudioData   = new System.IO.MemoryStream();

            bytesPerSample = (waveFormat.BitsPerSample / 8) * waveFormat.Channels;

            for (int i = 0; i < BUFFER_COUNT; i++)
            {
                sampleData[i] = new short[SAMPLE_SIZE * waveFormat.Channels];
                bData[i]      = new byte[SAMPLE_SIZE * bytesPerSample];
            }
            sourceVoice.SubmitSourceBuffer(buffer);
            currentBuffer = 0;
            playBuffer    = 0;
            samplePos     = 0;
        }
コード例 #2
0
 public void Shutdown()
 {
     buffer.Dispose();
     sourceVoice.FlushSourceBuffers();
     buffer = null;
     sourceVoice.Dispose();
     sourceVoice = null;
     masteringVoice.Dispose();
     masteringVoice = null;
     device.StopEngine();
     device.Dispose();
 }
コード例 #3
0
        static void PlayPCM(XAudio2 device, string fileName)
        {
            //WaveStream stream = new WaveStream(fileName);
            WaveStream stream;

            using (var s = System.IO.File.OpenRead(fileName))
            {
                stream = new WaveStream(s);
            }

            AudioBuffer buffer = new AudioBuffer();

            buffer.AudioData  = stream;
            buffer.AudioBytes = (int)stream.Length;
            buffer.Flags      = BufferFlags.EndOfStream;

            SourceVoice sourceVoice = new SourceVoice(device, stream.Format);

            sourceVoice.SubmitSourceBuffer(buffer);
            sourceVoice.Start();

            // loop until the sound is done playing
            while (sourceVoice.State.BuffersQueued > 0)
            {
                Thread.Sleep(10);
            }

            // cleanup the voice
            buffer.Dispose();
            sourceVoice.Dispose();
            stream.Dispose();
        }
コード例 #4
0
        private void DisposeSource()
        {
            //Stop playback
            Stop();

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

            if (_initialStream != _sourceStream)
            {
                //Dispose stream
                if (_sourceStream != null)
                {
                    _sourceStream.Dispose();
                    _sourceStream = null;
                }

                chkLoopEnable.Checked = chkLoop.Checked = chkLoop.Enabled = false;
            }

            btnOkay.Enabled = false;
        }
コード例 #5
0
        private void DisposeSource()
        {
            //Stop playback
            Stop();

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

#if LOOP_SELECTION_DIALOG_LIB
#else
            //Dispose stream
            if (_sourceStream != null)
            {
                _sourceStream.Dispose();
                _sourceStream = null;
            }

            chkLoopEnable.Checked = chkLoop.Checked = chkLoop.Enabled = false;
#endif
            btnOkay.Enabled = false;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: zhandb/slimdx
        static void PlayPCM(XAudio2 device, string fileName)
        {
            //WaveStream stream = new WaveStream(fileName);
            var s = System.IO.File.OpenRead(fileName);
            WaveStream stream = new WaveStream(s);
            s.Close();

            AudioBuffer buffer = new AudioBuffer();
            buffer.AudioData = stream;
            buffer.AudioBytes = (int)stream.Length;
            buffer.Flags = BufferFlags.EndOfStream;

            SourceVoice sourceVoice = new SourceVoice(device, stream.Format);
            sourceVoice.SubmitSourceBuffer(buffer);
            sourceVoice.Start();

            // loop until the sound is done playing
            while (sourceVoice.State.BuffersQueued > 0)
            {
                if (GetAsyncKeyState(VK_ESCAPE) != 0)
                    break;

                Thread.Sleep(10);
            }

            // wait until the escape key is released
            while (GetAsyncKeyState(VK_ESCAPE) != 0)
                Thread.Sleep(10);

            // cleanup the voice
            buffer.Dispose();
            sourceVoice.Dispose();
            stream.Dispose();
        }
コード例 #7
0
        private void Close()
        {
            //Stop playback
            Stop();

            //Dispose of buffer
            if (_buffer != null)
            {
                _buffer.Dispose();
                _buffer = null;
            }

            if (_targetStream != null)
            {
                _targetStream.Dispose();
                _targetStream = null;
            }

            _targetSource = null;

            //Reset fields
            chkLoop.Checked = false;

            lblProgress.Text = "0/0";
            btnPlay.Enabled  = false;
        }
コード例 #8
0
 public void Dispose()
 {
     buffer.Dispose();
     srcVoice.Dispose();
     masteringVoice.Dispose();
     device.Dispose();
 }
コード例 #9
0
        // ReSharper disable once UnusedParameter.Local
        private void PlayImpl(string soundName, double balance, double volume)
        {
            var soundStream = GetSoundStream(soundName);

            if (soundStream == null)
            {
                return;
            }

            var stream = new WaveStream(soundStream);
            var voice  = new SourceVoice(_audioDevice, stream.Format)
            {
                Volume = (float)volume
            };
            var buf = new AudioBuffer {
                AudioData = stream, AudioBytes = (int)stream.Length
            };

            voice.SubmitSourceBuffer(buf);
            voice.Start();

            // This does not work, need matrix http://xboxforums.create.msdn.com/forums/t/75836.aspx
            //voice.SetChannelVolumes(2, new[] {(float) (balance <= 0 ? 1 : balance), (float) (balance >= 0 ? 1 : -balance)});

            voice.BufferEnd += (sender, args) => _playerThreadDispatcher.BeginInvoke((Action)(() =>
            {
                voice.Stop();
                buf.Dispose();
                voice.Dispose();
                stream.Dispose();
            }));
        }
コード例 #10
0
 public void Dispose()
 {
     AudioSource?.Bind(null);
     AudioSource?.Dispose();
     AudioBuffer?.Dispose();
     AudioSource = null;
     AudioBuffer = null;
 }
コード例 #11
0
ファイル: Aja.cs プロジェクト: ratsil/bethe.helpers
        override public void Dispose()
        {
            lock (oLockDispose)
            {
                if (bDisposed)
                {
                    return;
                }
                bDisposed = true;
            }
            try
            {
                if (null != _cCard)
                {
                    _cCard.Dispose();
                }
                if (null != _aCurrentFramesIDs)
                {
                    _aCurrentFramesIDs.Clear();
                }
            }
            catch (Exception ex)
            {
                (new Logger("Aja", sName)).WriteError(ex);
            }
            try
            {
                if (null != _cAudioBuffer)
                {
                    _cAudioBuffer.Dispose();
                }

                if (_AjaFramesAudioBuffer.nCount > 0)
                {
                    _AjaFramesAudioBuffer.Dequeue().Dispose();
                }
                if (_AjaFramesAudioToDispose.nCount > 0)
                {
                    _AjaFramesAudioToDispose.Dequeue().Dispose();
                }
                if (_AjaFramesVideoBuffer.nCount > 0)
                {
                    FrameBufferReleased(_AjaFramesVideoBuffer.Dequeue()); //TODO - not disposed in device...
                }
                if (_AjaFramesVideoToDispose.nCount > 0)
                {
                    FrameBufferReleased(_AjaFramesVideoToDispose.Dequeue());
                }

                base.Dispose();
            }
            catch (Exception ex)
            {
                (new Logger("Aja", sName)).WriteError(ex);
            }
        }
コード例 #12
0
 private void disposeSound()
 {
     if (buffer == null)
     {
         return;
     }
     // cleanup the voice
     buffer.Dispose();
     sourceVoice.Dispose();
     buffer      = null;
     sourceVoice = null;
 }
コード例 #13
0
ファイル: XA2Audio.cs プロジェクト: DualBrain/Emu-o-Tron
 public void Reset()
 {
     if (sVoice != null)
     {
         sVoice.Stop();
         sVoice.Dispose();
     }
     if (audioWriter != null)
     {
         audioWriter.Close();
     }
     if (audioBuffer != null)
     {
         audioBuffer.Dispose();
     }
     sVoice                = new SourceVoice(device, audioFormat, VoiceFlags.None);
     audioBuffer           = new AudioBuffer();
     audioBuffer.AudioData = new MemoryStream();
     audioWriter           = new BinaryWriter(audioBuffer.AudioData);
     mVoice.Volume         = volume;
     sVoice.Start();
 }
コード例 #14
0
ファイル: AudioRoute.cs プロジェクト: bugRanger/Chat
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _buffer.Dispose();
                _codec.Dispose();
            }

            _disposed = true;
        }
コード例 #15
0
ファイル: AudioTest.cs プロジェクト: AmmRage/mmflex
        public static void PlayPcm(XAudio2 device, string fileName)
        {
            var        s      = System.IO.File.OpenRead(fileName); //open the wav file
            WaveStream stream = new WaveStream(s);                 //pass the stream to the library

            s.Close();                                             //close the file

            AudioBuffer buffer = new AudioBuffer();                //init the buffer

            buffer.AudioData  = stream;                            //set the input stream for the audio
            buffer.AudioBytes = (int)stream.Length;                //set the size of the buffer to the size of the stream
            buffer.Flags      = BufferFlags.EndOfStream;           //presumably set it to play until the end of the stream/file


            SourceVoice sourceVoice = new SourceVoice(device, stream.Format); //this looks like it might initalise the actual output

            sourceVoice.SubmitSourceBuffer(buffer);                           //pass the buffer to the output thingo
            sourceVoice.Start();                                              //start the playback?

            //above 2 sections are guessed, there is no documentation on the classes/proerties.

            // loop until the sound is done playing
            while (sourceVoice.State.BuffersQueued > 0) // This keeps looping while there is sound in the buffer
            {                                           // (presumably). For this specific example it will stop
                if (GetAsyncKeyState(VK_ESCAPE) != 0)   // plying the sound if escape is pressed. That is what the
                {
                    break;                              // DLLImport and stuff at the top is for
                }
                Thread.Sleep(10);                       //
            }

            // wait until the escape key is released
            while (GetAsyncKeyState(VK_ESCAPE) != 0) //it jsut waits here until the person presses escape
            {
                Thread.Sleep(10);
            }

            // cleanup the voice
            buffer.Dispose();
            sourceVoice.Dispose();
            stream.Dispose();
        }
コード例 #16
0
 new public void Dispose()
 {
     lock (oLockDispose)
     {
         if (bDisposed)
         {
             return;
         }
         bDisposed = true;
     }
     try
     {
         if (_TurnedOn)  // иначе, если не TurnedOn, то error при StopScheduledPlayback
         {
             Marshal.FreeHGlobal(_pFakePointer);
             _ahFramesBuffersBinds.Clear();
             _aCurrentFramesIDs.Clear();
         }
     }
     catch (Exception ex)
     {
         (new Logger("DeckLinkFake", sName)).WriteError(ex);
     }
     finally
     {
         try
         {
             if (null != _cAudioBuffer)
             {
                 _cAudioBuffer.Dispose();
             }
         }
         catch (Exception ex)
         {
             (new Logger("DeckLinkFake", sName)).WriteError(ex);
         }
         finally
         {
             _bStopped = true;
         }
     }
 }
コード例 #17
0
        static void PlayPCM(XAudio2 device, string fileName)
        {
            //WaveStream stream = new WaveStream(fileName);
            var        s      = System.IO.File.OpenRead(fileName);
            WaveStream stream = new WaveStream(s);

            s.Close();

            AudioBuffer buffer = new AudioBuffer();

            buffer.AudioData  = stream;
            buffer.AudioBytes = (int)stream.Length;
            buffer.Flags      = BufferFlags.EndOfStream;

            SourceVoice sourceVoice = new SourceVoice(device, stream.Format);

            sourceVoice.SubmitSourceBuffer(buffer);
            sourceVoice.Start();

            // loop until the sound is done playing
            while (sourceVoice.State.BuffersQueued > 0)
            {
                if (GetAsyncKeyState(VK_ESCAPE) != 0)
                {
                    break;
                }

                Thread.Sleep(10);
            }

            // wait until the escape key is released
            while (GetAsyncKeyState(VK_ESCAPE) != 0)
            {
                Thread.Sleep(10);
            }

            // cleanup the voice
            buffer.Dispose();
            sourceVoice.Dispose();
            stream.Dispose();
        }
コード例 #18
0
        protected override void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            if (disposing)
            {
                mSoundManager.RemoveSound(mGlobalSoundSource);
                mGlobalSoundSource.Dispose();
                mGlobalSoundSourceBuffer.Dispose();

                foreach (var actorBatch in mActorBatches)
                {
                    actorBatch.mMesh.Dispose();
                }
            }

            base.Dispose(disposing);
        }
コード例 #19
0
ファイル: AudioControlClass.cs プロジェクト: julienfars/tCSF
        void SoundPlayerThread()
        {
            Globals.bPlaySignal = true;

            WaveMemStream = new MemoryStream(WaveDaten);

            WaveBuffer           = new AudioBuffer();
            WaveBuffer.Flags     = BufferFlags.EndOfStream;
            WaveBuffer.AudioData = WaveMemStream;
            // WaveBuffer.AudioBytes = clGlobals.BytesProSekunde;
            WaveBuffer.AudioBytes = (int)WaveMemStream.Length;
            WaveBuffer.LoopCount  = XAudio2.LoopInfinite;

            WaveSourceVoice = new SourceVoice(AudioDevice, SignalFormat);
            WaveSourceVoice.SubmitSourceBuffer(WaveBuffer);

            WaveSourceVoice.Start();

            while (Globals.bPlaySignal)
            {
                Thread.Sleep(10);
            }

            WaveSourceVoice.Stop();
            Thread.Sleep(10);
            WaveMemStream.Close();
            WaveMemStream.Dispose();
            WaveMemStream = null;
            WaveBuffer.Dispose();
            WaveBuffer = null;
            WaveSourceVoice.Dispose();
            WaveSourceVoice = null;
            // Thread.Sleep(100);
            soundThreadStart = null;
            // this.ClearWaveContainer();
            // this.InitWaveContainer();
            this.m_soundThread.Abort();
        }
コード例 #20
0
        private void Close()
        {
            //Stop playback
            Stop();

            //Dispose of buffer
            if (_buffer != null)
            {
                _buffer.Dispose();
                _buffer = null;
            }

            if (_targetStream != null)
            {
                _targetStream.Dispose();
                _targetStream = null;
            }

            _targetSource = null;

            //Reset fields
            chkLoop.Checked = false;
        }
コード例 #21
0
ファイル: AudioControlClass.cs プロジェクト: julienfars/tCSF
 public virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             if (WaveMemStream != null)
             {
                 WaveMemStream.Dispose();
             }
             if (WaveBuffer != null)
             {
                 WaveBuffer.Dispose();
             }
             if (WaveSourceVoice != null)
             {
                 WaveSourceVoice.Dispose();
             }
             WaveMasterVoice.Dispose();
             AudioDevice.Dispose();
         }
     }
     disposed = true;
 }
コード例 #22
0
ファイル: Sounds.cs プロジェクト: MaulingMonkey/uberirc
        public void Play( Form on )
        {
            var screens = Screen.AllScreens;
            var screens_left  = screens.Min( screen => screen.Bounds.Left  );
            var screens_right = screens.Max( screen => screen.Bounds.Right );
            var screens_width = screens_right-screens_left;

            var bestScreen = screens.OrderByDescending( screen => {
                var area = screen.Bounds;
                area.Intersect( on.Bounds );
                return area.Width*area.Height;
            }).First();

            var balances = new[]{1.5f,1.5f};
            if ( screens.Length==3 && DisplayBalances.ContainsKey(bestScreen.DeviceName) ) balances = DisplayBalances[bestScreen.DeviceName];

            var path   = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\.Default\"+Name+@"\.Current").GetValue(null) as string;
            var stream = new WaveStream(path);
            var buffer = new AudioBuffer() { AudioBytes=(int)stream.Length, AudioData=stream, Flags=BufferFlags.EndOfStream };

            var voice = new SourceVoice( XAudio2, stream.Format );
            voice.SubmitSourceBuffer( buffer );
            voice.SetChannelVolumes( balances.Length, balances );
            voice.BufferEnd += (sender,ctx) => {
                try {
                    on.BeginInvoke(new Action(()=>{
                        voice.Dispose();
                        buffer.Dispose();
                        stream.Dispose();
                    }));
                } catch ( InvalidOperationException ) {
                    // herp derp on must be disposed/gone
                }
            };
            voice.Start();
        }
コード例 #23
0
 public override void Dispose()
 {
     mBuffer.Dispose();
 }
コード例 #24
0
        unsafe private void Timer_Tick(object sender, object e)
        {
            try
            {
                AudioFrame audioFrame = frameOutputNode.GetFrame();
                using (AudioBuffer buffer = audioFrame.LockBuffer(AudioBufferAccessMode.Read))
                    using (IMemoryBufferReference memoryBufferReference = buffer.CreateReference())
                    {
                        byte * dataInBytes;
                        uint   capacityInBytes;
                        float *dataInFloat;

                        ((IMemoryBufferByteAccess)memoryBufferReference).GetBuffer(out dataInBytes, out capacityInBytes);
                        dataInFloat = (float *)dataInBytes;

                        Int32   pulseOn             = 0;
                        Int32   pulseOff            = 0;
                        Boolean transitionUpFound   = false;
                        Boolean transitionDownFound = false;
                        Int32   transitionCount     = 0;
                        periodLength = 0;
                        Boolean high = dataInFloat[0] > 0;
                        for (Int32 i = 0; i < capacityInBytes / 8; i++)
                        {
                            if (dataInFloat[i] != 0)
                            {
                                if (dataInFloat[i] < -0.05) // If low
                                {
                                    if (high)               // If was high
                                    {
                                        transitionDownFound = true;
                                        transitionCount++;
                                    }
                                    high = false;
                                }
                                else if (dataInFloat[i] > 0.05) // Is high
                                {
                                    if (!high)                  // If was low
                                    {
                                        transitionUpFound = true;
                                        transitionCount++;
                                    }
                                    high = true;
                                }

                                if (transitionCount > 2)
                                {
                                    periodLength = (int)((pulseOn + pulseOff) / 9.27);
                                    break;
                                }

                                if (high && transitionUpFound)
                                {
                                    pulseOn++;
                                }
                                else if (!high && transitionDownFound)
                                {
                                    pulseOff++;
                                }
                            }
                        }
                        dataInFloat = null;
                        dataInBytes = null;
                        memoryBufferReference.Dispose();
                        buffer.Dispose();
                        audioFrame.Dispose();
                        periodLengthUK101 = periodLength;
                    }
            } catch { }
            //audioFrame = frameOutputNode.GetFrame();
            audioGraph.Stop();
            audioGraph.ResetAllNodes();
            audioGraph.Start();
        }