public void Apply3D(AudioListener listener, AudioEmitter emitter) { if (listener == null) { throw new ArgumentNullException("listener"); } if (emitter == null) { throw new ArgumentNullException("emitter"); } if (IsDisposed) { throw new ObjectDisposedException( "SoundEffectInstance" ); } is3D = true; SoundEffect.FAudioContext dev = SoundEffect.Device(); emitter.emitterData.CurveDistanceScaler = dev.CurveDistanceScaler; emitter.emitterData.ChannelCount = dspSettings.SrcChannelCount; FAudio.F3DAudioCalculate( dev.Handle3D, ref listener.listenerData, ref emitter.emitterData, ( FAudio.F3DAUDIO_CALCULATE_MATRIX | FAudio.F3DAUDIO_CALCULATE_DOPPLER ), ref dspSettings ); if (handle != IntPtr.Zero) { UpdatePitch(); FAudio.FAudioVoice_SetOutputMatrix( handle, SoundEffect.Device().MasterVoice, dspSettings.SrcChannelCount, dspSettings.DstChannelCount, dspSettings.pMatrixCoefficients, 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; }