Qt 4.8
Public Functions | Protected Variables | List of all members
QWSSoundServerBucket Class Reference
Inheritance diagram for QWSSoundServerBucket:
QWSSoundServerProvider

Public Functions

bool finished () const
 
 QWSSoundServerBucket (int d, int wid, int sid)
 
int readySamples (int)
 
 ~QWSSoundServerBucket ()
 
- Public Functions inherited from QWSSoundServerProvider
int add (int *mixl, int *mixr, int count)
 
bool equal (int wid, int sid)
 
int getSample (int off, int bps)
 
int groupId () const
 
bool muted ()
 
 QWSSoundServerProvider (int w, int s)
 
void setMute (bool m)
 
void setPriority (bool p)
 
void setVolume (int lv, int rv)
 
int soundId () const
 
void startSampleRunin ()
 
virtual ~QWSSoundServerProvider ()
 

Protected Variables

QRiffChunk chunk
 
bool mFinishedRead
 
bool mInsufficientSamples
 
int wavedata_remaining
 
- Protected Variables inherited from QWSSoundServerProvider
struct {
   qint32   avgBytesPerSec
 
   qint16   blockAlign
 
   qint16   channels
 
   qint16   formatTag
 
   qint32   samplesPerSec
 
   qint16   wBitsPerSample
 
chunkdata
 
int dev
 
int samples_due
 

Additional Inherited Members

- Static Public Functions inherited from QWSSoundServerProvider
static void setPlayPriorityOnly (bool p)
 
- Protected Functions inherited from QWSSoundServerProvider
int devSamples ()
 
char * prepareBuffer (int &size)
 
void updateBuffer (int read)
 

Detailed Description

Definition at line 518 of file qsoundqss_qws.cpp.

Constructors and Destructors

◆ QWSSoundServerBucket()

QWSSoundServerBucket::QWSSoundServerBucket ( int  d,
int  wid,
int  sid 
)
inline

Definition at line 520 of file qsoundqss_qws.cpp.

521  : QWSSoundServerProvider(wid, sid)
522  {
523  dev = d;
524  wavedata_remaining = -1;
525  mFinishedRead = false;
526  mInsufficientSamples = false;
527  }
double d
Definition: qnumeric_p.h:62
QWSSoundServerProvider(int w, int s)

◆ ~QWSSoundServerBucket()

QWSSoundServerBucket::~QWSSoundServerBucket ( )
inline

Definition at line 528 of file qsoundqss_qws.cpp.

529  {
530  //dev->close();
531  ::close(dev);
532  }

Functions

◆ finished()

bool QWSSoundServerBucket::finished ( ) const
inlinevirtual

Implements QWSSoundServerProvider.

Definition at line 533 of file qsoundqss_qws.cpp.

534  {
535  //return !max;
537  }

◆ readySamples()

int QWSSoundServerBucket::readySamples ( int  )
inlinevirtual

Implements QWSSoundServerProvider.

Definition at line 538 of file qsoundqss_qws.cpp.

539  {
540  int size;
541  char *dest = prepareBuffer(size);
542  // may want to change this to something like
543  // if (data == data1 && max2<<1 < sound_buffer_size
544  // ||
545  // data == data2 && max1<<1 < sound_buffer_size)
546  // so will keep filling off buffer while there is +50% space left
547  if (size > 0 && dest != 0) {
548  while ( wavedata_remaining < 0 ) {
549  //max = 0;
550  wavedata_remaining = -1;
551  // Keep reading chunks...
552  const int n = sizeof(chunk)-sizeof(chunk.data);
553  int nr = ::read(dev, (void*)&chunk,n);
554  if ( nr != n ) {
555  // XXX check error? or don't we care?
556  wavedata_remaining = 0;
557  mFinishedRead = true;
558  } else if ( qstrncmp(chunk.id,"data",4) == 0 ) {
560 
561  //out = max = sound_buffer_size;
562 
563  } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) {
564  char d[4];
565  if ( read(dev, d, 4) != 4 ) {
566  // XXX check error? or don't we care?
567  //qDebug("couldn't read riff");
568  mInsufficientSamples = true;
569  mFinishedRead = true;
570  return 0;
571  } else if ( qstrncmp(d,"WAVE",4) != 0 ) {
572  // skip
573  if ( chunk.size > 1000000000 || lseek(dev,chunk.size-4, SEEK_CUR) == -1 ) {
574  //qDebug("oversized wav chunk");
575  mFinishedRead = true;
576  }
577  }
578  } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) {
579  if ( ::read(dev,(char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) {
580  // XXX check error? or don't we care?
581  //qDebug("couldn't ready chunkdata");
582  mFinishedRead = true;
583  }
584 
585 #define WAVE_FORMAT_PCM 1
586  else
587  {
588  /*
589  ** Endian Fix the chuck data
590  */
591  chunkdata.formatTag = qToLittleEndian( chunkdata.formatTag );
592  chunkdata.channels = qToLittleEndian( chunkdata.channels );
593  chunkdata.samplesPerSec = qToLittleEndian( chunkdata.samplesPerSec );
594  chunkdata.avgBytesPerSec = qToLittleEndian( chunkdata.avgBytesPerSec );
595  chunkdata.blockAlign = qToLittleEndian( chunkdata.blockAlign );
596  chunkdata.wBitsPerSample = qToLittleEndian( chunkdata.wBitsPerSample );
597  if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) {
598  qWarning("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag);
599  mFinishedRead = true;
600  }
601  }
602  } else {
603  // ignored chunk
604  if ( chunk.size > 1000000000 || lseek(dev, chunk.size, SEEK_CUR) == -1) {
605  //qDebug("chunk size too big");
606  mFinishedRead = true;
607  }
608  }
609  }
610  // this looks wrong.
611  if (wavedata_remaining <= 0) {
612  mFinishedRead = true;
613  }
614 
615  }
616  // may want to change this to something like
617  // if (data == data1 && max2<<1 < sound_buffer_size
618  // ||
619  // data == data2 && max1<<1 < sound_buffer_size)
620  // so will keep filling off buffer while there is +50% space left
621 
622  if (wavedata_remaining) {
623  if (size > 0 && dest != 0) {
624  int read = ::read(dev, dest, qMin(size, wavedata_remaining));
625  // XXX check error? or don't we care?
626  wavedata_remaining -= read;
627  updateBuffer(read);
628  if (read <= 0) // data unexpectidly ended
629  mFinishedRead = true;
630  }
631  }
632  int possible = devSamples();
633  if (possible == 0)
634  mInsufficientSamples = true;
635  return possible;
636  }
quint32 size
double d
Definition: qnumeric_p.h:62
void updateBuffer(int read)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * prepareBuffer(int &size)
struct QWSSoundServerProvider::@162 chunkdata
char data[4]
Q_CORE_EXPORT void qWarning(const char *,...)
#define WAVE_FORMAT_PCM
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
T qToLittleEndian(T source)
Definition: qendian.h:341

Properties

◆ chunk

QRiffChunk QWSSoundServerBucket::chunk
protected

Definition at line 639 of file qsoundqss_qws.cpp.

◆ mFinishedRead

bool QWSSoundServerBucket::mFinishedRead
protected

Definition at line 641 of file qsoundqss_qws.cpp.

◆ mInsufficientSamples

bool QWSSoundServerBucket::mInsufficientSamples
protected

Definition at line 642 of file qsoundqss_qws.cpp.

◆ wavedata_remaining

int QWSSoundServerBucket::wavedata_remaining
protected

Definition at line 640 of file qsoundqss_qws.cpp.


The documentation for this class was generated from the following file: