Exemplo n.º 1
0
void kGUIAudio::Play(int rate,int channels,const unsigned char *sample,unsigned long samplesize,bool copy,bool loop)
{
	AudioBuffer *ab;

//	kGUI::Trace("Play:Lock (%s)\n",m_mutex.GetIsLocked()==true?"locked":"unlocked");
	
	m_mutex.Lock();

	if(m_playing==false)
	{
//		kGUI::Trace("Play:%08x, Not Playing, reset packets!\n",this);
		m_playbuffer=0;
		m_numbuffers=0;
	}
	m_rate=rate;
	m_channels=channels;
	m_loop=loop;

//	kGUI::Trace("Play:%08x, Adding Packet, rate=%d,channels=%d,size=%d\n",this,rate,channels,samplesize);

	/* can we append this packet to the last pending packet? */
	if(copy && m_numbuffers>m_playbuffer)
	{
		ab=m_buffers.GetEntry(m_numbuffers-1);
		ab->Append(samplesize,sample);
	}
	else
	{
		/* buffer sample data */
		ab=m_manager->GetBuffer();
		m_buffers.SetEntry(m_numbuffers,ab);
		ab->Set(samplesize,sample,copy);
		++m_numbuffers;
	}

	PlayBuffer();
	m_mutex.UnLock();
}