LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   kernel audio programming (https://www.linuxquestions.org/questions/programming-9/kernel-audio-programming-78871/)

ksnash 08-04-2003 10:19 AM

kernel audio programming
 
I am trying to do signal generation in kernel module, but can't seem to access /dev/dsp properly for output. Using syscalls, plain, and filp calls. I always seem to get a 0 for block size.

MSG("init_wg \n");

larynx_dev->filep=filp_open("/dev/audio",O_RDWR,0);

if(IS_ERR(larynx_dev->filep))
{
const int err=-PTR_ERR(larynx_dev->filep);
MSG("%s: error opening file. errno = %d\n",__FUNCTION__,err);
larynx_dev->filep=0;
return;
}

larynx_dev->inodep=larynx_dev->filep->f_dentry->d_inode;
if(larynx_dev->inodep==0||larynx_dev->inodep==NULL)
{
MSG("inodep bad\n");
filp_close(larynx_dev->filep,0);
return;
}

// if((larynx_dev->audio_fd=open("/dev/dsp",O_RDWR,0))<=0)
// {
// MSG("Audio fd not set!\n");
// return;
// }

mm_segment_t oldfs;
int handle;
ioctlp=larynx_dev->filep->f_op->ioctl;

if(ioctlp==0||ioctlp==NULL)
{
MSG("ioctlp invalid!\n");
filp_close(larynx_dev->filep,0);
return;
}

MSG("1\n");
int t=0x00020007;

oldfs=get_fs();
set_fs(get_ds());

handle=ioctlp(larynx_dev->inodep,larynx_dev->filep, SNDCTL_DSP_SETFRAGMENT,t);

set_fs(oldfs);

if(handle==-1)
{
filp_close(larynx_dev->filep,0);
MSG("couldn't set fragment size\n");
}

MSG("2\n");
t=AFMT_U16_LE;
set_fs(get_ds());

handle= ioctlp(larynx_dev->inodep,larynx_dev->filep,SNDCTL_DSP_SETFMT,t);

set_fs(oldfs);
if(handle==-1)
{
filp_close(larynx_dev->filep,0);
MSG("couldn't go to 16-bit unsigned little-endian mode\n");
}

MSG("3\n");
t=1;
set_fs(get_ds());
handle = ioctlp(larynx_dev->inodep,larynx_dev->filep,SNDCTL_DSP_STEREO,t);
set_fs(oldfs);
if(handle==-1)
{
filp_close(larynx_dev->filep,0);
MSG("couldn't set number of channels to 1\n");
}

MSG("4\n");
set_fs(get_ds());
handle=ioctlp(larynx_dev->inodep,larynx_dev->filep, SNDCTL_DSP_SPEED,larynx_dev->sample_rate);
set_fs(oldfs);
if(handle==-1)
{
filp_close(larynx_dev->filep,0);
MSG("couldn't set sampling speed\n");
}

int bs=0;

set_fs(get_ds());
handle= ioctlp(larynx_dev->inodep,larynx_dev->filep, SNDCTL_DSP_GETBLKSIZE,bs);
set_fs(oldfs);
if(handle==-1)
{
filp_close(larynx_dev->filep,0);
MSG("couldn't get blocksize\n");
}
MSG("handle=%d\n",handle);
MSG("bs=%d\n",bs);

bs/=2;
if(bs==larynx_dev->block_size)
{
if(larynx_dev->block_size!=0)
kfree(larynx_dev->block);
larynx_dev->block_size=bs;
larynx_dev->block=kmalloc(sizeof(Sample)*larynx_dev->block_size, GFP_KERNEL);
}


All times are GMT -5. The time now is 09:13 PM.