Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Protected Variables | Properties | Static Private Attributes | List of all members
QWSSoundServerProvider Class Referenceabstract
Inheritance diagram for QWSSoundServerProvider:
QWSSoundServerBucket QWSSoundServerStream

Public Functions

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

Static Public Functions

static void setPlayPriorityOnly (bool p)
 

Protected Functions

int devSamples ()
 
char * prepareBuffer (int &size)
 
void updateBuffer (int read)
 

Protected Variables

struct {
   qint32   avgBytesPerSec
 
   qint16   blockAlign
 
   qint16   channels
 
   qint16   formatTag
 
   qint32   samplesPerSec
 
   qint16   wBitsPerSample
 
chunkdata
 
int dev
 
int samples_due
 

Properties

uchardata
 
uchar data1 [sound_buffer_size+4]
 
uchar data2 [sound_buffer_size+4]
 
bool isPriority
 
int leftVolume
 
int * max
 
int max1
 
int max2
 
bool mMuted
 
int mSid
 
int mWid
 
int out
 
int rightVolume
 
int sampleRunin
 

Static Private Attributes

static int priorityExists = 0
 

Detailed Description

Definition at line 280 of file qsoundqss_qws.cpp.

Constructors and Destructors

◆ QWSSoundServerProvider()

QWSSoundServerProvider::QWSSoundServerProvider ( int  w,
int  s 
)
inline

Definition at line 282 of file qsoundqss_qws.cpp.

283  : mWid(w), mSid(s), mMuted(false)
284  {
285  leftVolume = maxVolume>>1;
286  rightVolume = maxVolume>>1;
287  isPriority = false;
288  samples_due = 0;
289  max1 = max2 = out = 0;// = sound_buffer_size;
290  data = data1;
291  max = &max1;
292  sampleRunin = 0;
293  dev = -1;
294  }
static const int maxVolume
uchar data1[sound_buffer_size+4]

◆ ~QWSSoundServerProvider()

virtual QWSSoundServerProvider::~QWSSoundServerProvider ( )
inlinevirtual

Definition at line 296 of file qsoundqss_qws.cpp.

296  {
297  }

Functions

◆ add()

int QWSSoundServerProvider::add ( int *  mixl,
int *  mixr,
int  count 
)
inline

Definition at line 350 of file qsoundqss_qws.cpp.

Referenced by QWSSoundServerPrivate::feedDevice().

351  {
352  int bytesPerSample = chunkdata.wBitsPerSample >> 3;
353 
354  if ( mMuted ) {
355  sampleRunin -= qMin(sampleRunin,count);
356  while (count && (dev != -1)) {
357  if (out >= *max) {
358  // switch buffers
359  out = 0;
360  if (data == data1 && max2 != 0) {
361  data = data2;
362  max = &max2;
363  max1 = 0;
364  } else if (data == data2 && max1 != 0) {
365  data = data1;
366  max = &max1;
367  max2 = 0;
368  } else {
369  qDebug("QSS Read Error: both buffers empty");
370  return 0;
371  }
372  }
374  while (count && samples_due >= chunkdata.samplesPerSec) {
375  samples_due -= chunkdata.samplesPerSec;
376  count--;
377  }
378  out += bytesPerSample * chunkdata.channels;
379  }
380  return count;
381  }
382 
383  // This shouldn't be the case
384  if ( !mixl || !mixr )
385  return 0;
386 
387  int lVolNum = leftVolume, lVolDen = maxVolume;
388  int rVolNum = rightVolume, rVolDen = maxVolume;
389  if (priorityExists > 0 && !isPriority) {
390  lVolNum = 0; // later, make this gradually fade in and out.
391  lVolDen = 5;
392  rVolNum = 0;
393  rVolDen = 5;
394  }
395 
396  while (count && (dev != -1)) {
397  if (out >= *max) {
398  // switch buffers
399  out = 0;
400  if (data == data1 && max2 != 0) {
401  data = data2;
402  max = &max2;
403  max1 = 0;
404  } else if (data == data2 && max1 != 0) {
405  data = data1;
406  max = &max1;
407  max2 = 0;
408  } else {
409  qDebug("QSS Read Error: both buffers empty");
410  return 0;
411  }
412  }
414  if (count && samples_due >= chunkdata.samplesPerSec) {
415  int l = getSample(0,bytesPerSample)*lVolNum/lVolDen;
416  int r = (chunkdata.channels == 2) ? getSample(1,bytesPerSample)*rVolNum/rVolDen : l;
417  if (!sound_stereo && chunkdata.channels == 2)
418  l += r;
419  if (sampleRunin) {
420  while (sampleRunin && count && samples_due >= chunkdata.samplesPerSec) {
421  mixl++;
422  if (sound_stereo)
423  mixr++;
424  samples_due -= chunkdata.samplesPerSec;
425  sampleRunin--;
426  count--;
427  }
428  }
429  while (count && samples_due >= chunkdata.samplesPerSec) {
430  *mixl++ += l;
431  if (sound_stereo)
432  *mixr++ += r;
433  samples_due -= chunkdata.samplesPerSec;
434  count--;
435  }
436  }
437 
438  // optimize out manipulation of sample if downsampling and we skip it
439  out += bytesPerSample * chunkdata.channels;
440  }
441 
442  return count;
443  }
static int sound_stereo
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static int sound_speed
uchar data2[sound_buffer_size+4]
Q_CORE_EXPORT void qDebug(const char *,...)
int getSample(int off, int bps)
struct QWSSoundServerProvider::@162 chunkdata
QFactoryLoader * l
static const int maxVolume
uchar data1[sound_buffer_size+4]

◆ devSamples()

int QWSSoundServerProvider::devSamples ( )
inlineprotected

Definition at line 481 of file qsoundqss_qws.cpp.

482  {
483  int possible = (((max1+max2-out) / ((chunkdata.wBitsPerSample>>3)*chunkdata.channels))
484  *sound_speed)/chunkdata.samplesPerSec;
485 
486  return possible;
487  }
static int sound_speed
struct QWSSoundServerProvider::@162 chunkdata

◆ equal()

bool QWSSoundServerProvider::equal ( int  wid,
int  sid 
)
inline

◆ finished()

virtual bool QWSSoundServerProvider::finished ( ) const
pure virtual

◆ getSample()

int QWSSoundServerProvider::getSample ( int  off,
int  bps 
)
inline

Definition at line 340 of file qsoundqss_qws.cpp.

340  {
341 
342  //
343  // 16-bit audio data is converted to native endian so that it can be scaled
344  // Yes, this is ugly on a BigEndian machine
345  // Perhaps it shouldn't be scaled at all
346  //
347  return (bps == 1) ? (data[out+off] - 128) * 128 : qToLittleEndian(((short*)data)[(out/2)+off]);
348  }
T qToLittleEndian(T source)
Definition: qendian.h:341

◆ groupId()

int QWSSoundServerProvider::groupId ( ) const
inline

◆ muted()

bool QWSSoundServerProvider::muted ( )
inline

Definition at line 314 of file qsoundqss_qws.cpp.

314 { return mMuted; }

◆ prepareBuffer()

char* QWSSoundServerProvider::prepareBuffer ( int &  size)
inlineprotected

Definition at line 454 of file qsoundqss_qws.cpp.

455  {
456  // keep reading as long as there is 50 % or more room in off buffer.
457  if (data == data1 && (max2<<1 < sound_buffer_size)) {
458  size=sound_buffer_size - max2;
459  return (char *)data2;
460  } else if (data == data2 && (max1<<1 < sound_buffer_size)) {
461  size=sound_buffer_size - max1;
462  return (char *)data1;
463  } else {
464  size = 0;
465  return 0;
466  }
467  }
uchar data2[sound_buffer_size+4]
uchar data1[sound_buffer_size+4]
static const int sound_buffer_size

◆ readySamples()

virtual int QWSSoundServerProvider::readySamples ( int  )
pure virtual

◆ setMute()

void QWSSoundServerProvider::setMute ( bool  m)
inline

◆ setPlayPriorityOnly()

static void QWSSoundServerProvider::setPlayPriorityOnly ( bool  p)
inlinestatic

Definition at line 323 of file qsoundqss_qws.cpp.

Referenced by QWSSoundServerPrivate::playPriorityOnly().

324  {
325  if (p)
326  priorityExists++;
327  else
328  priorityExists--;
329 
330  if (priorityExists < 0)
331  qDebug("QSS: got more priority offs than ons");
332  }
Q_CORE_EXPORT void qDebug(const char *,...)

◆ setPriority()

void QWSSoundServerProvider::setPriority ( bool  p)
inline

Definition at line 316 of file qsoundqss_qws.cpp.

Referenced by QWSSoundServerPrivate::playFile(), and QWSSoundServerPrivate::playRawFile().

316  {
317  if (p != isPriority) {
318  isPriority = p; // currently meaningless.
319  }
320  }

◆ setVolume()

void QWSSoundServerProvider::setVolume ( int  lv,
int  rv 
)
inline

Definition at line 308 of file qsoundqss_qws.cpp.

Referenced by QWSSoundServerPrivate::checkPresetVolumes(), QWSSoundServerPrivate::playFile(), QWSSoundServerPrivate::QWSSoundServerPrivate(), QWSSoundServerPrivate::setVolume(), and QWSSoundServerPrivate::~QWSSoundServerPrivate().

308  {
309  leftVolume = qMin(maxVolume, qMax(0, lv));
310  rightVolume = qMin(maxVolume, qMax(0, rv));
311  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static const int maxVolume

◆ soundId()

int QWSSoundServerProvider::soundId ( ) const
inline

◆ startSampleRunin()

void QWSSoundServerProvider::startSampleRunin ( )
inline

Definition at line 302 of file qsoundqss_qws.cpp.

302  {
303  // inteded to provide even audio return from mute/pause/dead samples.
304  //sampleRunin = runinLength; // or more?
305  }

◆ updateBuffer()

void QWSSoundServerProvider::updateBuffer ( int  read)
inlineprotected

Definition at line 469 of file qsoundqss_qws.cpp.

470  {
471  // always reads to off buffer.
472  if (read >= 0) {
473  if (data == data2) {
474  max1 = read;
475  } else {
476  max2 = read;
477  }
478  }
479  }
uchar data2[sound_buffer_size+4]

Properties

◆ avgBytesPerSec

qint32 QWSSoundServerProvider::avgBytesPerSec

Definition at line 494 of file qsoundqss_qws.cpp.

◆ blockAlign

qint16 QWSSoundServerProvider::blockAlign

Definition at line 495 of file qsoundqss_qws.cpp.

◆ channels

qint16 QWSSoundServerProvider::channels

◆ chunkdata

struct { ... } QWSSoundServerProvider::chunkdata

◆ data

uchar* QWSSoundServerProvider::data
private

Definition at line 508 of file qsoundqss_qws.cpp.

Referenced by QWSSoundServerPrivate::feedDevice().

◆ data1

uchar QWSSoundServerProvider::data1[sound_buffer_size+4]
private

Definition at line 509 of file qsoundqss_qws.cpp.

◆ data2

uchar QWSSoundServerProvider::data2[sound_buffer_size+4]
private

Definition at line 510 of file qsoundqss_qws.cpp.

◆ dev

int QWSSoundServerProvider::dev
protected

Definition at line 498 of file qsoundqss_qws.cpp.

◆ formatTag

qint16 QWSSoundServerProvider::formatTag

Definition at line 491 of file qsoundqss_qws.cpp.

◆ isPriority

bool QWSSoundServerProvider::isPriority
private

Definition at line 505 of file qsoundqss_qws.cpp.

◆ leftVolume

int QWSSoundServerProvider::leftVolume
private

Definition at line 503 of file qsoundqss_qws.cpp.

◆ max

int* QWSSoundServerProvider::max
private

Definition at line 507 of file qsoundqss_qws.cpp.

◆ max1

int QWSSoundServerProvider::max1
private

Definition at line 511 of file qsoundqss_qws.cpp.

◆ max2

int QWSSoundServerProvider::max2
private

Definition at line 511 of file qsoundqss_qws.cpp.

◆ mMuted

bool QWSSoundServerProvider::mMuted
private

Definition at line 513 of file qsoundqss_qws.cpp.

◆ mSid

int QWSSoundServerProvider::mSid
private

Definition at line 502 of file qsoundqss_qws.cpp.

◆ mWid

int QWSSoundServerProvider::mWid
private

Definition at line 501 of file qsoundqss_qws.cpp.

◆ out

int QWSSoundServerProvider::out
private

Definition at line 511 of file qsoundqss_qws.cpp.

◆ priorityExists

int QWSSoundServerProvider::priorityExists = 0
staticprivate

Definition at line 506 of file qsoundqss_qws.cpp.

◆ rightVolume

int QWSSoundServerProvider::rightVolume
private

Definition at line 504 of file qsoundqss_qws.cpp.

◆ sampleRunin

int QWSSoundServerProvider::sampleRunin
private

Definition at line 512 of file qsoundqss_qws.cpp.

◆ samples_due

int QWSSoundServerProvider::samples_due
protected

Definition at line 499 of file qsoundqss_qws.cpp.

◆ samplesPerSec

qint32 QWSSoundServerProvider::samplesPerSec

Definition at line 493 of file qsoundqss_qws.cpp.

◆ wBitsPerSample

qint16 QWSSoundServerProvider::wBitsPerSample

Definition at line 496 of file qsoundqss_qws.cpp.


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