Exemplo n.º 1
0
	/*!
	* \brief Gets the status of the music
	* \return Enumeration of type SoundStatus (Playing, Stopped, ...)
	*
	* \remark Music must be valid when calling this function
	*/
	SoundStatus Music::GetStatus() const
	{
		NazaraAssert(m_impl, "Music not created");

		SoundStatus status = GetInternalStatus();

		// To compensate any delays (or the timelaps between Play() and the thread startup)
		if (m_impl->streaming && status == SoundStatus_Stopped)
			status = SoundStatus_Playing;

		return status;
	}
Exemplo n.º 2
0
void NzMusic::MusicThread()
{
	ALuint buffers[NAZARA_AUDIO_STREAMED_BUFFER_COUNT];
	alGenBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);

	for (unsigned int i = 0; i < NAZARA_AUDIO_STREAMED_BUFFER_COUNT; ++i)
	{
		if (FillAndQueueBuffer(buffers[i])) // Fin du fichier ?
			break; // Nous avons atteint la fin du fichier, inutile de rajouter des buffers
	}

	alSourcePlay(m_source);

	while (m_impl->streaming)
	{
		nzSoundStatus status = GetInternalStatus();
		if (status == nzSoundStatus_Stopped)
		{
			m_impl->streaming = false;
			break;
		}

		ALint processedCount = 0;
		alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &processedCount);

		ALuint buffer;
		while (processedCount--)
		{
			alSourceUnqueueBuffers(m_source, 1, &buffer);
			if (FillAndQueueBuffer(buffer))
				break;
		}

		NzThread::Sleep(50);
	}

	alSourceStop(m_source);

	ALint queuedBufferCount;
	alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queuedBufferCount);

	ALuint buffer;
	for (ALint i = 0; i < queuedBufferCount; ++i)
		alSourceUnqueueBuffers(m_source, 1, &buffer);

	alDeleteBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);
}
Exemplo n.º 3
0
nzSoundStatus NzMusic::GetStatus() const
{
	#if NAZARA_AUDIO_SAFE
	if (!m_impl)
	{
		NazaraError("Music not created");
		return nzSoundStatus_Stopped;
	}
	#endif

	nzSoundStatus status = GetInternalStatus();

	if (m_impl->streaming && status == nzSoundStatus_Stopped)
		status = nzSoundStatus_Playing;

	return status;
}
Exemplo n.º 4
0
	SoundStatus Music::GetStatus() const
	{
		#if NAZARA_AUDIO_SAFE
		if (!m_impl)
		{
			NazaraError("Music not created");
			return SoundStatus_Stopped;
		}
		#endif

		SoundStatus status = GetInternalStatus();

		// Pour compenser les éventuels retards (ou le laps de temps entre Play() et la mise en route du thread)
		if (m_impl->streaming && status == SoundStatus_Stopped)
			status = SoundStatus_Playing;

		return status;
	}
Exemplo n.º 5
0
nzSoundStatus NzSound::GetStatus() const
{
	return GetInternalStatus();
}
Exemplo n.º 6
0
	void Music::MusicThread()
	{
		// Allocation of streaming buffers
		ALuint buffers[NAZARA_AUDIO_STREAMED_BUFFER_COUNT];
		alGenBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);

		for (unsigned int buffer : buffers)
		{
			if (FillAndQueueBuffer(buffer))
				break; // We have reached the end of the stream, there is no use to add new buffers
		}

		alSourcePlay(m_source);

		// Reading loop (Filling new buffers as playing)
		while (m_impl->streaming)
		{
			// The reading has stopped, we have reached the end of the stream
			SoundStatus status = GetInternalStatus();
			if (status == SoundStatus_Stopped)
			{
				m_impl->streaming = false;
				break;
			}

			Nz::LockGuard lock(m_impl->bufferLock);

			// We treat read buffers
			ALint processedCount = 0;
			alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &processedCount);
			while (processedCount--)
			{
				ALuint buffer;
				alSourceUnqueueBuffers(m_source, 1, &buffer);

				ALint bits, size;
				alGetBufferi(buffer, AL_BITS, &bits);
				alGetBufferi(buffer, AL_SIZE, &size);

				if (bits != 0)
					m_impl->processedSamples += (8 * size) / bits;

				if (FillAndQueueBuffer(buffer))
					break;
			}

			lock.Unlock();

			// We go back to sleep
			Thread::Sleep(50);
		}

		// Stop playing of the sound (in the case where it has not been already done)
		alSourceStop(m_source);

		// We delete buffers from the stream
		ALint queuedBufferCount;
		alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queuedBufferCount);

		ALuint buffer;
		for (ALint i = 0; i < queuedBufferCount; ++i)
			alSourceUnqueueBuffers(m_source, 1, &buffer);

		alDeleteBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);
	}
Exemplo n.º 7
0
	void Music::MusicThread()
	{
		// Allocation des buffers de streaming
		ALuint buffers[NAZARA_AUDIO_STREAMED_BUFFER_COUNT];
		alGenBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);

		for (unsigned int i = 0; i < NAZARA_AUDIO_STREAMED_BUFFER_COUNT; ++i)
		{
			if (FillAndQueueBuffer(buffers[i]))
				break; // Nous avons atteint la fin du stream, inutile de rajouter des buffers
		}

		alSourcePlay(m_source);

		// Boucle de lecture (remplissage de nouveaux buffers au fur et à mesure)
		while (m_impl->streaming)
		{
			// La lecture s'est arrêtée, nous avons atteint la fin du stream
			SoundStatus status = GetInternalStatus();
			if (status == SoundStatus_Stopped)
			{
				m_impl->streaming = false;
				break;
			}

			Nz::LockGuard lock(m_impl->bufferLock);

			// On traite les buffers lus
			ALint processedCount = 0;
			alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &processedCount);
			while (processedCount--)
			{
				ALuint buffer;
				alSourceUnqueueBuffers(m_source, 1, &buffer);
				
				ALint bits, size;
				alGetBufferi(buffer, AL_BITS, &bits);
				alGetBufferi(buffer, AL_SIZE, &size);
				
				if (bits != 0)
					m_impl->processedSamples += (8 * size) / bits;

				if (FillAndQueueBuffer(buffer))
					break;
			}

			lock.Unlock();

			// On retourne dormir un peu
			Thread::Sleep(50);
		}

		// Arrêt de la lecture du son (dans le cas où ça ne serait pas déjà fait)
		alSourceStop(m_source);

		// On supprime les buffers du stream
		ALint queuedBufferCount;
		alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queuedBufferCount);

		ALuint buffer;
		for (ALint i = 0; i < queuedBufferCount; ++i)
			alSourceUnqueueBuffers(m_source, 1, &buffer);

		alDeleteBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);
	}