Nsound  0.9.4
Functions
AudioBackendLibportaudio.cc File Reference
#include <Nsound/Nsound.h>
#include <Nsound/AudioBackendLibportaudio.h>
#include <Nsound/AudioPlayback.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
Include dependency graph for AudioBackendLibportaudio.cc:

Go to the source code of this file.

Functions

PaError write_stream (PaStream *stream, void *data, uint32 position, uint32 n_frames_per_buffer, PaSampleFormat format)
 
static std::string lower (const std::string &x)
 
static int32 integer (const std::string &x, Nsound::AudioBackend::State *state)
 

Function Documentation

PaError write_stream ( PaStream stream,
void *  data,
uint32  position,
uint32  n_frames_per_buffer,
PaSampleFormat  format 
)

Definition at line 342 of file AudioBackendLibportaudio.cc.

References M_THROW.

Referenced by Nsound::AudioBackendLibportaudio::play().

348 {
349  switch(format)
350  {
351  case paInt8:
352  {
353  int8 * data_ptr = reinterpret_cast<int8 *>(data);
354  return Pa_WriteStream(
355  stream,
356  reinterpret_cast<void *>(data_ptr + position),
357  n_frames_per_buffer);
358  }
359 
360  case paInt16:
361  {
362  int16 * data_ptr = reinterpret_cast<int16 *>(data);
363  return Pa_WriteStream(
364  stream,
365  reinterpret_cast<void *>(data_ptr + position),
366  n_frames_per_buffer);
367  }
368 
369  case paInt32:
370  {
371  int32 * data_ptr = reinterpret_cast<int32 *>(data);
372  return Pa_WriteStream(
373  stream,
374  reinterpret_cast<void *>(data_ptr + position),
375  n_frames_per_buffer);
376  }
377  }
378 
379  M_THROW("Nsound::AudioBackendLibportaudio::initialize():"
380  << ": can't handle bits per sample type: "
381  << format
382  << "\n");
383 
384  return paSampleFormatNotSupported;
385 }
signed char int8
Definition: Nsound.h:140
signed short int16
Definition: Nsound.h:141
#define M_THROW(message)
Definition: Macros.h:108
signed int int32
Definition: Nsound.h:142
static std::string lower ( const std::string &  x)
static

Definition at line 597 of file AudioBackendLibportaudio.cc.

Referenced by Nsound::AudioBackendLibportaudio::scanDevices(), and Nsound::AudioBackendLibportaudio::setOption().

598 {
599  std::string y = x;
600  std::transform(y.begin(), y.end(), y.begin(), ::tolower);
601  return y;
602 }
static int32 integer ( const std::string &  x,
Nsound::AudioBackend::State state 
)
static

Definition at line 652 of file AudioBackendLibportaudio.cc.

References Nsound::AudioBackend::BACKEND_ERROR, and M_THROW.

Referenced by Nsound::AudioBackendLibportaudio::setOption().

653 {
654  std::stringstream ss(x);
655  int32 i = 0;
656 
657  ss >> i;
658 
659  if(ss.fail())
660  {
661  *state = AudioBackend::BACKEND_ERROR;
662  M_THROW("Nsound::AudioBackendLibportaudio::setOption():"
663  << ": could not convert '"
664  << x
665  << "' to an integer.\n");
666  return -1;
667  }
668 
669  return i;
670 }
#define M_THROW(message)
Definition: Macros.h:108
signed int int32
Definition: Nsound.h:142