应该很容易产生自己.考虑到硬件可以以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;
}
}
Run Code Online (Sandbox Code Playgroud)
由于我正在使用添加剂合成(仅将正弦波加在一起),因此完成了16383.因此最大结果是-2.0 - 2.0所以在乘以16383后,我或多或少得到最大16位结果:-32768 - +32767
编辑:2个常见的是来自维基百科文章的频繁,其他人回答链接.两个独特的频率产生DTMF声音
答案很简单:
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];
Run Code Online (Sandbox Code Playgroud)
你有它.所有标准电话键盘的声音,阵列,准备好您的乐趣.