public override SoundInstance CreateInstance(AudioListener listener = null, bool useHrtf = false, float directionalFactor = 0.0f, HrtfEnvironment environment = HrtfEnvironment.Small) { return(CreateInstance(listener, false, useHrtf, directionalFactor, environment)); }
/// <summary> /// Create a new sound effect instance of the sound effect. /// The audio data are shared between the instances so that useless memory copies is avoided. /// Each instance that can be played and localized independently from others. /// </summary> /// <returns>A new sound instance</returns> /// <exception cref="ObjectDisposedException">The sound has already been disposed</exception> public SoundInstance CreateInstance(AudioListener listener = null, bool forceLoadInMemory = false, bool useHrtf = false, float directionalFactor = 0.0f, HrtfEnvironment environment = HrtfEnvironment.Small) { if (listener == null) { listener = AudioEngine.DefaultListener; } CheckNotDisposed(); var newInstance = new SoundInstance(this, listener, forceLoadInMemory, useHrtf, directionalFactor, environment) { Name = Name + " - Instance " + intancesCreationCount }; RegisterInstance(newInstance); return(newInstance); }
internal SoundInstance(Sound staticSound, AudioListener listener, bool forceLoadInMemory, bool useHrtf = false, float directionalFactor = 0.0f, HrtfEnvironment environment = HrtfEnvironment.Small) { Listener = listener; engine = staticSound.AudioEngine; sound = staticSound; spatialized = staticSound.Spatialized; var streamed = staticSound.StreamFromDisk && !forceLoadInMemory; if (engine.State == AudioEngineState.Invalidated) { return; } Source = AudioLayer.SourceCreate(listener.Listener, staticSound.SampleRate, streamed ? CompressedSoundSource.NumberOfBuffers : 1, staticSound.Channels == 1, spatialized, streamed, useHrtf, directionalFactor, environment); if (Source.Ptr == IntPtr.Zero) { throw new Exception("Failed to create an AudioLayer Source"); } if (streamed) { soundSource = new CompressedSoundSource(this, staticSound.FileProvider, staticSound.CompressedDataUrl, staticSound.NumberOfPackets, staticSound.Samples, staticSound.SampleRate, staticSound.Channels, staticSound.MaxPacketLength); } else { if (staticSound.PreloadedBuffer.Ptr == IntPtr.Zero) { staticSound.LoadSoundInMemory(); //this should be already loaded by the serializer, but in the case of forceLoadInMemory might not be the case yet. } AudioLayer.SourceSetBuffer(Source, staticSound.PreloadedBuffer); } ResetStateToDefault(); }
/// <summary> /// Initializes a new instance of the <see cref="SoundInstance"/> class using a dynamic sound source. /// </summary> /// <param name="engine">The audio engine that will be used to play this instance</param> /// <param name="listener">The listener of this instance</param> /// <param name="dynamicSoundSource">The source from where the PCM data will be fetched</param> /// <param name="sampleRate">The sample rate of this audio stream</param> /// <param name="mono">Set to true if the souce is mono, false if stereo</param> /// <param name="spatialized">If the SoundInstance will be used for spatialized audio set to true, if not false, if true mono must also be true</param> /// <param name="useHrtf">If the engine should use Hrtf for spatialization</param> /// <param name="directionalFactor"></param> /// <param name="environment"></param> public SoundInstance(AudioEngine engine, AudioListener listener, DynamicSoundSource dynamicSoundSource, int sampleRate, bool mono, bool spatialized = false, bool useHrtf = false, float directionalFactor = 0.0f, HrtfEnvironment environment = HrtfEnvironment.Small) { Listener = listener; this.engine = engine; this.spatialized = spatialized; soundSource = dynamicSoundSource; if (engine.State == AudioEngineState.Invalidated) { return; } Source = AudioLayer.SourceCreate(listener.Listener, sampleRate, dynamicSoundSource.MaxNumberOfBuffers, mono, spatialized, true, useHrtf, directionalFactor, environment); if (Source.Ptr == IntPtr.Zero) { throw new Exception("Failed to create an AudioLayer Source"); } ResetStateToDefault(); }
/// <summary> /// Create a new sound effect instance of the sound effect. /// Each instance that can be played and localized independently from others. /// </summary> /// <returns>A new sound instance</returns> /// <exception cref="ObjectDisposedException">The sound has already been disposed</exception> public abstract SoundInstance CreateInstance(AudioListener listener = null, bool useHrtf = false, float directionalFactor = 0.0f, HrtfEnvironment environment = HrtfEnvironment.Small);
public static extern Source SourceCreate(Listener listener, int sampleRate, int maxNumberOfBuffers, bool mono, bool spatialized, bool streamed, bool hrtf, float hrtfDirectionFactor, HrtfEnvironment environment);