/// <summary> /// Initializes a new instance of the BASSSoundEffect class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="filename">The filename of the sample to load.</param> public BASSSoundEffect(UltravioletContext uv, String filename) : base(uv) { var fileSystemService = FileSystemService.Create(); var fileData = default(Byte[]); using (var stream = fileSystemService.OpenRead(filename)) { fileData = new Byte[stream.Length]; stream.Read(fileData, 0, fileData.Length); } sample = BASSNative.SampleLoad(fileData, 0, (UInt32)fileData.Length, UInt16.MaxValue, 0); if (!BASSUtil.IsValidHandle(sample)) { throw new BASSException(); } if (!BASSNative.SampleGetInfo(sample, out this.sampleInfo)) { throw new BASSException(); } this.data = Marshal.AllocHGlobal((int)sampleInfo.length); if (!BASSNative.SampleGetData(sample, this.data)) { throw new BASSException(); } }