kwave  18.07.70
Kwave::PlayBackOSS Class Reference

#include <PlayBack-OSS.h>

Inheritance diagram for Kwave::PlayBackOSS:
Inheritance graph
Collaboration diagram for Kwave::PlayBackOSS:
Collaboration graph

Public Member Functions

 PlayBackOSS ()
 
virtual ~PlayBackOSS () Q_DECL_OVERRIDE
 
virtual QString open (const QString &device, double rate, unsigned int channels, unsigned int bits, unsigned int bufbase) Q_DECL_OVERRIDE
 
virtual int write (const Kwave::SampleArray &samples) Q_DECL_OVERRIDE
 
virtual int close () Q_DECL_OVERRIDE
 
virtual QStringList supportedDevices () Q_DECL_OVERRIDE
 
virtual QString fileFilter () Q_DECL_OVERRIDE
 
virtual QList< unsigned int > supportedBits (const QString &device) Q_DECL_OVERRIDE
 
virtual int detectChannels (const QString &device, unsigned int &min, unsigned int &max) Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::PlayBackDevice
virtual ~PlayBackDevice ()
 

Protected Member Functions

void format2mode (int format, int &compression, int &bits, Kwave::SampleFormat::Format &sample_format) const
 
int openDevice (const QString &device)
 
void flush ()
 

Protected Attributes

QString m_device_name
 
int m_handle
 
double m_rate
 
unsigned int m_channels
 
unsigned int m_bits
 
unsigned int m_bufbase
 
Kwave::SampleArray m_buffer
 
QByteArray m_raw_buffer
 
unsigned int m_buffer_size
 
unsigned int m_buffer_used
 
Kwave::SampleEncoderm_encoder
 
int m_oss_version
 

Detailed Description

Definition at line 37 of file PlayBack-OSS.h.

Constructor & Destructor Documentation

◆ PlayBackOSS()

Kwave::PlayBackOSS::PlayBackOSS ( )

Default constructor

Definition at line 87 of file PlayBack-OSS.cpp.

89  m_device_name(),
90  m_handle(-1),
91  m_rate(0),
92  m_channels(0),
93  m_bits(0),
94  m_bufbase(0),
95  m_buffer(),
96  m_raw_buffer(),
97  m_buffer_size(0),
98  m_buffer_used(0),
99  m_encoder(Q_NULLPTR),
100  m_oss_version(-1)
101 {
102 }
unsigned int m_buffer_size
Definition: PlayBack-OSS.h:151
QByteArray m_raw_buffer
Definition: PlayBack-OSS.h:148
unsigned int m_channels
Definition: PlayBack-OSS.h:136
Kwave::SampleArray m_buffer
Definition: PlayBack-OSS.h:145
unsigned int m_bufbase
Definition: PlayBack-OSS.h:142
unsigned int m_bits
Definition: PlayBack-OSS.h:139
unsigned int m_buffer_used
Definition: PlayBack-OSS.h:154
Kwave::SampleEncoder * m_encoder
Definition: PlayBack-OSS.h:157

◆ ~PlayBackOSS()

Kwave::PlayBackOSS::~PlayBackOSS ( )
virtual

Destructor

Definition at line 105 of file PlayBack-OSS.cpp.

References close().

106 {
107  close();
108 }
virtual int close() Q_DECL_OVERRIDE
Here is the call graph for this function:

Member Function Documentation

◆ close()

int Kwave::PlayBackOSS::close ( )
virtual

Closes the output device.

See also
PlayBackDevice::close

Implements Kwave::PlayBackDevice.

Definition at line 310 of file PlayBack-OSS.cpp.

References flush(), m_encoder, and m_handle.

Referenced by detectChannels(), supportedBits(), and ~PlayBackOSS().

311 {
312  flush();
313 
314  // close the device handle
315  if (m_handle) ::close(m_handle);
316 
317  // get rid of the old encoder
318  if (m_encoder) delete m_encoder;
319  m_encoder = Q_NULLPTR;
320 
321  return 0;
322 }
virtual int close() Q_DECL_OVERRIDE
Kwave::SampleEncoder * m_encoder
Definition: PlayBack-OSS.h:157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ detectChannels()

