免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1490 | 回复: 0
打印 上一主题 下一主题

Unable to handle kernel NULL pointer_音频小程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-10 11:46 |只看该作者 |倒序浏览
本帖最后由 keneth2078 于 2010-07-10 11:47 编辑

一个在嵌入式下的音频学习程序,抄ibm网站《音频编程指南》的,不能运行。
错误为:
/tmp # ./a.out
Say something:
buffer size is:80000
fd value is:3
Unable to handle kernel NULL pointer dereference at virtual address 00000088
pgd = c0004000
*pgd = 00000000, *pmd = 00000000
Internal error: Oops: 0
CPU: 0
pc : [<c013a5b8>]    lr : [<c00210d8>]    Not tainted
sp : c0215f1c  ip : c0215f38  fp : c0215f60
r10: c0234520  r9 : c0215f64  r8 : c022b6f8
r7 : c022cb18  r6 : c02551f0  r5 : 000000a1  r4 : c11bf880
r3 : 00000000  r2 : ffffffff  r1 : 00000000  r0 : 000000a1
Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  Segment kernel
Control: 317F  Table: 010EC000  DAC: 0000001D
Process swapper (pid: 0, stack limit = 0xc0214374)

问题出现在循环体内的read语句,怎么改才能正确运行啊? ??
求达人指点~

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>

#define LENGTH 10
#define RATE 8000
#define SIZE 8
#define CHANNELS 1



static unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8] = {0};

int main()
{
   int fd;
   int arg;
   int status;
   
   fd = open("/dev/dsp",O_RDWR);
    if (fd < 0)
    {
        perror ("open /dev/dsp");
        exit(1);
    }

     arg = SIZE;
    status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
    if (status  == -1)
        perror("SOUND_PCM_WRITE_BITS ioctl failed");
    if (arg != SIZE)
        perror("unable to set sample size");
   
   
    arg = CHANNELS;
    status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
    if (status == -1)
    {
        perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
    }
   
    if (arg != CHANNELS)
    {
        perror("unable to set number of channels");
    }


    arg = RATE;
    status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
    if (status  == -1)
    {
        perror("SOUND_PCM_WRITE_RATE ioctl failed");
    }

   while (1)
   {
       printf("Say something:\n");
       printf("buffer size is:%d\n", sizeof(buf));
       printf("fd value is:%d\n",fd);
      
        read((int)fd, buf, sizeof(buf));
      
       printf("status value is:%d\n",status);
       if (status != sizeof(buf));
       perror("Read wrong number of bytes");
       printf("You said:\n");
       status = write(fd, buf, sizeof(buf));
       if (status !=sizeof(buf))
           perror("wrote wrong number of bytes");
       status = ioctl(fd, SOUND_PCM_SYNC, 0);
       if (status == -1)
           perror("SOUND_PCM_SYNC ioctl failed");
   }

    return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP