mptkcodec工程(二):VS2008+Win7 编译 mptkcodec(上)

注:该mptkcodec工程来自http://manusourcecode.googlecode.com/svn/mptkcodec

1.在linux或cygwin下编译得到mpkt.h和mpktcodec.h拷贝到trunk下自建的inc目录下。拷贝dsp_windows.h(来自libdsp_windows目录),拷贝mp_system.h到inc目录下。

在mpkt.h中加入加入

#include <string.h>
#include <math.h>
#define round(x) floor(x+0.5) //??

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define VERSION "0.5.2"

在mptkcodec.h加入

#include <math.h>
__inline double log2(double n)
{
return (log(n)/log(2.0));
}

改#define FFT_WISDOM 1 为 #define FFT_WISDOM 0

2.拷贝fftw3.h和sndfile.h到inc目录下。

3.建立libdsp_windows工程,生成静态lib库。注意,dsp_windows.c需要增加包含#include <math.h>和

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

因为若不包含math.h文件,sin和cos无法计算,可以编译通过,但是会计算出错。而M_PI不在windows的math.h中要自己增加。

4.建立libmpkt静态库工程。修改如下部分

4.1 把所有的不定长度的数组申请改为malloc申请。注意释放,尤其在函数有多个出口的时候。linux支持数组不定长度申请,而windows不支持。

例如在atom.cpp 中

原申请数组

MP_Sample_t totalBuffer[totalChanLen];

这样在windows无法编译,

要改为

MP_Sample_t *totalBuffer = (MP_Sample_t *)malloc(sizeof(MP_Sample_t)*totalChanLen);

(注意释放)

4.2

把所有的fopen中的“w”或“r”改为“wb”,“rb”。否则在linux下的“w”、“r”会生成0x0A,而windows会产生0x0d,0x0a

4.3

把mp_messaging.cpp内的snprintf改为_snprintf.在windows无snprintf函数,有_snprintf函数。

在mp_messaging.cpp包含

#include <stdio.h>
#include <stdarg.h>。

4.4 删掉anywave_table_scanner.cpp的#include <unistd.h>

4.5 在mtrand.c加入#include <math.h>

5. 建立libmptkcodec工程

5.1 把所有的不定长度的数组申请改为malloc申请。注意释放,

5.2 在pow(2,x)这样的函数调用中,把2改为浮点表示2.0

6 根据makefile的提示,建立各个需要生成的win32控制台程序工程。

有mptkcodec_convert,mptkcodec_snr,mptkcodec_decompose_code,mptkcodec_decompose,mptkcodec_code,mptkcodec_decode,mptkcodec_synth。

6.1 删除部分文件中的#include <sys/time.h>

6.2 把所有的“w”,“r”改为“wb”,“rb”。

6.3 windows没有gettimeofday函数,在inc目录下建立gettimeofday.h工程,加入如下代码

/*********************/

#include <winsock.h>

__inline int gettimeofday(struct timeval* tv)

{
union {
long long ns100;
FILETIME ft;
} now;

GetSystemTimeAsFileTime (&now.ft);
tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL);
tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL);
return (0);
}

/********************/

在用到gettimeofday函数的工程文件中加入#include <gettimeofday.h>。

7. 注意所有工程的输出目录改为trunk下的output目录,设置include目录,设置lib目录,把sndfile的lib库和fftw3的lib库拷贝到指定目录下。

原文地址:https://www.cnblogs.com/gaozehua/p/2223133.html