int Kwave::PlayBackOSS::detectChannels ( const QString &  device,
unsigned int &  min,
unsigned int &  max 
)
virtual

Detect the minimum and maximum number of channels. If the detection fails, minimum and maximum are set to zero.

Parameters
devicefilename of the device
minreceives the lowest supported number of channels
maxreceives the highest supported number of channels
Returns
zero or positive number if ok, negative error number if failed

Reimplemented from Kwave::PlayBackDevice.

Definition at line 572 of file PlayBack-OSS.cpp.

References close(), m_handle, MAX_CHANNELS, openDevice(), SNDCTL_DSP_CHANNELS, and Kwave::toInt().

574 {
575  int fd, t, err = -1;
576 
577  min = 0;
578  max = 0;
579 
580  fd = openDevice(device);
581  if (fd < 0) return -1;
582 
583  // find the smalles number of tracks, limit to MAX_CHANNELS
584  for (t=1; t < MAX_CHANNELS; t++) {
585  int real_tracks = t;
586  err = ioctl(fd, SNDCTL_DSP_CHANNELS, &real_tracks);
587  Q_ASSERT(real_tracks == t);
588  if (err >= 0) {
589  min = real_tracks;
590  break;
591  }
592  }
593  if (t >= MAX_CHANNELS) {
594  // no minimum track number found :-o
595  qWarning("no minimum track number found, err=%d", err);
596  // close the device if *we* opened it
597  if ((fd != m_handle) && (fd >= 0)) ::close(fd);
598  return err;
599  }
600 
601  // find the highest number of tracks, start from MAX_CHANNELS downwards
602  for (t = MAX_CHANNELS; t >= Kwave::toInt(min); t--) {
603  int real_tracks = t;
604  err = ioctl(fd, SNDCTL_DSP_CHANNELS, &real_tracks);
605  Q_ASSERT(real_tracks == t);
606  if (err >= 0) {
607  max = real_tracks;
608  break;
609  }
610  }
611  max = t;
612 // qDebug("PlayBackOSS::detectTracks, min=%u, max=%u", min, max);
613 
614  // close the device if *we* opened it
615  if ((fd != m_handle) && (fd >= 0)) ::close(fd);
616  return 0;
617 }
#define MAX_CHANNELS
int toInt(T x)
Definition: Utils.h:127
int openDevice(const QString &device)
virtual int close() Q_DECL_OVERRIDE
#define SNDCTL_DSP_CHANNELS
Here is the call graph for this function:

◆ fileFilter()

QString Kwave::PlayBackOSS::fileFilter ( )
virtual

return a string suitable for a "File Open..." dialog

Reimplemented from Kwave::PlayBackDevice.

Definition at line 396 of file PlayBack-OSS.cpp.

References _.

397 {
398  QString filter;
399 
400  if (filter.length()) filter += _("\n");
401  filter += _("dsp*|") + i18n("OSS playback device (dsp*)");
402 
403  if (filter.length()) filter += _("\n");
404  filter += _("adsp*|") + i18n("ALSA playback device (adsp*)");
405 
406  if (filter.length()) filter += _("\n");
407  filter += _("*|") + i18n("Any device (*)");
408 
409  return filter;
410 }
#define _(m)
Definition: memcpy.c:66

◆ flush()

void Kwave::PlayBackOSS::flush ( )
protected

Writes the output buffer to the device

Definition at line 293 of file PlayBack-OSS.cpp.

References Kwave::SampleEncoder::encode(), m_buffer, m_buffer_used, m_encoder, m_handle, m_raw_buffer, Kwave::SampleEncoder::rawBytesPerSample(), and write().

Referenced by close(), and write().

