| coolbuddyguy@gmail.com 2006-10-31, 7:23 am |
| hi all...this is a code i wrote for sound recording....but i am not
getting how to save the recorded sound in file....give some inputs to
this....
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#include <sys/stat.h>
#define LENGTH 5
#define RATE 8000
#define SIZE 8
#define CHANNELS 1
unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];
int main()
{
int fd; /* sound device file descriptor */
int arg;
int status;
int fd1;
char *path;
fd = open("/dev/dsp", O_RDWR);
if (fd < 0) {
perror("open of /dev/dsp failed");
exit(1);
}
path="/root/d/progs/xyz";
if((fd1=open(path, O_WRONLY))<0)
if (fd1<0) {
if ((fd1=creat(path,S_IXUSR))<0)
perror("create error");
} else
perror("open error");
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_WRITE ioctl failed");
while (1) {
printf("Say something: in ur microfone :::: \n");
status = read(fd, buf, sizeof(buf));
if (status != sizeof(buf))
perror("read wrong number of bytes");
printf("You said: if u want to stop then press \"ctrl+c\"....Made
by Anuj\n");
status = write(fd1, 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");
}
}
|