40 void open(
const char *devName=
"default"){
41 int ret=
Stream::init(devName, SND_PCM_STREAM_PLAYBACK,
block ? 0 : SND_PCM_NONBLOCK);
43 std::cerr<<
"Playback :: Playback : open error: "<< snd_strerror(ret)<<std::endl;
54 int writeBuf(
void **buffers,
size_t len,
int ch){
56 std::cout<<
"ch = "<<ch<<
"\n";
57 if (buffer.size()!=ch)
59 for (
int i=0;i<ch;i++)
62 while ((len-=ret) > 0) {
64 ret = snd_pcm_writen(
getPCM(), &buffer[0], len);
65 std::cout<<
"ret "<<ret<<std::endl;
66 if (ret == -EAGAIN || (ret>=0 && ret<len))
68 if (ret<0 && ret!=-EAGAIN){
69 printf(
"Write error: %s\n", snd_strerror(ret));
72 std::cout<<
"ch = "<<ch<<
"\n";
73 for (
int i=0;i<ch;i++){
74 char *c=(
char*)buffer[i];
86 template <
typename Derived>
87 int writeBufN(
const Eigen::DenseBase<Derived> &audioData){
88 std::cout<<
"non interleaved"<<std::endl;
89 if (buffer.size()!=audioData.cols())
90 buffer.resize(audioData.cols());
91 for (
int i=0;i<audioData.cols();i++)
92 buffer[i]=(
void*)audioData.col(i).data();
93 return writeBuf(&buffer[0], audioData.rows(), audioData.cols());
106 int ret=snd_pcm_writei(
getPCM(), (
void *)bufferIn, len);
113 while ((len-=ret) > 0) {
114 if ((ret>=0 && ret<len) &&
block!=0)
121 bufferIn += ret*bytes_per_frame;
123 ret = snd_pcm_writei(
getPCM(), (
void *)bufferIn, len);
134 template <
typename Derived>
135 int writeBuf(
const Eigen::DenseBase<Derived> &audioData){
136 return writeBuf((
char*)&audioData(0,0), audioData.rows());
143 template <
typename Derived>
144 Playback& operator<<(const Eigen::DenseBase<Derived> &audioData){
145 int ret=
writeBuf((
char*)&audioData(0,0), audioData.rows());
int writeBufN(const Eigen::DenseBase< Derived > &audioData)
std::vector< void * > buffer
Non interleaved buffer pointers.
#define PCM_NOT_OPEN_CHECK_NO_PRINT(pcm, type)
virtual snd_pcm_t * getPCM()
int init(const char *device, snd_pcm_stream_t streamType, bool blockIn)
virtual int evaluateError(int errorNum)
void open(const char *devName="default")
#define PCM_NOT_OPEN_CHECK(pcm)
int writeBuf(const Eigen::DenseBase< Derived > &audioData)
int getFormatPhysicalWidth()
int wait(int timeOut=1000)
int writeBuf(char *bufferIn, size_t len)
Playback(const char *devName)
int writeBuf(void **buffers, size_t len, int ch)