294 {
295  if (!m_buffer_used || !m_encoder) return; // nothing to do
296 
297  // convert into byte stream
298  unsigned int bytes = m_buffer_used * m_encoder->rawBytesPerSample();
300 
301  ssize_t res = 0;
302  if (m_handle)
303  res = ::write(m_handle, m_raw_buffer.data(), bytes);
304  if (res < 0) perror(__FUNCTION__);
305 
306  m_buffer_used = 0;
307 }
virtual unsigned int rawBytesPerSample()=0
virtual int write(const Kwave::SampleArray &samples) Q_DECL_OVERRIDE
QByteArray m_raw_buffer
Definition: PlayBack-OSS.h:148
Kwave::SampleArray m_buffer
Definition: PlayBack-OSS.h:145
unsigned int m_buffer_used
Definition: PlayBack-OSS.h:154
virtual void encode(const Kwave::SampleArray &samples, unsigned int count, QByteArray &raw_data)=0
Kwave::SampleEncoder * m_encoder
Definition: PlayBack-OSS.h:157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ format2mode()

void Kwave::PlayBackOSS::format2mode ( int  format,
int &  compression,
int &  bits,
Kwave::SampleFormat::Format sample_format 
) const
protected

split a device format bitmask into its parameters. (copied from playback plugin)

Parameters
formatthe device specific format
compressionreceives a compression type
See also
Compression
Parameters
bitsreceives the number of bits per sample, related to the decoded stream
sample_formatreceives the sample format, as defined in libaudiofile (signed or unsigned)

Definition at line 413 of file PlayBack-OSS.cpp.

References AFMT_S24_BE, AFMT_S24_LE, AFMT_S32_BE, AFMT_S32_LE, Kwave::Compression::G711_ALAW, Kwave::Compression::G711_ULAW, m_oss_version, Kwave::Compression::MPEG_LAYER_II, Kwave::Compression::MS_ADPCM, Kwave::Compression::NONE, Kwave::SampleFormat::Signed, Kwave::SampleFormat::Unknown, and Kwave::SampleFormat::Unsigned.

Referenced by supportedBits().

