Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1146350
  • 博文数量: 139
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 1712
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 23:10
个人简介

每天进步一点点。

文章分类

全部博文(139)

文章存档

2015年(3)

2014年(11)

2013年(25)

2011年(1)

2009年(3)

2008年(29)

2007年(45)

2006年(22)

分类: Windows平台

2013-12-28 23:13:23

1.创建一个控制台工程。
2.把libsndfile-1.lib文件拷贝到工程里面。在工程选项里面添加lib文件。



3.拷贝头文件sndfile.h到工程目录,添加到工程。
4.编写如下代码:

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "sndfile.h"

  4. void save(short *b1, int n);
  5. int main(int argc,char *argv[])
  6. {
  7.     SF_INFO sf_info;
  8.     SNDFILE *snd_file;
  9.     SNDFILE *fpOut;
  10.     SF_INFO sf_info_out;
  11.     short *buf1;
  12.     //float *buf1;
  13.     sf_count_t cout;

  14.     sf_info.format = 0;
  15.     snd_file = sf_open(argv[1],SFM_READ,&sf_info);
  16.     

  17.     printf ("Using %s.\n", sf_version_string ()) ;
  18.     printf("File Name : %s\n", argv[1]);
  19.     printf("Sample Rate : %d\n", sf_info.samplerate);
  20.     printf("Channels : %d\n", sf_info.channels);
  21.     printf("Sections : %d\n", sf_info.sections );
  22.     printf("Frames : %d\n", (int)sf_info.frames );

  23.     buf1 = (short *)malloc(sf_info.frames *sizeof(short)*2);
  24.   
  25.     sf_info_out.channels = sf_info.channels;
  26.     sf_info_out.samplerate = sf_info.samplerate;
  27.     sf_info_out.frames = sf_info.frames;
  28.     sf_info_out.format = (SF_FORMAT_WAV|SF_FORMAT_PCM_16|SF_ENDIAN_LITTLE);
  29.     fpOut = sf_open(argv[2],SFM_WRITE,&sf_info_out);
  30.     if(fpOut == NULL)
  31.     {
  32.         printf("open out file failed\n");
  33.         exit(1);
  34.     }

  35.     while( sf_read_short(snd_file, buf1, 480) == 480)
  36.     {
  37.         sf_write_short(fpOut,buf1,480);
  38.     }


  39.     free(buf1);
  40.     sf_close(snd_file);
  41.     sf_close(fpOut);
  42.     return 0;
  43. }


输入一个*.wav文件,写的也是*.wav文件。


编译通过
运行的时候,提示缺少dll文件,把libsndfile-1.dll拷贝到程序运行的目录。生成的wav文件播放起来声音正常。



阅读(3160) | 评论(0) | 转发(0) |
0

上一篇:c/c++相互调用

下一篇:FAAC的参数

给主人留下些什么吧!~~