示例#1
0
/*!
	Plays the sound previously loaded.

	The sound can be composed of vaious melodies, so it is possible to play all at onde (\a melodiy = -1)
	or play only one of the melodies (\a melody = melody id).

	The sound can be played in loop setting \a loop to true.

	The signals can be deactivated by setting \a blockSignal to true.

	Returns true if it was possible to play the sound, otherwise false.

	\sa loadSound(), pauseSound() and stopSound().
*/
	bool Sound::playSound( int melodyId, bool loop, bool blockSignal )
	{
		qDebug() << "[Sound::playSound] - Melody ID:" << melodyId << "loop:" << "blockSignal" << blockSignal;
		if( melodyId < 0 )
		{
			//
			// play all melodies
			//
			qDebug() << "[Sound::playSound] - Play all melodies";
			return playSound( loop, blockSignal );
		}
		_loop = loop;
		blockSignals( blockSignal );
		//
		// Play only one melody
		//
		if( checkIdMelody( melodyId ) )
		{
			if( _melodyList[melodyId]->getNumberNotes() == 0)
			{
				_lastError = CS_MELODY_EMPTY;
				qWarning() << "[Sound::playSound] - melody empty";
				return false;
			}
			//
			// PLAY melody
			//
			if( !_melodyList[melodyId]->playSound( _soundMgr->checkOutSource(), loop, blockSignal ) )
			{
				_lastError = _melodyList[melodyId]->getLastError();
				qWarning() << "[Sound::playSound] - Melody:" << melodyId << "Trying to play error:" << _lastError;
				stopSound();
				return false;
			}

			_playMelody = melodyId;
		}
		else
		{
			return false;
		}

		qDebug() << "[Sound::playSound] - emit soundPlaying of sound: " << _name;
		emit soundPlaying( _name );
		_currTime = 0;
		_pauseTime = 0;

		_stopped = false;
		_flagThreadSoundStopped = false;
		// THREAD
		_timer->restart();
		start();
		return true;
	}
示例#2
0
void StopSound ()
{
   if (soundPlaying())
      {
#ifdef DEBUG
      printf("Interuppting sound\n");
#endif               
      waveOutReset(hw);
      waveOutUnprepareHeader(hw, &current->hdr, sizeof(WAVEHDR));
      current = NULL;   
      }
}
示例#3
0
/*!
	Pauses the sound.

	If it was already paused, resumes playing.

	Returns false if an error ocurred, otherwise true.

	\sa loadSound(), playSound() and stopSound().
*/
	bool Sound::pauseSound()
	{
		bool playing = isPlaying();
		if( playing || isPaused() )
		{
			if( _playMelody < 0 )
			{
				//
				// Check all melodies
				//
				for( int i=0; i < _melodyList.size(); i++ )
				{
					//
					// PAUSE / PLAY
					//
					_melodyList[i]->pauseSound();
				}
			}
			else
			{
				if( checkIdMelody( _playMelody ) )
				{
					//
					// PAUSE / PLAY
					//
					_melodyList[_playMelody]->pauseSound();
				}
				else{
					return false;
				}
			}

			if( playing )
			{
				_pauseTime += _timer->elapsed();
				qDebug() << "[Sound::pauseSound] - Emit soundPaused of sound:" << _name;
				emit soundPaused( _name );
			}
			else
			{
				_timer->restart();
				start();
				qDebug() << "[Sound::pauseSound] - Emit soundPlaying of sound:" << _name;
				emit soundPlaying( _name );
			}
			return true;
		}
		else{
			_lastError = CS_IS_ALREADY_STOPPED;
			return false;
		}
	}
