/// <summary> /// Create a sample form a WAV, AIFF, MP3, MP2, MP1, OGG or plug-in supported file sample. /// </summary> /// <param name="file">File name. </param> /// <param name="offset">File offset to load the sample from.</param> /// <param name="length"> /// Data length... 0 = use all data up to the end of file. If length over-runs the end of the file, it /// will automatically be lowered to the end of the file. /// </param> /// <param name="max"> /// Maximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the /// SampleConfig.OverXX flags to choose the override decider, in the case of there being no free channel available for /// playback (ie. the sample is already playing max times). /// </param> /// <param name="config">Some configures of sample.</param> public AudioSample(String file, UInt64 offset, uint length, uint max, SampleLoadConfig config) : this() { config |= SampleLoadConfig.Unicode; using (var fileHandle = InteropHelper.StringToPtr(file)) { Handle = AudioSampleModule.SampleLoadFunction.CheckResult( AudioSampleModule.SampleLoadFunction.Delegate(false, fileHandle.Handle, offset, length, max, config)); } }
/// <summary> /// Create a sample form a WAV, AIFF, MP3, MP2, MP1, OGG or plug-in supported file sample stream. /// </summary> /// <param name="stream">A .NET memory stream. </param> /// <param name="max"> /// Maximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the /// SampleConfig.OverXX flags to choose the override decider, in the case of there being no free channel available for /// playback (ie. the sample is already playing max times). /// </param> /// <param name="config">Some configures of sample.</param> public AudioSample(MemoryStream stream, uint max, SampleLoadConfig config) : this() { ArraySegment <byte> bufferSegment; byte[] buffer = null; if (stream.TryGetBuffer(out bufferSegment)) { buffer = bufferSegment.Array; } else { buffer = stream.ToArray(); } GCHandle bufferHandle = GCHandle.Alloc(buffer); Handle = AudioSampleModule.SampleLoadFunction.CheckResult( AudioSampleModule.SampleLoadFunction.Delegate(true, bufferHandle.AddrOfPinnedObject(), 0, (uint)stream.Length, max, config)); bufferHandle.Free(); }
/// <summary> /// Create a sample form a WAV, AIFF, MP3, MP2, MP1, OGG or plug-in supported file sample stream. /// </summary> /// <param name="stream">A .NET memory stream. </param> /// <param name="max"> /// Maximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the /// SampleConfig.OverXX flags to choose the override decider, in the case of there being no free channel available for /// playback (ie. the sample is already playing max times). /// </param> /// <param name="config">Some configures of sample.</param> public AudioSample(MemoryStream stream, uint max, SampleLoadConfig config) : this() { ArraySegment<byte> bufferSegment; byte[] buffer = null; if (stream.TryGetBuffer(out bufferSegment)) { buffer = bufferSegment.Array; } else { buffer = stream.ToArray(); } GCHandle bufferHandle = GCHandle.Alloc(buffer); Handle = AudioSampleModule.SampleLoadFunction.CheckResult( AudioSampleModule.SampleLoadFunction.Delegate(true, bufferHandle.AddrOfPinnedObject(), 0, (uint) stream.Length, max, config)); bufferHandle.Free(); }