Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SoundPlayThread.cc

Go to the documentation of this file.
00001 #include "SoundPlayThread.h"
00002 #include "Shared/Config.h"
00003 #include "Sound/SoundManager.h"
00004 
00005 //better to put this here instead of the header
00006 using namespace std; 
00007 
00008 void SoundPlayThread::reset() {
00009   if(sndman->getNumPlaying()<=0 && isStarted())
00010     stop();
00011   else if(sndman->getNumPlaying()>0 && !isStarted())
00012     start();
00013 }
00014 
00015 bool SoundPlayThread::launched() {
00016   buffersInFlight=0;
00017   //cout << "SoundPlayThread launched " << buffersInFlight << ' ' << sndman->getNumPlaying() << endl;
00018   return sndman->getNumPlaying()>0;
00019 }
00020 
00021 bool SoundPlayThread::poll() {
00022   if(buffersInFlight>0)
00023     buffersInFlight--; // poll has timed out, remove a buffer from in-flight
00024   size_t tgtsize = BUFFER_TIME*(config->sound.sample_bits/8)*config->sound.sample_rate/1000;
00025   if(bufsize!=tgtsize) {
00026     delete buf;
00027     buf = new char[bufsize=tgtsize];
00028   }
00029   while(buffersInFlight<NUM_BUFFERS) {
00030     sndman->CopyTo(buf,bufsize);
00031     // interface with host hardware to play the sound...?
00032     buffersInFlight++;
00033   }
00034   //cout << "SoundPlayThread polled " << buffersInFlight << ' ' << sndman->getNumPlaying() << endl;
00035   return sndman->getNumPlaying()>0;
00036 }
00037 
00038 /*! @file
00039  * @brief 
00040  * @author Ethan Tira-Thompson (ejt) (Creator)
00041  *
00042  * $Author: ejt $
00043  * $Name: tekkotsu-4_0 $
00044  * $Revision: 1.2 $
00045  * $State: Exp $
00046  * $Date: 2007/10/12 16:55:04 $
00047  */

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4