Exemple #1
0
        public virtual void Play()
        {
            if (State == SoundState.Playing)
            {
                return;
            }
            if (State == SoundState.Paused)
            {
                /* Just resume the existing handle */
                FAudio.FAudioSourceVoice_Start(handle, 0, 0);
                INTERNAL_state = SoundState.Playing;
                return;
            }

            SoundEffect.FAudioContext dev = SoundEffect.Device();

            /* Create handle */
            FAudio.FAudioWaveFormatEx fmt = isDynamic ?
                                            (this as DynamicSoundEffectInstance).format :
                                            parentEffect.format;
            FAudio.FAudio_CreateSourceVoice(
                dev.Handle,
                out handle,
                ref fmt,
                FAudio.FAUDIO_VOICE_USEFILTER,
                FAudio.FAUDIO_DEFAULT_FREQ_RATIO,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );
            if (handle == IntPtr.Zero)
            {
                return;                 /* What */
            }

            /* Apply current properties */
            FAudio.FAudioVoice_SetVolume(handle, INTERNAL_volume, 0);
            UpdatePitch();
            if (is3D || Pan != 0.0f)
            {
                FAudio.FAudioVoice_SetOutputMatrix(
                    handle,
                    SoundEffect.Device().MasterVoice,
                    dspSettings.SrcChannelCount,
                    dspSettings.DstChannelCount,
                    dspSettings.pMatrixCoefficients,
                    0
                    );
            }

            /* For static effects, submit the buffer now */
            if (isDynamic)
            {
                (this as DynamicSoundEffectInstance).QueueInitialBuffers();
            }
            else
            {
                if (IsLooped)
                {
                    parentEffect.handle.LoopCount  = 255;
                    parentEffect.handle.LoopBegin  = parentEffect.loopStart;
                    parentEffect.handle.LoopLength = parentEffect.loopLength;
                }
                else
                {
                    parentEffect.handle.LoopCount  = 0;
                    parentEffect.handle.LoopBegin  = 0;
                    parentEffect.handle.LoopLength = 0;
                }
                FAudio.FAudioSourceVoice_SubmitSourceBuffer(
                    handle,
                    ref parentEffect.handle,
                    IntPtr.Zero
                    );
            }

            /* Play, finally. */
            FAudio.FAudioSourceVoice_Start(handle, 0, 0);
            INTERNAL_state = SoundState.Playing;
            hasStarted     = true;
        }