void MediaObject::play() { if ((m_state == Phonon::PlayingState) && !m_paused && !m_stopped) return; if ((m_state == Phonon::LoadingState) || (m_state == Phonon::BufferingState) || (m_state == Phonon::ErrorState)) { setError(Phonon::FatalError, QLatin1String("illegale state for playback")); return; } if (m_state == Phonon::StoppedState) stop(); if (m_sourceIsValid) { setState(Phonon::PlayingState); if (!m_paused) { m_nextBufferIndex = true; m_stopped = false; playBuffer(m_soundBuffer1.waveHeader); playBuffer(m_soundBuffer2.waveHeader); } else { if (!(waveOutRestart(m_hWaveOut) == MMSYSERR_NOERROR)) setError(Phonon::NormalError, QLatin1String("cannot resume (system)")); } } else { setError(Phonon::FatalError, QLatin1String("cannot playback invalid source")); } m_paused = false; }
void MediaObject::swapBuffers() { if (m_stopped || m_paused) return; m_currentTime += m_tickIntervalResolution; if (m_tickInterval) { m_tick ++; if (m_tick > (m_tickInterval - 1)) { emit tick(m_currentTime); m_tick = 0; } } if ((m_prefinishMark > 0)&& (m_prefinishMark < m_currentTime)) emit prefinishMarkReached(m_totalTime - m_currentTime); while (!m_bufferingFinished) { setState(Phonon::BufferingState); qWarning() << QLatin1String("buffer underun"); Sleep(20); } setState(Phonon::PlayingState); //if size == o then stop... if (m_nextBufferIndex) { int size = m_soundBuffer1.waveHeader->dwBufferLength = m_soundBuffer1.data.size(); if (size == buffer_size) { playBuffer(m_soundBuffer1.waveHeader); emit outOfData(m_stream, &m_soundBuffer1.data, &m_bufferingFinished); } else { playBuffer(m_soundBuffer1.waveHeader); m_stopped = true; setState(Phonon::StoppedState); emit finished(); seek(0); } } else { int size = m_soundBuffer2.waveHeader->dwBufferLength = m_soundBuffer2.data.size(); if (size == buffer_size) { playBuffer(m_soundBuffer2.waveHeader); emit outOfData(m_stream, &m_soundBuffer2.data, &m_bufferingFinished); } else { playBuffer(m_soundBuffer2.waveHeader); m_stopped = true; setState(Phonon::StoppedState); emit finished(); seek(0); } } m_nextBufferIndex =! m_nextBufferIndex; }
// The real thread function void PspAudio::threadFunction() { assert(_callback); PSP_DEBUG_PRINT_FUNC("audio thread started\n"); while (_init) { // Keep looping so long as we haven't been told to stop if (_paused) PSP_DEBUG_PRINT("audio thread paused\n"); while (_paused) { // delay until we stop pausing PspThread::delayMicros(100000); // 100ms if (!_paused) PSP_DEBUG_PRINT("audio thread unpaused\n"); } PSP_DEBUG_PRINT("remaining samples[%d]\n", _remainingSamples); PSP_DEBUG_PRINT("filling buffer[%d]\n", _bufferToFill); _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in data nextBuffer(_bufferToFill); PSP_DEBUG_PRINT("playing buffer[%d].\n", _bufferToPlay); playBuffer(); nextBuffer(_bufferToPlay); } // while _init // destroy everything free(_buffers[0]); sceAudioChRelease(_pspChannel); PSP_DEBUG_PRINT("audio thread exiting. ****************************\n"); }
void Audio::run() { if (!initialized) { init(); initialized = true; qDebug() << "Audio components initialized."; } if (synth->masterPlaying && synth->isPlaying()) { replaceBuffer(synth->genChunk()); playBuffer(); // resetBuffer(); } if (state != snd_pcm_state(handle)) { state = snd_pcm_state(handle); qDebug() << "State: " << state; } // Buffer underrun (not being written to fast enough) if (state == 4) { snd_pcm_drain(handle); prepareDevice(); } }
int SDLChannelWave::play() { // Preload wave file int bytes = m_wave->readAll(); // Play buffer playBuffer(m_wave->m_buffer, bytes); return 0; }