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 bool StreamAudio(int buffer) { // The size of our abstracted buffer. const int BUFFER_SIZE = 4096 * 2; // Store our abstracted buffer into here. List <float> data = new List <float>(); // Be sure we have an audio stream first! if (Video.audioStream == IntPtr.Zero) { return(false); // NOPE } // Add to the buffer from the decoder until it's large enough. while (data.Count < BUFFER_SIZE && State != MediaState.Stopped) { data.AddRange( TheoraPlay.getSamples( currentAudio.samples, currentAudio.frames * currentAudio.channels ) ); // We've copied the audio, so free this. TheoraPlay.THEORAPLAY_freeAudio(Video.audioStream); do { Video.audioStream = TheoraPlay.THEORAPLAY_getAudio(Video.theoraDecoder); if (State == MediaState.Stopped) { // Screw it, just bail out ASAP. return(false); } } while (Video.audioStream == IntPtr.Zero); currentAudio = TheoraPlay.getAudioPacket(Video.audioStream); if ((BUFFER_SIZE - data.Count) < 4096) { break; } } // If we actually got data, buffer it into OpenAL. if (data.Count > 0) { AL.BufferData( buffer, (currentAudio.channels == 2) ? ALFormat.StereoFloat32Ext : ALFormat.MonoFloat32Ext, data.ToArray(), data.Count * 2 * currentAudio.channels, // Dear OpenAL: WTF?! Love, flibit currentAudio.freq ); return(true); } return(false); }
private bool StreamAudio(int buffer) { // The size of our abstracted buffer. const int BUFFER_SIZE = 4096 * 2; // Store our abstracted buffer into here. List <float> data = new List <float>(); // We'll store this here, so alBufferData can use it too. TheoraPlay.THEORAPLAY_AudioPacket currentAudio; currentAudio.channels = 0; currentAudio.freq = 0; // Add to the buffer from the decoder until it's large enough. while ( State != MediaState.Stopped && TheoraPlay.THEORAPLAY_availableAudio(Video.TheoraDecoder) == 0 ) { ; } while ( data.Count < BUFFER_SIZE && State != MediaState.Stopped && TheoraPlay.THEORAPLAY_availableAudio(Video.TheoraDecoder) > 0 ) { IntPtr audioPtr = TheoraPlay.THEORAPLAY_getAudio(Video.TheoraDecoder); currentAudio = TheoraPlay.getAudioPacket(audioPtr); data.AddRange( TheoraPlay.getSamples( currentAudio.samples, currentAudio.frames * currentAudio.channels ) ); TheoraPlay.THEORAPLAY_freeAudio(audioPtr); } // If we actually got data, buffer it into OpenAL. if (data.Count > 0) { AL.BufferData( buffer, (currentAudio.channels == 2) ? ALFormat.StereoFloat32Ext : ALFormat.MonoFloat32Ext, data.ToArray(), data.Count * 2 * currentAudio.channels, // Dear OpenAL: WTF?! Love, flibit currentAudio.freq ); return(true); } return(false); }
private bool StreamAudio() { // The size of our abstracted buffer. const int BUFFER_SIZE = 4096 * 2; // Store our abstracted buffer into here. List <float> data = new List <float>(); // We'll store this here, so alBufferData can use it too. TheoraPlay.THEORAPLAY_AudioPacket currentAudio; // There might be an initial period of silence, so forcibly push through. while (audioStream.State == SoundState.Stopped && TheoraPlay.THEORAPLAY_availableAudio(Video.theoraDecoder) == 0) { ; } // Add to the buffer from the decoder until it's large enough. while (data.Count < BUFFER_SIZE) { IntPtr audioPtr = TheoraPlay.THEORAPLAY_getAudio(Video.theoraDecoder); if (audioPtr == IntPtr.Zero) { // FIXME: THEORAPLAY_availableAudio has rounding issues! -flibit break; } currentAudio = TheoraPlay.getAudioPacket(audioPtr); data.AddRange( TheoraPlay.getSamples( currentAudio.samples, currentAudio.frames * currentAudio.channels ) ); TheoraPlay.THEORAPLAY_freeAudio(audioPtr); } // If we actually got data, queue it! if (data.Count > 0) { audioStream.SubmitFloatBufferEXT(data.ToArray()); } else if (TheoraPlay.THEORAPLAY_isDecoding(Video.theoraDecoder) == 0) { // Okay, we ran out. No need for this! audioStream.BufferNeeded -= OnBufferRequest; return(false); } return(true); }
private bool StreamAudio() { // The size of our abstracted buffer. const int BUFFER_SIZE = 4096 * 2; // Store our abstracted buffer into here. List <float> data = new List <float>(); // We'll store this here, so alBufferData can use it too. TheoraPlay.THEORAPLAY_AudioPacket currentAudio; currentAudio.channels = 0; currentAudio.freq = 0; // There might be an initial period of silence, so forcibly push through. while (audioStream.State == SoundState.Stopped && TheoraPlay.THEORAPLAY_availableAudio(Video.theoraDecoder) == 0) { ; } // Add to the buffer from the decoder until it's large enough. while (data.Count < BUFFER_SIZE && TheoraPlay.THEORAPLAY_availableAudio(Video.theoraDecoder) > 0) { IntPtr audioPtr = TheoraPlay.THEORAPLAY_getAudio(Video.theoraDecoder); currentAudio = TheoraPlay.getAudioPacket(audioPtr); data.AddRange( TheoraPlay.getSamples( currentAudio.samples, currentAudio.frames * currentAudio.channels ) ); TheoraPlay.THEORAPLAY_freeAudio(audioPtr); } // If we actually got data, buffer it into OpenAL. if (data.Count > 0) { audioStream.SubmitFloatBuffer( data.ToArray(), currentAudio.channels, currentAudio.freq ); return(true); } return(false); }
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()); } } }