/// <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); //} }
void CheckStatus (AudioFileStreamStatus status) { if (status != AudioFileStreamStatus.Ok) LoggingService.LogError (null, "Buggy status: {0}", status); }