415 {
416  switch (format) {
417  case AFMT_MU_LAW:
418  compression = Kwave::Compression::G711_ULAW;
419  sample_format = Kwave::SampleFormat::Signed;
420  bits = 16;
421  break;
422  case AFMT_A_LAW:
423  compression = Kwave::Compression::G711_ALAW;
424  sample_format = Kwave::SampleFormat::Unsigned;
425  bits = 16;
426  break;
427  case AFMT_IMA_ADPCM:
428  compression = Kwave::Compression::MS_ADPCM;
429  sample_format = Kwave::SampleFormat::Signed;
430  bits = 16;
431  break;
432  case AFMT_U8:
433  compression = Kwave::Compression::NONE;
434  sample_format = Kwave::SampleFormat::Unsigned;
435  bits = 8;
436  break;
437  case AFMT_S16_LE:
438  case AFMT_S16_BE:
439  compression = Kwave::Compression::NONE;
440  sample_format = Kwave::SampleFormat::Signed;
441  bits = 16;
442  break;
443  case AFMT_S8:
444  compression = Kwave::Compression::NONE;
445  sample_format = Kwave::SampleFormat::Signed;
446  bits = 8;
447  break;
448  case AFMT_U16_LE:
449  case AFMT_U16_BE:
450  compression = Kwave::Compression::NONE;
451  sample_format = Kwave::SampleFormat::Unsigned;
452  bits = 16;
453  break;
454  case AFMT_MPEG:
455  compression = static_cast<int>(
457  sample_format = Kwave::SampleFormat::Signed;
458  bits = 16;
459  break;
460 #if 0
461  case AFMT_AC3: /* Dolby Digital AC3 */
462  compression = Kwave::SampleFormat::Unknown;
463  sample_format = 0;
464  bits = 16;
465  break;
466 #endif
467  case AFMT_S24_LE:
468  case AFMT_S24_BE:
469  if (m_oss_version >= 0x040000) {
470  compression = Kwave::Compression::NONE;
471  sample_format = Kwave::SampleFormat::Signed;
472  bits = 24;
473  break;
474  } /* FALLTHROUGH */
475  case AFMT_S32_LE:
476  case AFMT_S32_BE:
477  if (m_oss_version >= 0x040000) {
478  compression = Kwave::Compression::NONE;
479  sample_format = Kwave::SampleFormat::Signed;
480  bits = 32;
481  break;
482  } /* FALLTHROUGH */
483  default:
484  compression = -1;
485  sample_format = Kwave::SampleFormat::Unknown;
486  bits = -1;
487  }
488 
489 }
#define AFMT_S32_LE
#define AFMT_S24_LE
#define AFMT_S32_BE
#define AFMT_S24_BE
Here is the caller graph for this function:

◆ open()

QString Kwave::PlayBackOSS::open ( const QString &  device,
double  rate,
unsigned int  channels,
unsigned int  bits,
unsigned int  bufbase 
)
virtual

Opens the device for playback.

See also
PlayBackDevice::open

Implements Kwave::PlayBackDevice.

Definition at line 111 of file PlayBack-OSS.cpp.

References _, AFMT_S24_LE, AFMT_S32_LE, DBG, Kwave::LittleEndian, m_bits, m_bufbase, m_buffer, m_buffer_size, m_buffer_used, m_channels, m_device_name, m_encoder, m_handle, m_oss_version, m_rate, m_raw_buffer, MAX_PLAYBACK_BUFFER, MIN_PLAYBACK_BUFFER, Kwave::SampleEncoder::rawBytesPerSample(), Kwave::SampleArray::resize(), Kwave::SampleFormat::Signed, SNDCTL_DSP_CHANNELS, SNDCTL_DSP_SETFMT, SNDCTL_DSP_SPEED, Kwave::toInt(), and Kwave::SampleFormat::Unsigned.

Referenced by openDevice().

114 {
115  qDebug("PlayBackOSS::open(device=%s,rate=%0.1f,channels=%u,"
116  "bits=%u, bufbase=%u)", DBG(device.split(_("|")).at(0)),
117  rate, channels, bits, bufbase);
118 
119  m_device_name = device;
120  m_rate = rate;
121  m_channels = channels;
122  m_bits = bits;
123  m_bufbase = bufbase;
124  m_buffer_size = 0;
125  m_buffer_used = 0;
126  m_handle = 0;
127 
128  // prepeare for playback by opening the sound device
129  // and initializing with the proper settings
130  m_handle = ::open(m_device_name.toLocal8Bit(), O_WRONLY | O_NONBLOCK);
131  if (m_handle == -1) {
132  QString reason;
133  switch (errno) {
134  case ENOENT:
135  case ENODEV:
136  case ENXIO:
137  case EIO:
138  reason = i18n("I/O error. Maybe the driver\n"\
139  "is not present in your kernel or it is not\n"\
140  "properly configured.");
141  break;
142  case EBUSY:
143  reason = i18n(
144  "The device is busy. Maybe some other application is\n"\
145  "currently using it. Please try again later.\n"\
146  "(Hint: you might find out the name and process ID of\n"\
147  "the program by calling: \"fuser -v %1\"\n"\
148  "on the command line.)",
149  m_device_name.section(QLatin1Char('|'), 0, 0));
150  break;
151  default:
152  reason = QString::fromLocal8Bit(strerror(errno));
153  }
154  return reason;
155  }
156 
157  // the device was opened in non-blocking mode to detect if it is
158  // busy or not - but from now on we need blocking mode again
159  ::fcntl(m_handle, F_SETFL, fcntl(m_handle, F_GETFL) & ~O_NONBLOCK);
160  if (fcntl(m_handle, F_GETFL) & O_NONBLOCK) {
161  // resetting O:NONBLOCK failed
162  return i18n("The device '%1' cannot be opened "\
163  "in the correct mode.",
164  m_device_name.section(QLatin1Char('|'), 0, 0));
165  }
166 
167  // query OSS driver version
168  m_oss_version = 0x030000;
169 #ifdef OSS_GETVERSION
170  ioctl(m_handle, OSS_GETVERSION, &m_oss_version);
171 #endif
172 
173  int format;
174  switch (m_bits) {
175  case 8: format = AFMT_U8; break;
176  case 24: format = AFMT_S24_LE; break;
177  case 32: format = AFMT_S32_LE; break;
178  default: format = AFMT_S16_LE;
179  }
180 
181  // number of bits per sample
182  int oldformat = format;
183  if ((ioctl(m_handle, SNDCTL_DSP_SETFMT, &format) == -1) ||
184  (format != oldformat)) {
185  return i18n("%1 bits per sample are not supported", m_bits);
186  }
187 
188  // channels selection
189  if ((ioctl(m_handle, SNDCTL_DSP_CHANNELS, &m_channels) == -1) ||
190  (format != oldformat)) {
191  return i18n("%1 channels playback is not supported", m_channels);
192  }
193 
194  // playback rate, we allow up to 10% variation
195  int int_rate = Kwave::toInt(m_rate);
196  if ((ioctl(m_handle, SNDCTL_DSP_SPEED, &int_rate) == -1) ||
197  (int_rate < 0.9 * m_rate) || (int_rate > 1.1 * m_rate)) {
198  return i18n("Playback rate %1 Hz is not supported", int_rate);
199  }
200  m_rate = int_rate;
201 
202  // buffer size
203  Q_ASSERT(bufbase >= MIN_PLAYBACK_BUFFER);
204  Q_ASSERT(bufbase <= MAX_PLAYBACK_BUFFER);
205  if (bufbase < MIN_PLAYBACK_BUFFER) bufbase = MIN_PLAYBACK_BUFFER;
206  if (bufbase > MAX_PLAYBACK_BUFFER) bufbase = MAX_PLAYBACK_BUFFER;
207  if (ioctl(m_handle, SNDCTL_DSP_SETFRAGMENT, &bufbase) == -1) {
208  return i18n("Unusable buffer size: %1", 1 << bufbase);
209  }
210 
211  // get the real buffer size in bytes
212  ioctl(m_handle, SNDCTL_DSP_GETBLKSIZE, &m_buffer_size);
213 
214  // create the sample encoder
215  // we assume that OSS is always little endian
216  if (m_encoder) delete m_encoder;
217 
218  switch (m_bits) {
219  case 8:
222  break;
223  case 24:
224  if (m_oss_version >= 0x040000) {
227  break;
228  } // else:
229  /* FALLTHROUGH */
230  case 32:
231  if (m_oss_version >= 0x040000) {
234  break;
235  }
236  // else:
237  /* FALLTHROUGH */
238  default:
241  break;
242  }
243 
244  Q_ASSERT(m_encoder);
245  if (!m_encoder) return i18n("Out of memory");
246 
247  // resize the raw buffer
248  m_raw_buffer.resize(m_buffer_size);
249 
250  // resize our buffer (size in samples) and reset it
253  return i18n("Out of memory");
254 
255  return QString();
256 }
virtual unsigned int rawBytesPerSample()=0
#define SNDCTL_DSP_SPEED
#define SNDCTL_DSP_SETFMT
unsigned int m_buffer_size
Definition: PlayBack-OSS.h:151
QByteArray m_raw_buffer
Definition: PlayBack-OSS.h:148
unsigned int m_channels
Definition: PlayBack-OSS.h:136
#define MIN_PLAYBACK_BUFFER
#define AFMT_S32_LE
Kwave::SampleArray m_buffer
Definition: PlayBack-OSS.h:145
unsigned int m_bufbase
Definition: PlayBack-OSS.h:142
#define AFMT_S24_LE
int toInt(T x)
Definition: Utils.h:127
unsigned int m_bits
Definition: PlayBack-OSS.h:139
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
#define MAX_PLAYBACK_BUFFER
unsigned int m_buffer_used
Definition: PlayBack-OSS.h:154
bool resize(unsigned int size) Q_REQUIRED_RESULT
Kwave::SampleEncoder * m_encoder
Definition: PlayBack-OSS.h:157
#define SNDCTL_DSP_CHANNELS
virtual QString open(const QString &device, double rate, unsigned int channels, unsigned int bits, unsigned int bufbase) Q_DECL_OVERRIDE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ openDevice()

int Kwave::PlayBackOSS::openDevice ( const QString &  device)
protected

Opens a physical device and returns its file descriptor

Parameters
devicefilename of the device
Returns
file descriptor >= 0 or negative value on errors

Definition at line 492 of file PlayBack-OSS.cpp.

References DBG, m_handle, m_oss_version, and open().

Referenced by detectChannels(), and supportedBits().

493 {
494  int fd = m_handle;
495 
496 // qDebug("PlayBackOSS::openDevice(%s)", device.local8Bit().data());
497  if (!device.length()) return -1;
498 
499  if (fd <= 0) {
500  // open the device in case it's not already open
501  fd = ::open(device.toLocal8Bit(), O_WRONLY | O_NONBLOCK);
502  if (fd <= 0) {
503  qWarning("PlayBackOSS::openDevice('%s') - failed, errno=%d (%s)",
504  DBG(device),
505  errno, strerror(errno));
506  } else {
507  // we use blocking mode
508  ::fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
509  // query OSS driver version
510  m_oss_version = -1;
511 #ifdef OSS_GETVERSION
512  ioctl(fd, OSS_GETVERSION, &m_oss_version);
513 #endif
514  }
515  }
516  if (fd <= 0) {
517  qWarning("PlayBackOSS::openDevice('%s') - failed, errno=%d (%s)",
518  DBG(device), errno, strerror(errno));
519  }
520 
521  return fd;
522 }
#define DBG(qs)
Definition: String.h:55
virtual QString open(const QString &device, double rate, unsigned int channels, unsigned int bits, unsigned int bufbase) Q_DECL_OVERRIDE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ supportedBits()

QList< unsigned int > Kwave::PlayBackOSS::supportedBits ( const QString &  device)
virtual

returns a list of supported bits per sample resolutions of a given device.

Parameters
devicefilename of the device
Returns
list of supported bits per sample, or empty on errors

Implements Kwave::PlayBackDevice.

Definition at line 525 of file PlayBack-OSS.cpp.

References close(), format2mode(), m_handle, Kwave::Compression::NONE, and openDevice().

526 {
527  QList<unsigned int> bits;
528  bits.clear();
529  int err = -1;
530  int mask = AFMT_QUERY;
531  int fd;
532 
533 // qDebug("PlayBackOSS::supportedBits(%s)", device.local8Bit().data());
534 
535  fd = openDevice(device);
536  if (fd >= 0) {
537  err = ::ioctl(fd, SNDCTL_DSP_GETFMTS, &mask);
538  if (err < 0) {
539  qWarning("PlayBackOSS::supportedBits() - "\
540  "SNDCTL_DSP_GETFMTS failed, "\
541  "fd=%d, result=%d, error=%d (%s)",
542  fd, err, errno, strerror(errno));
543  }
544  }
545 
546  // close the device if *we* opened it
547  if ((fd != m_handle) && (fd >= 0)) ::close(fd);
548 
549  if (err < 0) return bits;
550 
551  // mask out all modes that do not match the current compression
552  const int compression = Kwave::Compression::NONE;
553  for (unsigned int bit=0; bit < (sizeof(mask) << 3); bit++) {
554  if (!(mask & (1 << bit))) continue;
555 
556  // format is supported, split into compression, bits, sample format
557  int c, b;
559  format2mode(1 << bit, c, b, s);
560  if (b < 0) continue; // unknown -> skip
561 
562  // take the mode if compression matches and it is not already known
563  if ((c == compression) && !(bits.contains(b))) {
564  bits += b;
565  }
566  }
567 
568  return bits;
569 }
int openDevice(const QString &device)
virtual int close() Q_DECL_OVERRIDE
void format2mode(int format, int &compression, int &bits, Kwave::SampleFormat::Format &sample_format) const
Here is the call graph for this function:

◆ supportedDevices()

QStringList Kwave::PlayBackOSS::supportedDevices ( )
virtual

return a string list with supported device names

Reimplemented from Kwave::PlayBackDevice.

Definition at line 379 of file PlayBack-OSS.cpp.

References _, scanDirectory(), and scanFiles().

380 {
381  QStringList list, dirlist;
382 
383  scanDirectory(list, _("/dev"));
384  scanDirectory(list, _("/dev/snd"));
385  scanDirectory(list, _("/dev/sound"));
386  scanFiles(dirlist, _("/dev/oss"), _("[^.]*"));
387  foreach (QString dir, dirlist)
388  scanDirectory(list, dir);
389  list.append(_("#EDIT#"));
390  list.append(_("#SELECT#"));
391 
392  return list;
393 }
static void scanFiles(QStringList &list, const QString &dirname, const QString &mask)
static void scanDirectory(QStringList &list, const QString &dir)
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:

◆ write()

int Kwave::PlayBackOSS::write ( const Kwave::SampleArray samples)
virtual

Writes an array of samples to the output device.

See also
PlayBackDevice::write

Implements Kwave::PlayBackDevice.

Definition at line 259 of file PlayBack-OSS.cpp.

References flush(), m_buffer, m_buffer_size, m_buffer_used, MEMCPY, and Kwave::SampleArray::size().

Referenced by flush().

260 {
261  Q_ASSERT (m_buffer_used <= m_buffer_size);
263  qWarning("PlayBackOSS::write(): buffer overflow ?!");
265  flush();
266  return -EIO;
267  }
268 
269  // number of samples left in the buffer
270  unsigned int remaining = samples.size();
271  unsigned int offset = 0;
272  while (remaining) {
273  unsigned int length = remaining;
274  if (m_buffer_used + length > m_buffer_size)
275  length = m_buffer_size - m_buffer_used;
276 
277  MEMCPY(&(m_buffer[m_buffer_used]),
278  &(samples[offset]),
279  length * sizeof(sample_t));
280  m_buffer_used += length;
281  offset += length;
282  remaining -= length;
283 
284  // write buffer to device if it has become full
285  if (m_buffer_used >= m_buffer_size)
286  flush();
287  }
288 
289  return 0;
290 }
unsigned int m_buffer_size
Definition: PlayBack-OSS.h:151
Kwave::SampleArray m_buffer
Definition: PlayBack-OSS.h:145
#define MEMCPY
Definition: memcpy.h:37
unsigned int size() const
unsigned int m_buffer_used
Definition: PlayBack-OSS.h:154
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bits