示例#4
0
/*!
	Plays the sound previously loaded.

	The sound can be composed of vaious melodies, so it is possible to play all at onde (\a melodiy = -1)
	or play only one of the melodies (\a melody = melody id).

	The sound can be played in loop setting \a loop to true.

	The signals can be deactivated by setting \a blockSignal to false.

	Returns true if it was possible to play the sound, otherwise false.

	\sa loadSound(), pauseSound() and stopSound().
*/
	bool Sound::playSound( bool loop, bool blockSignal )
	{
		qDebug() << "[Sound::playSound] - Loop:" << loop << "blockSignal" << blockSignal;
		_loop = loop;
		blockSignals( blockSignal );
		int numberNotes = 0;
		//
		// Start to play all melodies
		//
		for(int i=0; i < _melodyList.size(); i++ )
		{
			if( _melodyList[i]->getNumberNotes() > 0 )
			{
				numberNotes += _melodyList[i]->getNumberNotes();
				//
				// PLAY melody
				//
				if( !_melodyList[i]->playSound( _soundMgr->checkOutSource(), loop, blockSignal ) )
				{
					_lastError = _melodyList[i]->getLastError();
					_stopped = false; // To do everything in the stopSound()
					stopSound();
					return false;
				}
			}
		}
		//
		// Empty
		//
		if( numberNotes == 0 )
		{
			_lastError = CS_SOUND_EMPTY;
			return false;
		}

		_playMelody = -1;

		qDebug() << "[Sound::playSound] - Emit soundPlaying of sound:" << _name;
		emit soundPlaying( _name );
		_currTime = 0;
		_pauseTime = 0;

		_stopped = false;
		_flagThreadSoundStopped = false;
		// THREAD
		_timer->restart();
		start();
		return true;

	}
示例#5
0
void ExitSound ()
{
  if (hw)
   {
   if (soundPlaying())
      StopSound();
   waveOutClose(hw);
   }
   hw = NULL;

   /* Delete all the sounds in the cache */
   while (newest)
      {
      struct sound *tmp = newest->older;
      free(newest->hdr.lpData);
      free(newest);
#ifdef DEBUG
      /* Avoid circular lists */
      newest->older=0;
#endif      
      }
   oldest=newest=NULL;
}
示例#6
0
/*!
	Starts playing the stream of file given in loadSound( const QString& filename ).

	The stream can be played in loop setting \a loop to true.

	The signals can be deactivated by setting \a signal to false.

	Returns true if it was possible to play the sample, otherwise false.

	\sa loadSound(), pauseSound() and stopSound().
*/
	bool Stream::playSound( bool loop, bool blockSignal )
	{		
		_loop = loop;
		blockSignals( blockSignal );
		
		qDebug() << "[Stream::playSound]"<< "------------  Stream::playSound( File: " << _filename << " Loop: " << CnotiLogManager::boolean(loop) << ")";
		
		int error = alGetError();

		if( isPlaying() )
		{
			qDebug() << "[Stream::playSound]"<< "----------------------------- ERROR sound stream is too playing... Restarting";
			
			_lastError = CS_IS_ALREADY_PLAYING;
            this->stopSound();
		}

		//
		// Reset some values
		//
		_currTime = 0;
		_pauseTime = 0;

		//
		// Gets a new source & set source volume
		//
		_uiSource = _soundMgr->checkOutSource();
		alSourcef( _uiSource, AL_GAIN, _intensity);
		
		if( !_streamingStarted )
		{
			//
			// Start Streaming
			//
			if( !startStreaming() )
			{
				alDeleteBuffers( NUMBUFFERSOGG, _uiBuffers );
				_streamingStarted = false;
				qDebug() << "[Stream::playSound]" << " ERROR streaming start failed";
				return false;
			}
		}
		else
		{
			qDebug() << "[Stream::playSound]" << "  ----------------------------- streaming already started";
		}
		//
		// PLAY 
		//
        qDebug() << "[Stream::playSound]" << "  ----------------------------- play source";
		_flagThreadSoundStopped = false;
        alSourcePlay( _uiSource );
		error = alGetError();
	    if( error != AL_NO_ERROR )
		{
            qDebug() << "[Stream::playSound]" << "  ----------------------------- ERROR openal failed";
		    alDeleteBuffers( NUMBUFFERSOGG, _uiBuffers );
		    stopSound();
			_lastError = CS_AL_ERROR;
		    return false;
        }
		emit soundPlaying( _name );
        qDebug() << "[Stream::playSound]" << "  ----------------------------- emit soundPlaying of sound: " << _name;
		//
		// THREAD
		//
		_timer->restart();
		start();
		qDebug() << "[Stream::playSound]" << "  ----------------------------- thread start";

		return true;
	}