snd_pcm_format_t inFormat;
snd_pcm_format_t outFormat;
public:
ALSAExternalPluginTest(){
std::cout<<__func__<<std::endl;
setName("ALSAExternalPluginTest");
}
virtual ~ALSAExternalPluginTest(){
std::cout<<__func__<<std::endl;
}
virtual int parseConfig(const char *name, snd_config_t *conf, snd_pcm_stream_t stream, int mode){
if (stream != SND_PCM_STREAM_PLAYBACK) {
ostringstream oss;
oss<<name<<" : is only for playback.";
SNDERR(oss.str().c_str());
return -EINVAL;
}
return ALSAExternalPlugin::parseConfig(name, conf, stream, mode);
}
virtual int hwParams(snd_pcm_hw_params_t *params){
std::cout<<__func__<<std::endl;
copyFrom(params);
cout<<"extplug.rate "<<extplug.rate<<endl;
cout<<"extplug.channels "<<extplug.channels<<endl;
cout<<"extplug.slave_channels "<<extplug.slave_channels<<endl;
return 0;
}
virtual int specifyHWParams(){
int ret;
if ((ret=snd_pcm_extplug_set_param_minmax(&extplug, SND_PCM_EXTPLUG_HW_CHANNELS, 2, 2))!=0)
if ((ret=snd_pcm_extplug_set_slave_param(&extplug, SND_PCM_EXTPLUG_HW_CHANNELS, 2))!=0)
inFormat=SND_PCM_FORMAT_FLOAT_LE;
outFormat=SND_PCM_FORMAT_FLOAT_LE;
if ((ret=snd_pcm_extplug_set_param(&extplug, SND_PCM_EXTPLUG_HW_FORMAT, inFormat))!=0)
if ((ret=snd_pcm_extplug_set_slave_param(&extplug, SND_PCM_EXTPLUG_HW_FORMAT, outFormat))!=0)
return 0;
}
virtual int init(){
cout<<__func__<<endl;
cout<<"period size "<<getPeriodSize()<<endl;
if (getPeriodSize()==0){
cout<<"can't have 0 period size, exiting"<<endl;
return -1;
}
cout<<"extplug.rate "<<extplug.rate<<endl;
cout<<"extplug.channels "<<extplug.channels<<endl;
cout<<"extplug.slave_channels "<<extplug.slave_channels<<endl;
return 0;
}
virtual snd_pcm_sframes_t transfer(
const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset, snd_pcm_uframes_t
size){
int ch=2;
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> stride(1,ch);
float *srcAddr=(float*)getAddress(src_areas, src_offset);
float *dstAddr=(float*)getAddress(dst_areas, dst_offset);
Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>, Eigen::Unaligned, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> >
in(srcAddr, size, ch, stride);
Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>, Eigen::Unaligned, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> >
out(dstAddr, size, ch, stride);
out=in;
}
};
ALSAExternalPluginTest aEPlugin;
extern "C" SND_PCM_PLUGIN_DEFINE_FUNC(ALSAExternalPluginTest){
std::cout<<__func__<<std::endl;
aEPlugin.parseConfig(name, conf, stream, mode);
int ret=aEPlugin.create(name, root, stream, mode);
if (ret<0)
return ret;
aEPlugin.specifyHWParams();
*pcmp=aEPlugin.getPCM();
std::cout<<__func__<<" returning "<<std::endl;
return 0;
}
SND_PCM_PLUGIN_SYMBOL(ALSAExternalPluginTest);