internal static void ThrowRawkError(RawkError error) { switch (error) { case RawkError.InvalidParameter: throw new ArgumentException(); case RawkError.OutOfMemory: throw new InsufficientMemoryException(); case RawkError.FileError: throw new IOException(); case RawkError.NotVorbis: case RawkError.NotBink: case RawkError.NotFsb: case RawkError.NotVgs: throw new NotSupportedException("Input audio file could not be identified"); case RawkError.MisalignedSamplingRates: throw new NotSupportedException("Streams with different sampling rates are not supported"); case RawkError.Unknown: throw new Exception(); } }
public Decoder(string filename, AudioFormat format) : this(format) { RawkError error = RawkError.Unknown; int channels; int samplerate; long samples; switch (Format) { case AudioFormat.VorbisOgg: error = CreateVorbisDecoder(filename, out channels, out samplerate, out samples, out identifier); break; case AudioFormat.FmodSoundBank: error = CreateFsbDecoder(filename, out channels, out samplerate, out samples, out identifier); break; case AudioFormat.BinkAudio: case AudioFormat.BinkEncryptedRB2: error = CreateBinkDecoder(filename, out channels, out samplerate, out samples, out identifier); break; case AudioFormat.Vgs: error = CreateVgsDecoder(filename, out channels, out samplerate, out samples, out identifier); break; default: throw new ArgumentException(); } Channels = channels; SampleRate = samplerate; Samples = samples; ThrowRawkError(error); AudioBuffer = new JaggedShortArray(Channels, BufferSize); }
public Encoder(Stream stream, int channels, int samplerate, int targetsamplerate, int bitrate) : this(channels, samplerate, targetsamplerate, bitrate) { callbacks = new Callbacks(stream, false); RawkError error = CreateEncoder(ref callbacks.Struct, Channels, SampleRate, targetsamplerate, BitRate, out identifier); ThrowRawkError(error); }
public int Read(int count) { if (disposed) { throw new ObjectDisposedException(string.Empty); } if (eof) { return(0); } RawkError error = RawkError.Unknown; count = Math.Min(count, BufferSize); switch (Format) { case AudioFormat.VorbisOgg: error = VorbisDecompress(identifier, AudioBuffer.Pointer, count); break; case AudioFormat.FmodSoundBank: error = FsbDecompress(identifier, AudioBuffer.Pointer, count); break; case AudioFormat.BinkAudio: case AudioFormat.BinkEncryptedRB2: error = BinkDecompress(identifier, AudioBuffer.Pointer, count); break; case AudioFormat.Vgs: error = VgsDecompress(identifier, AudioBuffer.Pointer, count); break; default: break; } if (error == RawkError.FileError) { eof = true; return(0); // EOF } ThrowRawkError(error); Position += (int)error; if (Position == Samples) { eof = true; } return((int)error); // Returns positive number of read samples }
public void Write(JaggedShortArray samples, int count) { if (disposed) { throw new ObjectDisposedException(string.Empty); } RawkError error = Compress(identifier, samples.Pointer, count); ThrowRawkError(error); }
public void Seek(long sample) { if (disposed) { throw new ObjectDisposedException(string.Empty); } RawkError error = RawkError.Unknown; switch (Format) { case AudioFormat.VorbisOgg: error = VorbisSeek(identifier, sample); break; case AudioFormat.FmodSoundBank: error = FsbSeek(identifier, sample); break; case AudioFormat.BinkAudio: case AudioFormat.BinkEncryptedRB2: error = BinkSeek(identifier, sample); break; case AudioFormat.Vgs: error = VgsSeek(identifier, sample); break; } // BUG: Seeking to the beginning of the Bink decoder returns INVALID_PARAM because it tries to decode 0 samples if (Format == AudioFormat.BinkAudio || Format == AudioFormat.BinkEncryptedRB2 && sample == 0 && error == RawkError.InvalidParameter) { error = RawkError.OK; } ThrowRawkError(error); eof = false; Position = sample; }
public Encoder(string filename, int channels, int samplerate, int targetsamplerate, int bitrate) : this(channels, samplerate, targetsamplerate, bitrate) { RawkError error = CreateEncoder(filename, Channels, SampleRate, targetsamplerate, BitRate, out identifier); ThrowRawkError(error); }