/// <summary> /// Determines the correct codec to use for a stream header /// packet. /// </summary> /// <param name="packet"> /// A <see cref="ByteVector" /> object containing the first /// packet of an Ogg logical bitstream. /// </param> /// <returns> /// A <see cref="Codec" /> object capable of handling /// <paramref name="packet" /> and subsequent packets from /// the same stream. /// </returns> /// <exception cref="UnsupportedFormatException"> /// No registered codec capable of processing /// <paramref /// name="packet" /> /// could be found. /// </exception> /// <remarks> /// This method will first use <see cref="CodecProvider" /> /// delegates registered with <see cref="AddCodecProvider" /> /// and then attempt to use the built-in codecs. /// </remarks> public static Codec GetCodec(ByteVector packet) { Codec c = null; foreach (var p in providers) { c = p(packet); if (c != null) { return(c); } } c = Vorbis.FromPacket(packet); if (c != null) { return(c); } c = Theora.FromPacket(packet); if (c != null) { return(c); } c = Opus.FromPacket(packet); if (c != null) { return(c); } throw new UnsupportedFormatException("Unknown codec."); }
public override void ExtractAsWav(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string wavPath) { var rawContentBytes = fullFileBytes.SubArray(entry.InnerStreamStartPosition, entry.InnerStreamSize); var vorbis = Vorbis.FromMemory(rawContentBytes); WavWriterLoopPoint[] loopPoints = null; if (entry.IsLooping) { loopPoints = new[] { new WavWriterLoopPoint { StartSample = entry.LoopStart, EndSample = entry.LoopEnd } } } ; var wavWriter = new CustomWavWriter(); wavWriter.WriteWav(new CustomWavWriterRequest() { WavPath = wavPath, Channels = vorbis.Channels, SampleRate = vorbis.SampleRate, WavSampleWriter = new OggVorbisToWavSampleWriter(vorbis), LoopPoints = loopPoints, }); logger.Log($"Created wav audio track at: {wavPath}"); }
private void LoadSong() { var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); path = Path.Combine(path, "music.ogg"); var buffer = File.ReadAllBytes(path); _vorbis = Vorbis.FromMemory(buffer); _effect = new DynamicSoundEffectInstance(_vorbis.SampleRate, (AudioChannels)_vorbis.Channels) { Volume = 0.5f }; _effect.BufferNeeded += (s, a) => SubmitBuffer(); SubmitBuffer(); }
public OggVorbisToWavSampleWriter(Vorbis vorbis) { _vorbis = vorbis; }