private void DecodeAudio() { const int bufferSize = 4096 * 2; while (State != MediaState.Stopped && _theoraVideo != null) { var theoraDecoder = _theoraVideo.TheoraDecoder; while (State != MediaState.Stopped && TheoraPlay.THEORAPLAY_availableAudio(theoraDecoder) == 0) { continue; } var data = new List <float>(); TheoraPlay.THEORAPLAY_AudioPacket currentAudio; while (data.Count < bufferSize && TheoraPlay.THEORAPLAY_availableAudio(theoraDecoder) > 0) { var audioPtr = TheoraPlay.THEORAPLAY_getAudio(theoraDecoder); currentAudio = TheoraPlay.getAudioPacket(audioPtr); data.AddRange(TheoraPlay.getSamples(currentAudio.samples, currentAudio.frames * currentAudio.channels)); TheoraPlay.THEORAPLAY_freeAudio(audioPtr); } if (State == MediaState.Playing) { _fmodTheoraStream.Stream(data.ToArray()); } } }
private void DecodeAudio() { const int bufferSize = 4096 * 2; while (State != MediaState.Stopped && _theoraVideo != null) { var theoraDecoder = _theoraVideo.TheoraDecoder; while (State != MediaState.Stopped && TheoraPlay.THEORAPLAY_availableAudio(theoraDecoder) == 0) { // don't use all of the cpu while waiting for data Thread.Sleep(1); // if the game object has somehow been disposed with the state being set to stopped, then the thread will never // exit, so check for that explicitly here if (GameObj != null && GameObj.Disposed) { return; } } var data = new List <float>(); TheoraPlay.THEORAPLAY_AudioPacket currentAudio; while (data.Count < bufferSize && TheoraPlay.THEORAPLAY_availableAudio(theoraDecoder) > 0) { var audioPtr = TheoraPlay.THEORAPLAY_getAudio(theoraDecoder); currentAudio = TheoraPlay.getAudioPacket(audioPtr); data.AddRange(TheoraPlay.getSamples(currentAudio.samples, currentAudio.frames * currentAudio.channels)); TheoraPlay.THEORAPLAY_freeAudio(audioPtr); } if (State == MediaState.Playing) { _fmodTheoraStream.Stream(data.ToArray()); } } }