public void Reset() { if (fileStream != null) { fileStream.Close(); fileStream = new AudioFileStream(AudioFileType.MP3); currentByteCount = 0; fileStream.PacketDecoded += AudioPacketDecoded; fileStream.PropertyFound += AudioPropertyFound; } }
/// <summary> /// Loads the audio stream from the given byte array. If the AudioFileStream does not return an Ok status /// then a ContentLoadException is thrown. /// </summary> /// <param name="audiodata">The full byte array of the audio stream.</param> void LoadAudioStream(byte[] audiodata) { AudioFileStream afs = new AudioFileStream(AudioFileType.WAVE); //long pac = afs.DataPacketCount; afs.ParseBytes(audiodata, false); // AudioFileStreamStatus status AudioStreamBasicDescription asbd = afs.StreamBasicDescription; Rate = (float)asbd.SampleRate; Size = (int)afs.DataByteCount; if (asbd.ChannelsPerFrame == 1) { Format = asbd.BitsPerChannel == 8 ? ALFormat.Mono8 : ALFormat.Mono16; } else { Format = asbd.BitsPerChannel == 8 ? ALFormat.Stereo8 : ALFormat.Stereo16; } byte [] d = new byte[afs.DataByteCount]; Array.Copy(audiodata, afs.DataOffset, d, 0, afs.DataByteCount); _data = d; var _dblDuration = (Size / ((asbd.BitsPerChannel / 8) * ((asbd.ChannelsPerFrame == 0) ? 1 : asbd.ChannelsPerFrame))) / asbd.SampleRate; _duration = TimeSpan.FromSeconds(_dblDuration); afs.Close(); //if(status != AudioFileStreamStatus.Ok) { // throw new Content.ContentLoadException("Could not load audio data. The status code was " + status); //} }
void LoadAudioStream(byte[] audiodata) { AudioFileStream afs = new AudioFileStream(AudioFileType.WAVE); //long pac = afs.DataPacketCount; afs.PacketDecoded += HandlePacketDecoded; afs.ParseBytes(audiodata, false); afs.Close(); }
/// <summary> /// Loads the audio stream from the given byte array. If the AudioFileStream does not return an Ok status /// then a ContentLoadException is thrown. /// </summary> /// <param name="audiodata">The full byte array of the audio stream.</param> void LoadAudioStream (byte[] audiodata) { AudioFileStream afs = new AudioFileStream (AudioFileType.WAVE); //long pac = afs.DataPacketCount; AudioFileStreamStatus status = afs.ParseBytes (audiodata, false); AudioStreamBasicDescription asbd = afs.StreamBasicDescription; Rate = (float)asbd.SampleRate; Size = (int)afs.DataByteCount; if (asbd.ChannelsPerFrame == 1) Format = asbd.BitsPerChannel == 8 ? ALFormat.Mono8 : ALFormat.Mono16; else Format = asbd.BitsPerChannel == 8 ? ALFormat.Stereo8 : ALFormat.Stereo16; _data = audiodata; var _dblDuration = (Size / ((asbd.BitsPerChannel / 8) * asbd.ChannelsPerFrame == 0 ? 1 : asbd.ChannelsPerFrame)) / asbd.SampleRate; _duration = TimeSpan.FromSeconds(_dblDuration); afs.Close (); //if(status != AudioFileStreamStatus.Ok) { // throw new Content.ContentLoadException("Could not load audio data. The status code was " + status); //} }
private void WriteWave() { this.prbBytesWritten.Maximum = (int)this.AFS.Length; this.prbBytesWritten.Maximum += 0x2c; if (this.AF.Looped) { this.prbBytesWritten.Maximum += 0x48; // For the "Loop Start" cue marker } { // Write WAV header var BW = new BinaryWriter(this.FS, Encoding.ASCII); // File Header BW.Write("RIFF".ToCharArray()); BW.Write(this.prbBytesWritten.Maximum); // Wave Format Header BW.Write("WAVEfmt ".ToCharArray()); BW.Write((int)0x10); // Wave Format Data BW.Write((short)1); // PCM BW.Write((short)this.AF.Channels); BW.Write((int)this.AF.SampleRate); BW.Write((int)(2 * this.AF.Channels * this.AF.SampleRate)); // bytes per second BW.Write((short)(2 * this.AF.Channels)); // bytes per sample BW.Write((short)16); // bits // Wave Data Header BW.Write("data".ToCharArray()); BW.Write((int)this.AFS.Length); } this.prbBytesWritten.Value = 0x2c; // Write PCM data var data = new byte[this.ChunkSize]; while (true) { int read = AFS.Read(data, 0, this.ChunkSize); this.prbBytesWritten.Value += read; FS.Write(data, 0, read); if (read != this.ChunkSize) { break; } } AFS.Close(); // Write "Loop Start" cue marker if (this.AF.Looped) { var BW = new BinaryWriter(this.FS, Encoding.ASCII); BW.Write("cue ".ToCharArray()); BW.Write((int)0x1c); BW.Write((int)1); BW.Write((int)1); BW.Write((int)(this.AF.LoopStart * this.AF.SampleRate)); BW.Write("data".ToCharArray()); BW.Write((int)0); BW.Write((int)0); BW.Write((int)(this.AF.LoopStart * this.AF.SampleRate)); BW.Write("LIST".ToCharArray()); BW.Write((int)0x10 + 12); BW.Write("adtl".ToCharArray()); BW.Write("labl".ToCharArray()); BW.Write((int)0x04 + 12); BW.Write((int)1); BW.Write("Loop Start\0\0".ToCharArray()); this.prbBytesWritten.Value += 0x48; } FS.Close(); }
void LoadAudioStream (byte[] audiodata) { AudioFileStream afs = new AudioFileStream (AudioFileType.WAVE); //long pac = afs.DataPacketCount; afs.PacketDecoded += HandlePacketDecoded; afs.ParseBytes (audiodata, false); afs.Close (); }