我想知道是否有人发现了在iPhone SDK中生成音调的方法。我正在尝试生成DTMF音调,但似乎找不到任何实质性的东西。我希望能够指定播放音调的时间(例如,模拟按住按钮,而不是简单地按下它。)
我发现了一个名为iPhreak的开源应用程序。据推测,它会生成DTMF音调来愚弄公用电话(我向你保证这不是我的本意--我的公司处理基于电话的对讲机系统)。该应用程序的唯一问题是开源项目中缺少文件。也许其他人在过去已经让这个项目起作用了?
如果有人知道我会在哪里找到这样的东西,我将非常感谢我的投票:)
发布于 2009-09-09 14:05:18
应该很容易生成你自己。如果硬件能够以44.1 khz的频率回放pcm缓冲区(16位采样)(它肯定可以使用一些库函数或其他库函数),那么您只需要计算波形:
const int PLAYBACKFREQ = 44100;
const float PI2 = 3.14159265359f * 2;
void generateDTMF(short *buffer, int length, float freq1, float freq2)
{
int i;
short *dest = buffer;
for(i=0; i<length; i++)
{
*(dest++) = (sin(i*(PI2*(PLAYBACKFREQ/freq1))) + sin(i (PI2*(PLAYBACKFREQ/freq2)))) * 16383;
}
}16383已经完成了,因为我使用了加法合成(只需将正弦波相加在一起)。因此,最大结果是-32768 -2.0,所以乘以16383后,我得到的最大16位结果或多或少是:-32768- +32767
编辑:这2个频率是另一个回复的人链接到的维基百科文章中的频率。两个独特的频率发出DTMF声音
发布于 2009-10-13 04:03:39
简单的答案是:
soundArray = [[NSArray alloc] initWithObjects:
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-0.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-1.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-2.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-3.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-4.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-5.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-6.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-7.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-8.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-9.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-0.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-pound.caf"] autorelease],
[[[SoundEffect alloc] initWithContentsOfFile: @"/System/Library/Audio/UISounds/dtmf-star.caf"] autorelease],
nil];这就对了。所有声音的标准电话键盘,在一个阵列,随时为您提供享受。
发布于 2016-05-01 04:37:00
Swift DTMF声音
我正在尝试生成PCM数据,并在Swift中想到了这一点。此函数将生成一个[Float],它是音频样本。你可以用AVAudio来玩它们。
每个DTMF由一对音调、一个标记长度(250ms)、一个空格长度(250ms)组成,当然,您还需要指定一个采样频率(8000 Hz)。对于我所说的标准人工拨号,Mark and Space通常在250ms左右。采样频率玩起来很有趣,但需要是最高频率的两倍。为了好玩,你可以把它放在下面来听听发生了什么。
public static func generateDTMF(frequency1 frequency1: Float, frequency2: Float, markSpace: MarkSpaceType, sampleRate: Float) -> [Float]
{
let toneLengthInSamples = 10e-4 * markSpace.0 * sampleRate
let silenceLengthInSamples = 10e-4 * markSpace.1 * sampleRate
var sound = [Float](count: Int(toneLengthInSamples + silenceLengthInSamples), repeatedValue: 0)
let twoPI = 2.0 * Float(M_PI)
for i in 0 ..< Int(toneLengthInSamples) {
// Add first tone at half volume
let sample1 = 0.5 * sin(Float(i) * twoPI / (sampleRate / frequency1));
// Add second tone at half volume
let sample2 = 0.5 * sin(Float(i) * twoPI / (sampleRate / frequency2));
sound[i] = sample1 + sample2
}
return sound
}完整的游乐场可以在GitHub上下载。
https://stackoverflow.com/questions/1399501
复制相似问题