资源简介
此文件为c++代码,使用Speex对音频进行重采样,demo中做了48kHz到44.1kHz的转换。
代码片段和文件信息
// Speex_Resample.cpp : 此文件包含 “main“ 函数。程序执行将在此处开始并结束。
//
#include
/* Copyright (C) 2007 Jean-Marc Valin
File: testresample.c
Testing the resampling code
Redistribution and use in source and binary forms with or without
modification are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ‘‘AS IS‘‘ AND ANY EXPRESS OR
IMPLIED WARRANTIES INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT
INDIRECT INCIDENTAL SPECIAL EXEMPLARY OR CONSEQUENTIAL DAMAGES
(INCLUDING BUT NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE DATA OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT
STRICT LIABILITY OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include “config.h“
#endif
#include “speex/speex_resampler.h“
#include
#include
#include
#define NN 480
#pragma comment(lib “libspeexdsp.lib“)
#pragma warning(disable:4996)
int main()
{
spx_uint32_t i;
short *in;
short *out;
short *fin *fout;
int count = 0;
SpeexResamplerState *st = speex_resampler_init(1 48000 44100 10 NULL);
int nRet = speex_resampler_skip_zeros(st);
in = (short*)malloc(NN * sizeof(short));
out = (short*)malloc(2 * NN * sizeof(short));
fin = (short*)malloc(NN * sizeof(short));
fout = (short*)malloc(2 * NN * sizeof(short));
FILE *pIn = fopen(“in.pcm“ “rb“);
FILE *pOut = fopen(“out.pcm“ “wb“);
if (!pIn || !pOut)
{
printf(“open file Err!\r\n“);
system(“pause“);
return 0;
}
while (1)
{
spx_uint32_t in_len;
spx_uint32_t out_len;
fread(in sizeof(short) NN pIn);
if (feof(pIn))
break;
in_len = NN;
out_len = NN;
if (count==2)
speex_resampler_set_quality(st 10);
speex_resampler_process_interleaved_int(st in &in_len fout &out_len);
fwrite(fout sizeof(short) out_len pOut);
count++;
}
speex_resampler_destroy(st);
free(pIn);
free(pOut);
free(fin);
free(fout);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-10-09 16:18 Speex_Resample\
文件 1455 2020-10-09 14:28 Speex_Resample.sln
文件 3313664 2020-10-09 15:14 Speex_Resample\in.pcm
目录 0 2020-10-09 14:32 Speex_Resample\include\
目录 0 2020-10-09 14:31 Speex_Resample\include\speex\
文件 358 2008-04-25 19:21 Speex_Resample\include\speex\Makefile.am
文件 13456 2008-07-21 10:17 Speex_Resample\include\speex\Makefile.in
文件 13947 2008-04-25 19:21 Speex_Resample\include\speex\speex.h
文件 6669 2007-08-11 21:00 Speex_Resample\include\speex\speex_bits.h
文件 2172 2008-04-25 19:21 Speex_Resample\include\speex\speex_buffer.h
文件 5045 2007-10-25 21:59 Speex_Resample\include\speex\speex_callbacks.h
文件 241 2007-06-23 12:18 Speex_Resample\include\speex\speex_config_types.h.in
文件 6453 2008-06-05 17:27 Speex_Resample\include\speex\speex_echo.h
文件 4103 2008-04-25 19:21 Speex_Resample\include\speex\speex_header.h
文件 7219 2008-04-25 19:21 Speex_Resample\include\speex\speex_jitter.h
文件 8609 2008-05-30 15:34 Speex_Resample\include\speex\speex_preprocess.h
文件 14713 2008-05-05 20:41 Speex_Resample\include\speex\speex_resampler.h
文件 3698 2008-04-25 19:21 Speex_Resample\include\speex\speex_stereo.h
文件 3591 2008-04-25 19:21 Speex_Resample\include\speex\speex_types.h
文件 1119214 2020-10-09 14:43 Speex_Resample\libspeexdsp.lib
文件 2856 2020-10-09 15:28 Speex_Resample\Speex_Resample.cpp
文件 8457 2020-10-09 16:11 Speex_Resample\Speex_Resample.vcxproj
文件 2176 2020-10-09 14:33 Speex_Resample\Speex_Resample.vcxproj.filters
文件 223 2020-10-09 14:35 Speex_Resample\Speex_Resample.vcxproj.user
评论
共有 条评论