public void StopImmediate()
        {
            Debug.Assert(PlatformUtils.IsInMainThread());

            if (immediateStream != IntPtr.Zero)
            {
                Pa_AbortStream(immediateStream);
                //Pa_StopStream(immediateStream);
                Pa_CloseStream(immediateStream);
                immediateStream         = IntPtr.Zero;
                immediateStreamData     = null;
                immediateStreamPosition = -1;
            }
        }
Exemple #2
0
        public void StopImmediate()
        {
            Debug.Assert(PlatformUtils.IsInMainThread());

            if (immediateSource >= 0)
            {
                AL.SourceStop(immediateSource);
                AL.Source(immediateSource, ALSourcei.Buffer, 0);
                AL.DeleteBuffers(immediateBuffers);
                AL.DeleteSource(immediateSource);

                immediateBuffers = null;
                immediateSource  = -1;
            }
        }
Exemple #3
0
        public unsafe void PlayImmediate(short[] data, int sampleRate, float volume)
        {
            Debug.Assert(PlatformUtils.IsInMainThread());

            StopImmediate();

            immediateSource  = AL.GenSource();
            immediateBuffers = AL.GenBuffers(1);

            fixed(short *p = &data[0])
            AL.BufferData(immediateBuffers[0], ALFormat.Mono16, new IntPtr(p), data.Length * sizeof(short), sampleRate);

            AL.Source(immediateSource, ALSourcef.Gain, volume);
            AL.SourceQueueBuffer(immediateSource, immediateBuffers[0]);
            AL.SourcePlay(immediateSource);
        }
Exemple #4
0
        public void StopImmediate()
        {
            Debug.Assert(PlatformUtils.IsInMainThread());

            if (immediateVoice != null)
            {
                immediateVoice.Stop();
                immediateVoice.FlushSourceBuffers();
                immediateVoice.BufferEnd -= ImmediateVoice_BufferEnd;
                immediateVoice.DestroyVoice();
                immediateVoice.Dispose();
                immediateVoice = null;

                Utilities.FreeMemory(immediateAudioBuffer.AudioDataPointer);
                immediateAudioBuffer = null;
                immediateDonePlaying = true;
            }
        }
Exemple #5
0
        public void PlayImmediate(short[] data, int sampleRate, float volume)
        {
            Debug.Assert(PlatformUtils.IsInMainThread());

            StopImmediate();

            immediateDonePlaying = false;

            immediateAudioBuffer = new AudioBuffer();
            immediateAudioBuffer.AudioDataPointer = Utilities.AllocateMemory(data.Length * sizeof(short));
            immediateAudioBuffer.AudioBytes       = data.Length * sizeof(short);
            Marshal.Copy(data, 0, immediateAudioBuffer.AudioDataPointer, data.Length);

            var waveFormat = new WaveFormat(sampleRate, 16, 1);

            immediateVoice            = new SourceVoice(xaudio2, waveFormat);
            immediateVoice.BufferEnd += ImmediateVoice_BufferEnd;
            immediateVoice.SetVolume(volume);
            immediateVoice.SubmitSourceBuffer(immediateAudioBuffer, null);
            immediateVoice.Start();
        }
        public unsafe void PlayImmediate(short[] data, int sampleRate, float volume)
        {
            Debug.Assert(PlatformUtils.IsInMainThread());

            StopImmediate();

            Pa_OpenDefaultStream(out immediateStream, 0, 1, PaSampleFormat.Int16, sampleRate, 0, immediateStreamCallback, IntPtr.Zero);

            if (immediateStream != IntPtr.Zero)
            {
                // Cant find volume adjustment in port audio.
                short vol = (short)(volume * 32768);

                immediateStreamData = new short[data.Length];
                for (int i = 0; i < data.Length; i++)
                {
                    immediateStreamData[i] = (short)((data[i] * vol) >> 15);
                }

                immediateStreamPosition = 0;
                Pa_StartStream(immediateStream);
            }
        }