add .gitignore
This commit is contained in:
41
msext/Class/Common/VoiceConvert/VoiceConverter.h
Executable file
41
msext/Class/Common/VoiceConvert/VoiceConverter.h
Executable file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// VoiceConverter.h
|
||||
// Jeans
|
||||
//
|
||||
// Created by Jeans Huang on 12-7-22.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@interface VoiceConverter : NSObject
|
||||
|
||||
/**
|
||||
* 转换wav到amr
|
||||
*
|
||||
* @param aWavPath wav文件路径
|
||||
* @param aSavePath amr保存路径
|
||||
*
|
||||
* @return 0失败 1成功
|
||||
*/
|
||||
+ (int)ConvertWavToAmr:(NSString *)aWavPath amrSavePath:(NSString *)aSavePath;
|
||||
|
||||
/**
|
||||
* 转换amr到wav
|
||||
*
|
||||
* @param aAmrPath amr文件路径
|
||||
* @param aSavePath wav保存路径
|
||||
*
|
||||
* @return 0失败 1成功
|
||||
*/
|
||||
+ (int)ConvertAmrToWav:(NSString *)aAmrPath wavSavePath:(NSString *)aSavePath;
|
||||
|
||||
/**
|
||||
获取录音设置.
|
||||
建议使用此设置,如有修改,则转换amr时也要对应修改参数,比较麻烦
|
||||
@returns 录音设置
|
||||
*/
|
||||
+ (NSDictionary*)GetAudioRecorderSettingDict;
|
||||
|
||||
@end
|
||||
50
msext/Class/Common/VoiceConvert/VoiceConverter.mm
Executable file
50
msext/Class/Common/VoiceConvert/VoiceConverter.mm
Executable file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// VoiceConverter.m
|
||||
// Jeans
|
||||
//
|
||||
// Created by Jeans Huang on 12-7-22.
|
||||
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VoiceConverter.h"
|
||||
//#import "interf_dec.h"
|
||||
//#import "dec_if.h"
|
||||
//#import "interf_enc.h"
|
||||
#import "amrFileCodec.h"
|
||||
|
||||
|
||||
@implementation VoiceConverter
|
||||
|
||||
//转换amr到wav
|
||||
+ (int)ConvertAmrToWav:(NSString *)aAmrPath wavSavePath:(NSString *)aSavePath{
|
||||
|
||||
if (! DecodeAMRFileToWAVEFile([aAmrPath cStringUsingEncoding:NSASCIIStringEncoding], [aSavePath cStringUsingEncoding:NSASCIIStringEncoding]))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//转换wav到amr
|
||||
+ (int)ConvertWavToAmr:(NSString *)aWavPath amrSavePath:(NSString *)aSavePath{
|
||||
|
||||
if (! EncodeWAVEFileToAMRFile([aWavPath cStringUsingEncoding:NSASCIIStringEncoding], [aSavePath cStringUsingEncoding:NSASCIIStringEncoding], 1, 16))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//获取录音设置
|
||||
+ (NSDictionary*)GetAudioRecorderSettingDict{
|
||||
NSDictionary *recordSetting = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithFloat: 8000.0],AVSampleRateKey, //采样率
|
||||
[NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,
|
||||
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,//采样位数 默认 16
|
||||
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,//通道的数目
|
||||
// [NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,//大端还是小端 是内存的组织方式
|
||||
// [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,//采样信号是整数还是浮点数
|
||||
// [NSNumber numberWithInt: AVAudioQualityMedium],AVEncoderAudioQualityKey,//音频编码质量
|
||||
nil];
|
||||
return recordSetting;
|
||||
}
|
||||
|
||||
@end
|
||||
75
msext/Class/Common/VoiceConvert/amrwapper/amrFileCodec.h
Executable file
75
msext/Class/Common/VoiceConvert/amrwapper/amrFileCodec.h
Executable file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// amrFileCodec.h
|
||||
// amrDemoForiOS
|
||||
//
|
||||
// Created by Tang Xiaoping on 9/27/11.
|
||||
// Copyright 2011 test. All rights reserved.
|
||||
//
|
||||
#ifndef amrFileCodec_h
|
||||
#define amrFileCodec_h
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "interf_dec.h"
|
||||
#include "interf_enc.h"
|
||||
|
||||
#define AMR_MAGIC_NUMBER "#!AMR\n"
|
||||
|
||||
#define PCM_FRAME_SIZE 160 // 8khz 8000*0.02=160
|
||||
#define MAX_AMR_FRAME_SIZE 32
|
||||
#define AMR_FRAME_COUNT_PER_SECOND 50
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char chChunkID[4];
|
||||
int nChunkSize;
|
||||
}XCHUNKHEADER;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short nFormatTag;
|
||||
short nChannels;
|
||||
int nSamplesPerSec;
|
||||
int nAvgBytesPerSec;
|
||||
short nBlockAlign;
|
||||
short nBitsPerSample;
|
||||
}WAVEFORMAT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short nFormatTag;
|
||||
short nChannels;
|
||||
int nSamplesPerSec;
|
||||
int nAvgBytesPerSec;
|
||||
short nBlockAlign;
|
||||
short nBitsPerSample;
|
||||
short nExSize;
|
||||
}WAVEFORMATX;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char chRiffID[4];
|
||||
int nRiffSize;
|
||||
char chRiffFormat[4];
|
||||
}RIFFHEADER;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char chFmtID[4];
|
||||
int nFmtSize;
|
||||
WAVEFORMAT wf;
|
||||
}FMTBLOCK;
|
||||
|
||||
// WAVE音频采样频率是8khz
|
||||
// 音频样本单元数 = 8000*0.02 = 160 (由采样频率决定)
|
||||
// 声道数 1 : 160
|
||||
// 2 : 160*2 = 320
|
||||
// bps决定样本(sample)大小
|
||||
// bps = 8 --> 8位 unsigned char
|
||||
// 16 --> 16位 unsigned short
|
||||
int EncodeWAVEFileToAMRFile(const char* pchWAVEFilename, const char* pchAMRFileName, int nChannels, int nBitsPerSample);
|
||||
|
||||
// 将AMR文件解码成WAVE文件
|
||||
int DecodeAMRFileToWAVEFile(const char* pchAMRFileName, const char* pchWAVEFilename);
|
||||
|
||||
#endif
|
||||
393
msext/Class/Common/VoiceConvert/amrwapper/amrFileCodec.mm
Executable file
393
msext/Class/Common/VoiceConvert/amrwapper/amrFileCodec.mm
Executable file
@@ -0,0 +1,393 @@
|
||||
//
|
||||
// amrFileCodec.cpp
|
||||
// amrDemoForiOS
|
||||
//
|
||||
// Created by Tang Xiaoping on 9/27/11.
|
||||
// Copyright 2011 test. All rights reserved.
|
||||
//
|
||||
|
||||
#include "amrFileCodec.h"
|
||||
int amrEncodeMode[] = {4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200}; // amr 编码方式
|
||||
// 从WAVE文件中跳过WAVE文件头,直接到PCM音频数据
|
||||
void SkipToPCMAudioData(FILE* fpwave)
|
||||
{
|
||||
RIFFHEADER riff;
|
||||
FMTBLOCK fmt;
|
||||
XCHUNKHEADER chunk;
|
||||
WAVEFORMATX wfx;
|
||||
int bDataBlock = 0;
|
||||
|
||||
// 1. 读RIFF头
|
||||
fread(&riff, 1, sizeof(RIFFHEADER), fpwave);
|
||||
|
||||
// 2. 读FMT块 - 如果 fmt.nFmtSize>16 说明需要还有一个附属大小没有读
|
||||
fread(&chunk, 1, sizeof(XCHUNKHEADER), fpwave);
|
||||
if ( chunk.nChunkSize>16 )
|
||||
{
|
||||
fread(&wfx, 1, sizeof(WAVEFORMATX), fpwave);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(fmt.chFmtID, chunk.chChunkID, 4);
|
||||
fmt.nFmtSize = chunk.nChunkSize;
|
||||
fread(&fmt.wf, 1, sizeof(WAVEFORMAT), fpwave);
|
||||
}
|
||||
|
||||
// 3.转到data块 - 有些还有fact块等。
|
||||
while(!bDataBlock)
|
||||
{
|
||||
fread(&chunk, 1, sizeof(XCHUNKHEADER), fpwave);
|
||||
if ( !memcmp(chunk.chChunkID, "data", 4) )
|
||||
{
|
||||
bDataBlock = 1;
|
||||
break;
|
||||
}
|
||||
// 因为这个不是data块,就跳过块数据
|
||||
fseek(fpwave, chunk.nChunkSize, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
|
||||
// 从WAVE文件读一个完整的PCM音频帧
|
||||
// 返回值: 0-错误 >0: 完整帧大小
|
||||
int ReadPCMFrame(short speech[], FILE* fpwave, int nChannels, int nBitsPerSample)
|
||||
{
|
||||
int nRead = 0;
|
||||
int x = 0, y=0;
|
||||
// unsigned short ush1=0, ush2=0, ush=0;
|
||||
|
||||
// 原始PCM音频帧数据
|
||||
unsigned char pcmFrame_8b1[PCM_FRAME_SIZE];
|
||||
unsigned char pcmFrame_8b2[PCM_FRAME_SIZE<<1];
|
||||
unsigned short pcmFrame_16b1[PCM_FRAME_SIZE];
|
||||
unsigned short pcmFrame_16b2[PCM_FRAME_SIZE<<1];
|
||||
|
||||
if (nBitsPerSample==8 && nChannels==1)
|
||||
{
|
||||
|
||||
nRead = fread(pcmFrame_8b1, (nBitsPerSample/8), PCM_FRAME_SIZE*nChannels, fpwave);
|
||||
|
||||
for(x=0; x<PCM_FRAME_SIZE; x++)
|
||||
{
|
||||
speech[x] =(short)((short)pcmFrame_8b1[x] << 7);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (nBitsPerSample==8 && nChannels==2)
|
||||
{
|
||||
nRead = fread(pcmFrame_8b2, (nBitsPerSample/8), PCM_FRAME_SIZE*nChannels, fpwave);
|
||||
for( x=0, y=0; y<PCM_FRAME_SIZE; y++,x+=2 )
|
||||
{
|
||||
// 1 - 取两个声道之左声道
|
||||
speech[y] =(short)((short)pcmFrame_8b2[x+0] << 7);
|
||||
// 2 - 取两个声道之右声道
|
||||
//speech[y] =(short)((short)pcmFrame_8b2[x+1] << 7);
|
||||
// 3 - 取两个声道的平均值
|
||||
//ush1 = (short)pcmFrame_8b2[x+0];
|
||||
//ush2 = (short)pcmFrame_8b2[x+1];
|
||||
//ush = (ush1 + ush2) >> 1;
|
||||
//speech[y] = (short)((short)ush << 7);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (nBitsPerSample==16 && nChannels==1)
|
||||
{
|
||||
nRead = fread(pcmFrame_16b1, (nBitsPerSample/8), PCM_FRAME_SIZE*nChannels, fpwave);
|
||||
for(x=0; x<PCM_FRAME_SIZE; x++)
|
||||
{
|
||||
speech[x] = (short)pcmFrame_16b1[x+0];
|
||||
}
|
||||
}
|
||||
else
|
||||
if (nBitsPerSample==16 && nChannels==2)
|
||||
{
|
||||
nRead = fread(pcmFrame_16b2, (nBitsPerSample/8), PCM_FRAME_SIZE*nChannels, fpwave);
|
||||
for( x=0, y=0; y<PCM_FRAME_SIZE; y++,x+=2 )
|
||||
{
|
||||
//speech[y] = (short)pcmFrame_16b2[x+0];
|
||||
speech[y] = (short)((int)((int)pcmFrame_16b2[x+0] + (int)pcmFrame_16b2[x+1])) >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果读到的数据不是一个完整的PCM帧, 就返回0
|
||||
if (nRead<PCM_FRAME_SIZE*nChannels) return 0;
|
||||
|
||||
return nRead;
|
||||
}
|
||||
|
||||
// WAVE音频采样频率是8khz
|
||||
// 音频样本单元数 = 8000*0.02 = 160 (由采样频率决定)
|
||||
// 声道数 1 : 160
|
||||
// 2 : 160*2 = 320
|
||||
// bps决定样本(sample)大小
|
||||
// bps = 8 --> 8位 unsigned char
|
||||
// 16 --> 16位 unsigned short
|
||||
int EncodeWAVEFileToAMRFile(const char* pchWAVEFilename, const char* pchAMRFileName, int nChannels, int nBitsPerSample)
|
||||
{
|
||||
FILE* fpwave;
|
||||
FILE* fpamr;
|
||||
|
||||
/* input speech vector */
|
||||
short speech[160];
|
||||
|
||||
/* counters */
|
||||
int byte_counter, frames = 0, bytes = 0;
|
||||
|
||||
/* pointer to encoder state structure */
|
||||
void *enstate;
|
||||
|
||||
/* requested mode */
|
||||
enum Mode req_mode = MR122;
|
||||
int dtx = 0;
|
||||
|
||||
/* bitstream filetype */
|
||||
unsigned char amrFrame[MAX_AMR_FRAME_SIZE];
|
||||
|
||||
fpwave = fopen(pchWAVEFilename, "rb");
|
||||
if (fpwave == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 创建并初始化amr文件
|
||||
fpamr = fopen(pchAMRFileName, "wb");
|
||||
if (fpamr == NULL)
|
||||
{
|
||||
fclose(fpwave);
|
||||
return 0;
|
||||
}
|
||||
/* write magic number to indicate single channel AMR file storage format */
|
||||
bytes = fwrite(AMR_MAGIC_NUMBER, sizeof(char), strlen(AMR_MAGIC_NUMBER), fpamr);
|
||||
|
||||
/* skip to pcm audio data*/
|
||||
SkipToPCMAudioData(fpwave);
|
||||
|
||||
enstate = Encoder_Interface_init(dtx);
|
||||
|
||||
while(1)
|
||||
{
|
||||
// read one pcm frame
|
||||
if (!ReadPCMFrame(speech, fpwave, nChannels, nBitsPerSample)) break;
|
||||
|
||||
frames++;
|
||||
|
||||
/* call encoder */
|
||||
byte_counter = Encoder_Interface_Encode(enstate, req_mode, speech, amrFrame, 0);
|
||||
|
||||
bytes += byte_counter;
|
||||
fwrite(amrFrame, sizeof (unsigned char), byte_counter, fpamr );
|
||||
}
|
||||
|
||||
Encoder_Interface_exit(enstate);
|
||||
|
||||
fclose(fpamr);
|
||||
fclose(fpwave);
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma mark - Decode
|
||||
//decode
|
||||
void WriteWAVEFileHeader(FILE* fpwave, int nFrame)
|
||||
{
|
||||
char tag[10] = "";
|
||||
|
||||
// 1. 写RIFF头
|
||||
RIFFHEADER riff;
|
||||
strcpy(tag, "RIFF");
|
||||
memcpy(riff.chRiffID, tag, 4);
|
||||
riff.nRiffSize = 4 // WAVE
|
||||
+ sizeof(XCHUNKHEADER) // fmt
|
||||
+ sizeof(WAVEFORMATX) // WAVEFORMATX
|
||||
+ sizeof(XCHUNKHEADER) // DATA
|
||||
+ nFrame*160*sizeof(short); //
|
||||
strcpy(tag, "WAVE");
|
||||
memcpy(riff.chRiffFormat, tag, 4);
|
||||
fwrite(&riff, 1, sizeof(RIFFHEADER), fpwave);
|
||||
|
||||
// 2. 写FMT块
|
||||
XCHUNKHEADER chunk;
|
||||
WAVEFORMATX wfx;
|
||||
strcpy(tag, "fmt ");
|
||||
memcpy(chunk.chChunkID, tag, 4);
|
||||
chunk.nChunkSize = sizeof(WAVEFORMATX);
|
||||
fwrite(&chunk, 1, sizeof(XCHUNKHEADER), fpwave);
|
||||
memset(&wfx, 0, sizeof(WAVEFORMATX));
|
||||
wfx.nFormatTag = 1;
|
||||
wfx.nChannels = 1; // 单声道
|
||||
wfx.nSamplesPerSec = 8000; // 8khz
|
||||
wfx.nAvgBytesPerSec = 16000;
|
||||
wfx.nBlockAlign = 2;
|
||||
wfx.nBitsPerSample = 16; // 16位
|
||||
fwrite(&wfx, 1, sizeof(WAVEFORMATX), fpwave);
|
||||
|
||||
// 3. 写data块头
|
||||
strcpy(tag, "data");
|
||||
memcpy(chunk.chChunkID, tag, 4);
|
||||
chunk.nChunkSize = nFrame*160*sizeof(short);
|
||||
fwrite(&chunk, 1, sizeof(XCHUNKHEADER), fpwave);
|
||||
}
|
||||
|
||||
const int myround(const double x)
|
||||
{
|
||||
return((int)(x+0.5));
|
||||
}
|
||||
|
||||
// 根据帧头计算当前帧大小
|
||||
int caclAMRFrameSize(unsigned char frameHeader)
|
||||
{
|
||||
int mode;
|
||||
int temp1 = 0;
|
||||
int temp2 = 0;
|
||||
int frameSize;
|
||||
|
||||
temp1 = frameHeader;
|
||||
|
||||
// 编码方式编号 = 帧头的3-6位
|
||||
temp1 &= 0x78; // 0111-1000
|
||||
temp1 >>= 3;
|
||||
|
||||
mode = amrEncodeMode[temp1];
|
||||
|
||||
// 计算amr音频数据帧大小
|
||||
// 原理: amr 一帧对应20ms,那么一秒有50帧的音频数据
|
||||
temp2 = myround((double)(((double)mode / (double)AMR_FRAME_COUNT_PER_SECOND) / (double)8));
|
||||
|
||||
frameSize = myround((double)temp2 + 0.5);
|
||||
return frameSize;
|
||||
}
|
||||
|
||||
// 读第一个帧 - (参考帧)
|
||||
// 返回值: 0-出错; 1-正确
|
||||
int ReadAMRFrameFirst(FILE* fpamr, unsigned char frameBuffer[], int* stdFrameSize, unsigned char* stdFrameHeader)
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wsizeof-array-argument"
|
||||
#pragma clang diagnostic ignored "-Wsizeof-pointer-memaccess"
|
||||
memset(frameBuffer, 0, sizeof(frameBuffer));
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// 先读帧头
|
||||
fread(stdFrameHeader, 1, sizeof(unsigned char), fpamr);
|
||||
if (feof(fpamr)) return 0;
|
||||
|
||||
// 根据帧头计算帧大小
|
||||
*stdFrameSize = caclAMRFrameSize(*stdFrameHeader);
|
||||
|
||||
// 读首帧
|
||||
frameBuffer[0] = *stdFrameHeader;
|
||||
fread(&(frameBuffer[1]), 1, (*stdFrameSize-1)*sizeof(unsigned char), fpamr);
|
||||
if (feof(fpamr)) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 返回值: 0-出错; 1-正确
|
||||
int ReadAMRFrame(FILE* fpamr, unsigned char frameBuffer[], int stdFrameSize, unsigned char stdFrameHeader)
|
||||
{
|
||||
int bytes = 0;
|
||||
unsigned char frameHeader; // 帧头
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wsizeof-array-argument"
|
||||
#pragma clang diagnostic ignored "-Wsizeof-pointer-memaccess"
|
||||
memset(frameBuffer, 0, sizeof(frameBuffer));
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// 读帧头
|
||||
// 如果是坏帧(不是标准帧头),则继续读下一个字节,直到读到标准帧头
|
||||
while(1)
|
||||
{
|
||||
bytes = fread(&frameHeader, 1, sizeof(unsigned char), fpamr);
|
||||
if (feof(fpamr)) return 0;
|
||||
if (frameHeader == stdFrameHeader) break;
|
||||
}
|
||||
|
||||
// 读该帧的语音数据(帧头已经读过)
|
||||
frameBuffer[0] = frameHeader;
|
||||
bytes = fread(&(frameBuffer[1]), 1, (stdFrameSize-1)*sizeof(unsigned char), fpamr);
|
||||
if (feof(fpamr)) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 将AMR文件解码成WAVE文件
|
||||
int DecodeAMRFileToWAVEFile(const char* pchAMRFileName, const char* pchWAVEFilename)
|
||||
{
|
||||
|
||||
|
||||
FILE* fpamr = NULL;
|
||||
FILE* fpwave = NULL;
|
||||
char magic[8];
|
||||
void * destate;
|
||||
int nFrameCount = 0;
|
||||
int stdFrameSize;
|
||||
unsigned char stdFrameHeader;
|
||||
|
||||
unsigned char amrFrame[MAX_AMR_FRAME_SIZE];
|
||||
short pcmFrame[PCM_FRAME_SIZE];
|
||||
|
||||
// NSString * path = [[NSBundle mainBundle] pathForResource: @"test" ofType: @"amr"];
|
||||
// fpamr = fopen([path cStringUsingEncoding:NSASCIIStringEncoding], "rb");
|
||||
fpamr = fopen(pchAMRFileName, "rb");
|
||||
|
||||
if ( fpamr==NULL ) return 0;
|
||||
|
||||
// 检查amr文件头
|
||||
fread(magic, sizeof(char), strlen(AMR_MAGIC_NUMBER), fpamr);
|
||||
if (strncmp(magic, AMR_MAGIC_NUMBER, strlen(AMR_MAGIC_NUMBER)))
|
||||
{
|
||||
fclose(fpamr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 创建并初始化WAVE文件
|
||||
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
// NSString *documentPath = [paths objectAtIndex:0];
|
||||
// NSString *docFilePath = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%s", pchWAVEFilename]];
|
||||
// NSLog(@"documentPath=%@", documentPath);
|
||||
//
|
||||
// fpwave = fopen([docFilePath cStringUsingEncoding:NSASCIIStringEncoding], "wb");
|
||||
fpwave = fopen(pchWAVEFilename,"wb");
|
||||
|
||||
WriteWAVEFileHeader(fpwave, nFrameCount);
|
||||
|
||||
/* init decoder */
|
||||
destate = Decoder_Interface_init();
|
||||
|
||||
// 读第一帧 - 作为参考帧
|
||||
memset(amrFrame, 0, sizeof(amrFrame));
|
||||
memset(pcmFrame, 0, sizeof(pcmFrame));
|
||||
ReadAMRFrameFirst(fpamr, amrFrame, &stdFrameSize, &stdFrameHeader);
|
||||
|
||||
// 解码一个AMR音频帧成PCM数据
|
||||
Decoder_Interface_Decode(destate, amrFrame, pcmFrame, 0);
|
||||
nFrameCount++;
|
||||
fwrite(pcmFrame, sizeof(short), PCM_FRAME_SIZE, fpwave);
|
||||
|
||||
// 逐帧解码AMR并写到WAVE文件里
|
||||
while(1)
|
||||
{
|
||||
memset(amrFrame, 0, sizeof(amrFrame));
|
||||
memset(pcmFrame, 0, sizeof(pcmFrame));
|
||||
if (!ReadAMRFrame(fpamr, amrFrame, stdFrameSize, stdFrameHeader)) break;
|
||||
|
||||
// 解码一个AMR音频帧成PCM数据 (8k-16b-单声道)
|
||||
Decoder_Interface_Decode(destate, amrFrame, pcmFrame, 0);
|
||||
nFrameCount++;
|
||||
fwrite(pcmFrame, sizeof(short), PCM_FRAME_SIZE, fpwave);
|
||||
}
|
||||
printf("frame = %d\n", nFrameCount);
|
||||
Decoder_Interface_exit(destate);
|
||||
|
||||
fclose(fpwave);
|
||||
|
||||
// 重写WAVE文件头
|
||||
// fpwave = fopen([docFilePath cStringUsingEncoding:NSASCIIStringEncoding], "r+");
|
||||
fpwave = fopen(pchWAVEFilename, "r+");
|
||||
WriteWAVEFileHeader(fpwave, nFrameCount);
|
||||
fclose(fpwave);
|
||||
|
||||
return nFrameCount;
|
||||
}
|
||||
BIN
msext/Class/Common/VoiceConvert/lib/libopencore-amrnb.a
Executable file
BIN
msext/Class/Common/VoiceConvert/lib/libopencore-amrnb.a
Executable file
Binary file not shown.
BIN
msext/Class/Common/VoiceConvert/lib/libopencore-amrwb.a
Executable file
BIN
msext/Class/Common/VoiceConvert/lib/libopencore-amrwb.a
Executable file
Binary file not shown.
34
msext/Class/Common/VoiceConvert/opencore-amrnb/interf_dec.h
Executable file
34
msext/Class/Common/VoiceConvert/opencore-amrnb/interf_dec.h
Executable file
@@ -0,0 +1,34 @@
|
||||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 2009 Martin Storsjo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef OPENCORE_AMRNB_INTERF_DEC_H
|
||||
#define OPENCORE_AMRNB_INTERF_DEC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void* Decoder_Interface_init(void);
|
||||
void Decoder_Interface_exit(void* state);
|
||||
void Decoder_Interface_Decode(void* state, const unsigned char* in, short* out, int bfi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
50
msext/Class/Common/VoiceConvert/opencore-amrnb/interf_enc.h
Executable file
50
msext/Class/Common/VoiceConvert/opencore-amrnb/interf_enc.h
Executable file
@@ -0,0 +1,50 @@
|
||||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 2009 Martin Storsjo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef OPENCORE_AMRNB_INTERF_ENC_H
|
||||
#define OPENCORE_AMRNB_INTERF_ENC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef AMRNB_WRAPPER_INTERNAL
|
||||
/* Copied from enc/src/gsmamr_enc.h */
|
||||
enum Mode {
|
||||
MR475 = 0,/* 4.75 kbps */
|
||||
MR515, /* 5.15 kbps */
|
||||
MR59, /* 5.90 kbps */
|
||||
MR67, /* 6.70 kbps */
|
||||
MR74, /* 7.40 kbps */
|
||||
MR795, /* 7.95 kbps */
|
||||
MR102, /* 10.2 kbps */
|
||||
MR122, /* 12.2 kbps */
|
||||
MRDTX, /* DTX */
|
||||
N_MODES /* Not Used */
|
||||
};
|
||||
#endif
|
||||
|
||||
void* Encoder_Interface_init(int dtx);
|
||||
void Encoder_Interface_exit(void* state);
|
||||
int Encoder_Interface_Encode(void* state, enum Mode mode, const short* speech, unsigned char* out, int forceSpeech);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
36
msext/Class/Common/VoiceConvert/opencore-amrwb/dec_if.h
Executable file
36
msext/Class/Common/VoiceConvert/opencore-amrwb/dec_if.h
Executable file
@@ -0,0 +1,36 @@
|
||||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 2009 Martin Storsjo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef OPENCORE_AMRWB_DEC_IF_H
|
||||
#define OPENCORE_AMRWB_DEC_IF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _good_frame 0
|
||||
|
||||
void* D_IF_init(void);
|
||||
void D_IF_decode(void* state, const unsigned char* bits, short* synth, int bfi);
|
||||
void D_IF_exit(void* state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
33
msext/Class/Common/VoiceConvert/opencore-amrwb/if_rom.h
Executable file
33
msext/Class/Common/VoiceConvert/opencore-amrwb/if_rom.h
Executable file
@@ -0,0 +1,33 @@
|
||||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 2009 Martin Storsjo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef OPENCORE_AMRWB_IF_ROM_H
|
||||
#define OPENCORE_AMRWB_IF_ROM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
typedef int16_t Word16;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user