internal static byte[] Decode(string file, out float length, out int channels, out int samples, out int sampleRate, out int bitDepth) { AudioCodec codec = new AudioCodec(file); length = codec.Length; channels = codec.Channels; samples = codec.Samples; sampleRate = codec.SampleRate; bitDepth = codec.BitDepth; byte[] bytes = codec.GetData(codec.Size); codec.Destroy(); return(bytes); }
internal AudioStream(AudioBuffer buffer, AudioSource source) { this.source = source; codec = new AudioCodec(buffer.File); format = Audio.GetalBufferFormat(codec.Channels, codec.BitDepth); alGenBuffers(bufferIDs.Length, bufferIDs); Audio.CheckALError("Could not create Buffers"); fillInitialBuffers(); Audio.Streams.Add(this); }
public AudioBuffer(string file, bool streamed = false) { if (!System.IO.File.Exists(file)) { throw new FileNotFoundException("Audio file not found.", file); } File = file; Streamed = streamed; if (Streamed) { AudioCodec codec = new AudioCodec(file); Size = codec.Size; Samples = codec.Samples; Length = codec.Length; codec.Destroy(); } else { ID = alGenBuffer(); Audio.CheckALError("Could not create Buffer"); byte[] bytes = AudioCodec.Decode(file, out float length, out int channels, out int samples, out int sampleRate, out int bitDepth); Size = bytes.Length; Samples = samples; Length = length; alBufferData(ID, Audio.GetalBufferFormat(channels, bitDepth), bytes, bytes.Length, sampleRate); Audio.CheckALError("Could not set Buffer Data"); } // Debug //Output.WriteLine($"Buffer: Size: {Size} Samples: {Samples} Length: {Length}s"); Audio.Buffers.Add(this); }