在iPhone中使用FMOD为音频添加效果并保存新音频

时间:2012-11-28 07:14:44

标签: iphone ios ipad audio fmod

我正在使用FMOD在音频文件中添加效果,并将带有效果的音频保存到文档目录中。我面临的问题是,如果音频已停止,FMOD会继续将数据写入文件。如果音频已经完成,我应该用什么来阻止FMOD写入数据? 以下是我的代码......

- (void)startFMODToAddEffects
{
FMOD_RESULT result = FMOD_OK;

unsigned int  version       = 0;

/*
 Create a System object and initialize
 */
result = FMOD::System_Create(&system);
ERRCHECK(result);

result = system->getVersion(&version);
ERRCHECK(result);

if (version < FMOD_VERSION)
{
    fprintf(stderr, "You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
    exit(-1);
}

char buffer[200] = {0};
NSString *tFileName=[NSString stringWithFormat:@"%@/Part2.m4a", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
[tFileName getCString:buffer maxLength:200 encoding:NSASCIIStringEncoding];

char cDest[200] = {0};
NSString *fileName=[NSString stringWithFormat:@"%@/Part2WithEffect.wav", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
[fileName getCString:cDest maxLength:200 encoding:NSASCIIStringEncoding];

result = system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER);
ERRCHECK(result);

result = system->init(32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, cDest);
ERRCHECK(result);

result = system->createStream(buffer, FMOD_SOFTWARE, NULL, &sound);
ERRCHECK(result);

result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);

result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
ERRCHECK(result);

result = system->addDSP(dsplowpass, NULL);
ERRCHECK(result);
}

1 个答案:

答案 0 :(得分:0)

只需调用您停止播放的方法

  

//系统::释放
  system - &gt;释放();

它应该停止在您的文件中写入数据。