- 论坛徽章:
- 0
|
本帖最后由 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;
} |
|