#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <errno.h> #define MAX_LEN 1024*500 #define WAV_HEAD_LEN 44 int main(int argc, char *argv[]) { if(3 != argc) { printf("Please input 3 param\n"); return -1; } char input_name[40]; char output_name[40]; int input_fd = -1; int output_fd = -1; int len = -1; char *error_buf = NULL; char *buf = NULL; //------------------------------------------------------------ // 初始化一些东西 buf = (char *)malloc(MAX_LEN); if(NULL == buf) { printf("malloc error\n"); return -1; } input_fd = open(argv[1], O_RDWR); if(input_fd < 0) { printf("open error\n"); return -1; } printf("open [%s] success\n", argv[1]); output_fd = open(argv[2], O_RDWR|O_CREAT); if(output_fd < 0) { printf("open error\n"); return -1; } printf("open [%s] success\n", argv[2]); //----------------------------------------------------------------- //------------------------------------------------------ // 转换wav 为 pcm, 实际上只是跳过wav的头,后面即是pcm数据 lseek(input_fd, WAV_HEAD_LEN, SEEK_SET); while((len = read(input_fd, buf, MAX_LEN)) > 0 ) { write(output_fd, buf, len); } //------------------------------------------------------ printf("wav2pcm complete\n"); close(input_fd); close(output_fd); return 0; } |
|