【发布时间】:2014-02-10 15:43:07
【问题描述】:
我正在为 iOS 开发一个与录音相关的移动应用程序。
因此,我正在开发一些不同的音效来修改录制的声音,但我在实现其中一些时遇到了问题。
我正在尝试创建回显/延迟效果,我需要将一个字节数组转换为一个短数组,但我不知道如何在 Objective-C 中做到这一点。
谢谢。
这是我目前实现它的源代码,但就像 byte 是一个非常短的类型一样,当我应用衰减(必须返回一个浮点值)时,我的音频会产生可怕的噪音。
- (NSURL *)echo:(NSURL *)input output:(NSURL *)output{
int delay = 50000;
float attenuation = 0.5f;
NSMutableData *audioData = [NSMutableData dataWithContentsOfURL:input];
NSUInteger dataSize = [audioData length] - 44;
NSUInteger audioLength = [audioData length];
NSUInteger newAudioLength = audioLength + delay;
// Copy bytes
Byte *byteData = (Byte*)malloc(audioLength);
memcpy(byteData, [audioData bytes], audioLength);
short *shortData = (short*)malloc(audioLength/2);
// create a new array to store new modify data
Byte *newByteData = (Byte*)malloc(newAudioLength);
newByteData = byteData;
for (int i = 44; i < audioLength - delay; i++)
{
newByteData[i + delay] += byteData[i] * attenuation;
}
// Copy bytes in a new NSMutableData
NSMutableData *newAudioData = [NSMutableData dataWithBytes:newByteData length:newAudioLength];
// Store in a file
[newAudioData writeToFile:[output path] atomically:YES];
// Set WAV size
[[AudioUtils alloc] setAudioFileSize:output];
return output;
}
【问题讨论】:
-
您的音频文件格式是什么?看起来是 WAV 吗?
标签: ios objective-c audio effects voice