class OSSRenderer : public SimpleModule {
public:
OSSRenderer() { }
void init();
void process( const Frame &f );
const char *name() { return "OSS Renderer"; }
Format inputFormat() { return "FRAME_ID_PCM_AUDIO_DATA"; }
Format outputFormat() { return "FRAME_ID_RENDERED_AUDIO"; }
bool isBlocking() { return true; }
private:
int fd;
};
void OSSRenderer::init()
{
// Initialize OSS
fd = open( "/dev/dsp", O_WRONLY );
int format = AFMT_S16_LE;
ioctl( fd, SNDCTL_DSP_SETFMT, &format );
int channels = 2;
ioctl( fd, SNDCTL_DSP_CHANNELS, &channels );
int speed = 44100;
ioctl( fd, SNDCTL_DSP_SPEED, &speed );
}
void OSSRenderer::process( const Frame &frame )
{
// Render PCM to device
PCMData *pcm = (PCMData*)frame.data();
if ( write( fd, pcm->data, pcm->size ) == -1 )
perror( "OSSRenderer::process( Frame )" );
frame.deref();
}