【发布时间】:2011-05-29 04:06:13
【问题描述】:
我正在尝试为 iphone 应用程序实现低通滤波器,在该应用程序中我录制声音,然后播放时声音会略微低沉;好像声音是从另一个房间传来的。
我研究了音频录制和处理的不同选项,发现它有点令人困惑……数字信号处理根本不是一个强项。我主要研究了 OpenAL,在 EFX 库中,有一个过滤器专门满足我的需求,但 iPhone 中不包含 EFX。有没有办法使用 iPhone 的 OpenAL 来复制这种行为?是否有其他选项(例如 Audio Units)可以提供解决方案?
感谢您的帮助
编辑:
所以在汤姆的回答和链接之后,我想出了我认为正确的实现。但是,我根本没有得到消音效果,而只是音量减少。这是我目前拥有的(摘要)代码:
使用 AVAudioRecorder 和以下设置录制文件:
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
然后我读入文件并使用以下代码对其进行转换:
// Read in the file using AudioFileOpenURL
AudioFileID fileID = [self openAudioFile:filePath];
// find out how big the actual audio data is
UInt32 fileSize = [self audioFileSize:fileID];
// allocate the memory to hold the file
SInt16 * outData = (SInt16 *)malloc(fileSize);
// Read in the file to outData
OSStatus result = noErr;
result = AudioFileReadBytes(fileID, false, 0, &fileSize, outData);
// close off the file
AudioFileClose(fileID);
// Allocate memory to hold the transformed values
SInt16 * transformData = (SInt16 *)malloc(fileSize);
// Start the transform - Need to set alpha to 0.15 or below to have a noticeable affect
float alpha = 1;
// Code as per Tom's example
transformData[0] = outData[0];
for(int sample = 1; sample < fileSize / sizeof(SInt16); sample ++)
{
transformData[sample] = transformData[sample - 1] + alpha * (outData[sample] - transformData[sample - 1]);
}
// Add the data to OpenAL buffer
NSUInteger bufferID;
// grab a buffer ID from openAL
alGenBuffers(1, &bufferID);
// Add the audio data into the new buffer
alBufferData(bufferID,AL_FORMAT_MONO16,transformData,fileSize,44100);
所以,在这之后,我然后使用标准方法通过 OpenAL 播放它(我认为它对我的结果没有任何影响,所以我不会在这里包含它。)
我已经跟踪了转换前后的结果,它们对我来说似乎是正确的,即之前的值正负变化,正如我所期望的那样,for 循环肯定会使这些值变平。但正如我之前提到的,我只看到(在我看来)音量减少,所以我能够增加增益并抵消我刚刚所做的。
看来我一定是在处理错误的价值观。关于我在这里做错了什么的任何建议?
【问题讨论】:
-
你好....你有什么发现吗?
标签: iphone filter signal-processing openal