7

我想知道是否有人遇到过在 iPhone SDK 中生成音调的方法。我正在尝试生成 DTMF 音调,但似乎找不到任何实质性的东西。我还希望能够指定播放音调的时间(即模拟按住按钮而不是简单地按下它......

我找到了一个名为 iPhreak 的开源应用程序。据说它会产生 DTMF 音调来欺骗公用电话(我向你保证这不是我的意图——我的公司处理基于电话的对讲系统)。该应用程序的唯一问题是开源项目中缺少文件。也许其他人过去已经让这个项目工作了?

如果有人知道我会在哪里寻找这样的东西,我会非常感谢我的投票:)

4

3 回答 3

5

应该很容易生成自己。鉴于硬件可以以 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 已经完成,因为我使用的是加法合成(只需将正弦波加在一起)。因此最大结果是 -2.0 - 2.0 所以乘以 16383 后,我或多或少地得到最大 16 位结果:-32768 - +32767

编辑:这两个频率是来自维基百科文章的频率,另一个回答的人链接到。两个独特的频率发出 DTMF 声音

于 2009-09-09T14:05:18.250 回答
5

简单的答案是这样的:

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];

你有它。标准电话键盘的所有声音,排列成一个阵列,随时供您欣赏。

于 2009-10-13T04:03:39.170 回答
1

Swift DTMF 声音

我正在尝试生成 PCM 数据,并在 Swift 中提出了这个问题。此函数将生成[Float]音频样本。您可以使用AVAudio.

每个DTMF由一对音调、一个标记长度 (250 ms)、一个间隔长度 (250 ms) 组成,当然您还需要指定一个采样频率 (8000 Hz)。对于我所说的标准人工拨号,Mark 和 Space通常在 250 毫秒左右。采样频率很有趣,但需要是最高频率的两倍。为了好玩,你可以把它放到下面来听听会发生什么。

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
}

完整的 Playground 可以在GitHub 上下载。

于 2016-04-30T20:37:00.353 回答