private static byte[] LoadWave(BinaryReader reader, out ALFormat format, out int size, out int frequency) { if (new string(reader.ReadChars(4)) != "RIFF") { throw new NotSupportedException("Specified stream is not a wave file."); } reader.ReadInt32(); if (new string(reader.ReadChars(4)) != "WAVE") { throw new NotSupportedException("Specified stream is not a wave file."); } for (string str = new string(reader.ReadChars(4)); str != "fmt "; str = new string(reader.ReadChars(4))) { reader.ReadBytes(reader.ReadInt32()); } int num1 = reader.ReadInt32(); int num2 = (int)reader.ReadUInt16(); int channels = (int)reader.ReadUInt16(); int num3 = (int)reader.ReadUInt32(); int num4 = (int)reader.ReadUInt32(); int num5 = (int)reader.ReadUInt16(); int bits = (int)reader.ReadUInt16(); if (num1 > 16) { reader.ReadBytes(num1 - 16); } string str1; for (str1 = new string(reader.ReadChars(4)); str1.ToLower(CultureInfo.InvariantCulture) != "data"; str1 = new string(reader.ReadChars(4))) { reader.ReadBytes(reader.ReadInt32()); } if (str1 != "data") { throw new NotSupportedException("Specified wave file is not supported."); } int num6 = reader.ReadInt32(); frequency = num3; format = AudioLoader.GetSoundFormat(channels, bits, num2 == 2); byte[] numArray; if (reader.BaseStream.Length <= 11072L) { numArray = new byte[0]; size = 0; } else { numArray = reader.ReadBytes((int)reader.BaseStream.Length); size = num6 / num5 * num5; } return(numArray); }
private void PlatformInitializeFormat(byte[] header, byte[] buffer, int bufferSize, int loopStart, int loopLength) { var wavFormat = BitConverter.ToInt16(header, 0); var channels = BitConverter.ToInt16(header, 2); var sampleRate = BitConverter.ToInt32(header, 4); var blockAlignment = BitConverter.ToInt16(header, 12); var bitsPerSample = BitConverter.ToInt16(header, 14); var format = AudioLoader.GetSoundFormat(wavFormat, channels, bitsPerSample); PlatformInitializeBuffer(buffer, bufferSize, format, channels, sampleRate, blockAlignment, bitsPerSample, loopStart, loopLength); }
private static byte[] LoadWave(BinaryReader reader, out ALFormat format, out int size, out int frequency) { if (new string(reader.ReadChars(4)) != "RIFF") { throw new NotSupportedException("Specified stream is not a wave file."); } reader.ReadInt32(); if (new string(reader.ReadChars(4)) != "WAVE") { throw new NotSupportedException("Specified stream is not a wave file."); } for (string str = new string(reader.ReadChars(4)); str != "fmt "; str = new string(reader.ReadChars(4))) { reader.ReadBytes(reader.ReadInt32()); } int num1 = reader.ReadInt32(); int num2 = (int)reader.ReadInt16(); int channels = (int)reader.ReadInt16(); int num3 = reader.ReadInt32(); reader.ReadInt32(); int num4 = (int)reader.ReadInt16(); int bits = (int)reader.ReadInt16(); if (num1 > 16) { reader.ReadBytes(num1 - 16); } string str1; for (str1 = new string(reader.ReadChars(4)); str1.ToLower() != "data"; str1 = new string(reader.ReadChars(4))) { reader.ReadBytes(reader.ReadInt32()); } if (str1 != "data") { throw new NotSupportedException("Specified wave file is not supported."); } int num5 = reader.ReadInt32(); frequency = num3; format = AudioLoader.GetSoundFormat(channels, bits); byte[] numArray = reader.ReadBytes((int)reader.BaseStream.Length); size = num5; if (num2 != 1) { Console.WriteLine("Wave compression is not supported."); size = 0; } return(numArray); }
private void PlatformInitializeIeeeFloat(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength) { if (!OpenALSoundController.GetInstance.SupportsIeee) { // If 32-bit IEEE float is not supported, convert to 16-bit signed PCM buffer = AudioLoader.ConvertFloatTo16(buffer, offset, count); PlatformInitializePcm(buffer, 0, buffer.Length, 16, sampleRate, channels, loopStart, loopLength); return; } var format = AudioLoader.GetSoundFormat(AudioLoader.FormatIeee, (int)channels, 32); // bind buffer SoundBuffer = new OALSoundBuffer(); SoundBuffer.BindDataBuffer(buffer, format, count, sampleRate); }
private void PlatformInitializePcm(byte[] buffer, int offset, int count, int sampleBits, int sampleRate, AudioChannels channels, int loopStart, int loopLength) { if (sampleBits == 24) { // Convert 24-bit signed PCM to 16-bit signed PCM buffer = AudioLoader.Convert24To16(buffer, offset, count); offset = 0; count = buffer.Length; sampleBits = 16; } var format = AudioLoader.GetSoundFormat(AudioLoader.FormatPcm, (int)channels, sampleBits); // bind buffer SoundBuffer = new OALSoundBuffer(); SoundBuffer.BindDataBuffer(buffer, format, count, sampleRate); }
private void PlatformInitializeIma4(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int blockAlignment, int loopStart, int loopLength) { if (!OpenALSoundController.GetInstance.SupportsIma4) { // If IMA/ADPCM is not supported, convert to 16-bit signed PCM buffer = AudioLoader.ConvertIma4ToPcm(buffer, offset, count, (int)channels, blockAlignment); PlatformInitializePcm(buffer, 0, buffer.Length, 16, sampleRate, channels, loopStart, loopLength); return; } var format = AudioLoader.GetSoundFormat(AudioLoader.FormatIma4, (int)channels, 0); int sampleAlignment = AudioLoader.SampleAlignment(format, blockAlignment); // bind buffer SoundBuffer = new OALSoundBuffer(); SoundBuffer.BindDataBuffer(buffer, format, count, sampleRate, sampleAlignment); }
private void PlatformInitializeAdpcm(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int blockAlignment, int loopStart, int loopLength) { if (!OpenALSoundController.GetInstance.SupportsAdpcm) { // If MS-ADPCM is not supported, convert to 16-bit signed PCM buffer = AudioLoader.ConvertMsAdpcmToPcm(buffer, offset, count, (int)channels, blockAlignment); PlatformInitializePcm(buffer, 0, buffer.Length, 16, sampleRate, channels, loopStart, loopLength); return; } var format = AudioLoader.GetSoundFormat(AudioLoader.FormatMsAdpcm, (int)channels, 0); int sampleAlignment = AudioLoader.SampleAlignment(format, blockAlignment); // bind buffer SoundBuffer = new OALSoundBuffer(); // Buffer length must be aligned with the block alignment int alignedCount = count - (count % blockAlignment); SoundBuffer.BindDataBuffer(buffer, format, alignedCount, sampleRate, sampleAlignment); }