LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2003, 10:19 AM   #1
ksnash
Member
 
Registered: Jul 2003
Location: Pensacola,Florida
Distribution: Mandrake 9.1
Posts: 41

Rep: Reputation: 15
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);
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
about kernel programming wangjinyi Programming 1 09-26-2005 09:23 AM
kernel programming help Pratik H Pandya Red Hat 4 09-02-2005 11:54 PM
Kernel Programming. dreamz_jaleel Programming 7 04-15-2005 11:38 AM
Question Abt Audio Programming sibtay Programming 1 10-11-2004 12:56 PM
OSS Audio Programming jinksys Programming 0 10-11-2003 03:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration