public void Load(string filename) { XRamExtension XRam = new XRamExtension(); if (XRam.IsInitialized) { XRam.SetBufferMode(1, ref Buffer, XRamExtension.XRamStorage.Hardware); } BinaryReader br = new BinaryReader(File.OpenRead(filename)); byte[] bytes = new byte[1]; if (new string(br.ReadChars(4)) != "caff") { throw new Exception("input file not caff"); } br.ReadBytes(4); // rest of caf file header cafInfo = new CAFAudioFormat(); do { string type = new string(br.ReadChars(4)); long size = BitConverter.ToInt64(br.ReadBytes(8).Reverse().ToArray(), 0); if (type == "data") { bytes = new byte[size]; bytes = br.ReadBytes((int)size); } else if (type == "desc") { cafInfo.InitWithData(br.ReadBytes((int)size)); } else { br.ReadBytes((int)size); } } while (bytes.Length == 1); br.Close(); IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(bytes.Length); System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bytes.Length); AL.BufferData((uint)Buffer, cafInfo.GetALFormat(), ptr, bytes.Length, (int)cafInfo.mSampleRate); ALError error = AL.GetError(); if (error != ALError.NoError) { // respond to load error etc. Console.WriteLine("borked buffer load. ALError: " + error.ToString()); } AL.Source(Source, ALSourcei.Buffer, (int)Buffer); // attach the buffer to a source }
public void Load(string filename) { XRamExtension XRam = new XRamExtension(); if (XRam.IsInitialized) XRam.SetBufferMode(1, ref Buffer, XRamExtension.XRamStorage.Hardware); BinaryReader br = new BinaryReader(File.OpenRead(filename)); byte[] bytes = new byte[1]; if (new string(br.ReadChars(4)) != "caff") throw new Exception("input file not caff"); br.ReadBytes(4); // rest of caf file header cafInfo = new CAFAudioFormat(); do { string type = new string(br.ReadChars(4)); long size = BitConverter.ToInt64(br.ReadBytes(8).Reverse().ToArray(), 0); if (type == "data") { bytes = new byte[size]; bytes = br.ReadBytes((int)size); } else if (type == "desc") { cafInfo.InitWithData(br.ReadBytes((int)size)); } else { br.ReadBytes((int)size); } } while (bytes.Length == 1); br.Close(); IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(bytes.Length); System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bytes.Length); AL.BufferData((uint)Buffer, cafInfo.GetALFormat(), ptr, bytes.Length, (int)cafInfo.mSampleRate); ALError error = AL.GetError(); if (error != ALError.NoError) { // respond to load error etc. Console.WriteLine("borked buffer load. ALError: " + error.ToString()); } AL.Source(Source, ALSourcei.Buffer, (int)Buffer ); // attach the buffer to a source }