unsigned int Kwave::PlayBackOSS::m_bits
protected

Resolution in bits per sample

Definition at line 139 of file PlayBack-OSS.h.

Referenced by open().

◆ m_bufbase

unsigned int Kwave::PlayBackOSS::m_bufbase
protected

Exponent of the buffer size

Definition at line 142 of file PlayBack-OSS.h.

Referenced by open().

◆ m_buffer

Kwave::SampleArray Kwave::PlayBackOSS::m_buffer
protected

buffer with samples data

Definition at line 145 of file PlayBack-OSS.h.

Referenced by flush(), open(), and write().

◆ m_buffer_size

unsigned int Kwave::PlayBackOSS::m_buffer_size
protected

Buffer size on bytes

Definition at line 151 of file PlayBack-OSS.h.

Referenced by open(), and write().

◆ m_buffer_used

unsigned int Kwave::PlayBackOSS::m_buffer_used
protected

number of bytes in the buffer

Definition at line 154 of file PlayBack-OSS.h.

Referenced by flush(), open(), and write().

◆ m_channels

unsigned int Kwave::PlayBackOSS::m_channels
protected

Number of channels

Definition at line 136 of file PlayBack-OSS.h.

Referenced by open().

◆ m_device_name

QString Kwave::PlayBackOSS::m_device_name
protected

Name of the output device

Definition at line 127 of file PlayBack-OSS.h.

Referenced by open().

◆ m_encoder

Kwave::SampleEncoder* Kwave::PlayBackOSS::m_encoder
protected

encoder for converting from samples to raw format

Definition at line 157 of file PlayBack-OSS.h.

Referenced by close(), flush(), and open().

◆ m_handle

int Kwave::PlayBackOSS::m_handle
protected

Handle of the output device

Definition at line 130 of file PlayBack-OSS.h.

Referenced by close(), detectChannels(), flush(), open(), openDevice(), and supportedBits().

◆ m_oss_version

int Kwave::PlayBackOSS::m_oss_version
protected

OSS driver version

Definition at line 160 of file PlayBack-OSS.h.

Referenced by format2mode(), open(), and openDevice().

◆ m_rate

double Kwave::PlayBackOSS::m_rate
protected

Playback rate [samples/second]

Definition at line 133 of file PlayBack-OSS.h.

Referenced by open().

◆ m_raw_buffer

QByteArray Kwave::PlayBackOSS::m_raw_buffer
protected

buffer with raw data

Definition at line 148 of file PlayBack-OSS.h.

Referenced by flush(), and open().


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