Generate DTMF Tones
I am wondering if anyone has come across a way to generate tones in the iPhone SDK. I am trying to generate DTMF tones, and can't seem to find anything substantial out there. I want to be able to specify how long to play the tone for as well (i.e. to simulate holding the button down as opposed to just pressing it briefly..
I found an open source app called iPhreak. It supposedly generates DTMF tones to fool payphones (I Assure you this is not my intention - my company deals with telephone based Intercom systems). The only problem with that application is that there are files missing from the open source project. Perhaps someone else has gotten this project to work in the past?
If anyone has any idea on where I would look for something like this, I would be very appreciative with my votes :)
iphone generator dtmf
add a comment |
I am wondering if anyone has come across a way to generate tones in the iPhone SDK. I am trying to generate DTMF tones, and can't seem to find anything substantial out there. I want to be able to specify how long to play the tone for as well (i.e. to simulate holding the button down as opposed to just pressing it briefly..
I found an open source app called iPhreak. It supposedly generates DTMF tones to fool payphones (I Assure you this is not my intention - my company deals with telephone based Intercom systems). The only problem with that application is that there are files missing from the open source project. Perhaps someone else has gotten this project to work in the past?
If anyone has any idea on where I would look for something like this, I would be very appreciative with my votes :)
iphone generator dtmf
add a comment |
I am wondering if anyone has come across a way to generate tones in the iPhone SDK. I am trying to generate DTMF tones, and can't seem to find anything substantial out there. I want to be able to specify how long to play the tone for as well (i.e. to simulate holding the button down as opposed to just pressing it briefly..
I found an open source app called iPhreak. It supposedly generates DTMF tones to fool payphones (I Assure you this is not my intention - my company deals with telephone based Intercom systems). The only problem with that application is that there are files missing from the open source project. Perhaps someone else has gotten this project to work in the past?
If anyone has any idea on where I would look for something like this, I would be very appreciative with my votes :)
iphone generator dtmf
I am wondering if anyone has come across a way to generate tones in the iPhone SDK. I am trying to generate DTMF tones, and can't seem to find anything substantial out there. I want to be able to specify how long to play the tone for as well (i.e. to simulate holding the button down as opposed to just pressing it briefly..
I found an open source app called iPhreak. It supposedly generates DTMF tones to fool payphones (I Assure you this is not my intention - my company deals with telephone based Intercom systems). The only problem with that application is that there are files missing from the open source project. Perhaps someone else has gotten this project to work in the past?
If anyone has any idea on where I would look for something like this, I would be very appreciative with my votes :)
iphone generator dtmf
iphone generator dtmf
asked Sep 9 '09 at 12:51
Dutchie432
23.4k1883105
23.4k1883105
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
should be easy enough to generate yourself.
given that the hardware can playback a pcm buffer (16bit samples) at 44.1 khz (which it surely can with some library function or the other), you're only left with calculating the waveform:
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;
}
}
the 16383 is done since I'm using additive synthesis (just adding the sinewaves together). Therefore the max result is -2.0 - 2.0 So after multiplying by 16383 I get more or less the max 16 bit result: -32768 - +32767
EDIT:
the 2 frequenties are the frequenties from the wikipedia article the other person who answered linked to. Two unique frequencies make a DTMF sound
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
add a comment |
The easy answer is this:
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];
There you have it. All the sounds of a standard phone keypad, in an array, ready for your enjoyment.
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
1
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
|
show 6 more comments
Swift DTMF Sounds
I was experimenting with generating PCM data and came up with this in Swift. This function will generate an [Float] which are the audio samples. You can play them with AVAudio.
Each DTMF is comprised of a pair of tones, a mark length (250 ms), a space length (250 ms), and of course you need to specify a sample frequency (8000 Hz). Mark and Space are usually around 250 ms for what I would call standard human dialing. The sample frequency is fun to play with, but needs to be twice the highest frequency. For fun you can drop it below that to hear what happens.
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
}
The full Playground can be downloaded on GitHub.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1399501%2fgenerate-dtmf-tones%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
should be easy enough to generate yourself.
given that the hardware can playback a pcm buffer (16bit samples) at 44.1 khz (which it surely can with some library function or the other), you're only left with calculating the waveform:
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;
}
}
the 16383 is done since I'm using additive synthesis (just adding the sinewaves together). Therefore the max result is -2.0 - 2.0 So after multiplying by 16383 I get more or less the max 16 bit result: -32768 - +32767
EDIT:
the 2 frequenties are the frequenties from the wikipedia article the other person who answered linked to. Two unique frequencies make a DTMF sound
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
add a comment |
should be easy enough to generate yourself.
given that the hardware can playback a pcm buffer (16bit samples) at 44.1 khz (which it surely can with some library function or the other), you're only left with calculating the waveform:
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;
}
}
the 16383 is done since I'm using additive synthesis (just adding the sinewaves together). Therefore the max result is -2.0 - 2.0 So after multiplying by 16383 I get more or less the max 16 bit result: -32768 - +32767
EDIT:
the 2 frequenties are the frequenties from the wikipedia article the other person who answered linked to. Two unique frequencies make a DTMF sound
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
add a comment |
should be easy enough to generate yourself.
given that the hardware can playback a pcm buffer (16bit samples) at 44.1 khz (which it surely can with some library function or the other), you're only left with calculating the waveform:
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;
}
}
the 16383 is done since I'm using additive synthesis (just adding the sinewaves together). Therefore the max result is -2.0 - 2.0 So after multiplying by 16383 I get more or less the max 16 bit result: -32768 - +32767
EDIT:
the 2 frequenties are the frequenties from the wikipedia article the other person who answered linked to. Two unique frequencies make a DTMF sound
should be easy enough to generate yourself.
given that the hardware can playback a pcm buffer (16bit samples) at 44.1 khz (which it surely can with some library function or the other), you're only left with calculating the waveform:
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;
}
}
the 16383 is done since I'm using additive synthesis (just adding the sinewaves together). Therefore the max result is -2.0 - 2.0 So after multiplying by 16383 I get more or less the max 16 bit result: -32768 - +32767
EDIT:
the 2 frequenties are the frequenties from the wikipedia article the other person who answered linked to. Two unique frequencies make a DTMF sound
answered Sep 9 '09 at 14:05
Toad
10.1k1066119
10.1k1066119
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
add a comment |
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
Ok, maybe I am a bit behind the curve on this. Can you give me an example of how you would call that (for example for the #3)? I understand the freq's but don't really get the buffer concept.
– Dutchie432
Sep 9 '09 at 14:45
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
you create a buffer of sufficient length of a 16 bit signed datatype (I'm not sure how this is done in objective c). You then pick the 2 frequencies belonging to the dtmf tone of 3 (697hz and 1477hz). Call my function with a pointer to the buffer, the length you allocated and then the function will fill it with the waveform of the DTMF tone. This Waveform you'll then have to pass to the iPhone library function which can output the contents of a buffer to the audiohardware.
– Toad
Sep 9 '09 at 15:15
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
Note that the buffer is rendered with 44100 samples/seq. So when playing the waveform, the audio hardware should use the same frequenty or else the DTMF frequencies will be off. Also note, that if you want the waveform to last 10 seconds, then the buffer length should be PLAYBACKFREQ*10. I hope this explains it a bit. More info on PCM (the way a waveform is stored in computer memory) can be found here: en.wikipedia.org/wiki/Pulse-code_modulation
– Toad
Sep 9 '09 at 15:18
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
This does make sense now, although I still have no idea where to start... off to the Docs. Thanks very much.
– Dutchie432
Sep 9 '09 at 15:35
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
Reinier: I believe that w is 2pi*f/c so wouldn't sin part of formula be sin(i*(PI2*(freq1/PLAYBACKFREQ))?
– user180730
Sep 28 '09 at 21:14
add a comment |
The easy answer is this:
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];
There you have it. All the sounds of a standard phone keypad, in an array, ready for your enjoyment.
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
1
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
|
show 6 more comments
The easy answer is this:
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];
There you have it. All the sounds of a standard phone keypad, in an array, ready for your enjoyment.
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
1
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
|
show 6 more comments
The easy answer is this:
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];
There you have it. All the sounds of a standard phone keypad, in an array, ready for your enjoyment.
The easy answer is this:
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];
There you have it. All the sounds of a standard phone keypad, in an array, ready for your enjoyment.
edited Oct 18 '10 at 9:08
answered Oct 13 '09 at 4:03
mahboudz
34.1k1688120
34.1k1688120
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
1
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
|
show 6 more comments
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
1
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
I am hoping to generate the tones programatically... so i can play them for any amount of time. this may be a good fallback if I can't get it working right.
– Dutchie432
Oct 13 '09 at 11:11
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
You can loop these, with varying amounts of work depending on how you chose to play them. Of course, they really are two pure sine waves, and easy to create. However, you still have to create them in some finite length and pass them to a sound player, in which case you'd have to loop those too once the sound player run out of data. Either way, you may have to do the extra work of looping.
– mahboudz
Oct 13 '09 at 17:48
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Will this get you rejected from the App store?
– NateS
Aug 1 '10 at 20:00
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
Technically, you are not using any prohibited or private APIs. Also, you didn't have to do anything tricky to get outside of your sandbox. I'd use it as is, and if there is a problem, then go ahead and copy those files into your Bundle and distribute with your app. It won't be a huge hit if you got rejected and had to use that as your plan B.
– mahboudz
Aug 3 '10 at 19:38
1
1
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
This example has memory leaks. Don't post code with obvious memory leaks.
– rpetrich
Oct 16 '10 at 22:18
|
show 6 more comments
Swift DTMF Sounds
I was experimenting with generating PCM data and came up with this in Swift. This function will generate an [Float] which are the audio samples. You can play them with AVAudio.
Each DTMF is comprised of a pair of tones, a mark length (250 ms), a space length (250 ms), and of course you need to specify a sample frequency (8000 Hz). Mark and Space are usually around 250 ms for what I would call standard human dialing. The sample frequency is fun to play with, but needs to be twice the highest frequency. For fun you can drop it below that to hear what happens.
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
}
The full Playground can be downloaded on GitHub.
add a comment |
Swift DTMF Sounds
I was experimenting with generating PCM data and came up with this in Swift. This function will generate an [Float] which are the audio samples. You can play them with AVAudio.
Each DTMF is comprised of a pair of tones, a mark length (250 ms), a space length (250 ms), and of course you need to specify a sample frequency (8000 Hz). Mark and Space are usually around 250 ms for what I would call standard human dialing. The sample frequency is fun to play with, but needs to be twice the highest frequency. For fun you can drop it below that to hear what happens.
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
}
The full Playground can be downloaded on GitHub.
add a comment |
Swift DTMF Sounds
I was experimenting with generating PCM data and came up with this in Swift. This function will generate an [Float] which are the audio samples. You can play them with AVAudio.
Each DTMF is comprised of a pair of tones, a mark length (250 ms), a space length (250 ms), and of course you need to specify a sample frequency (8000 Hz). Mark and Space are usually around 250 ms for what I would call standard human dialing. The sample frequency is fun to play with, but needs to be twice the highest frequency. For fun you can drop it below that to hear what happens.
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
}
The full Playground can be downloaded on GitHub.
Swift DTMF Sounds
I was experimenting with generating PCM data and came up with this in Swift. This function will generate an [Float] which are the audio samples. You can play them with AVAudio.
Each DTMF is comprised of a pair of tones, a mark length (250 ms), a space length (250 ms), and of course you need to specify a sample frequency (8000 Hz). Mark and Space are usually around 250 ms for what I would call standard human dialing. The sample frequency is fun to play with, but needs to be twice the highest frequency. For fun you can drop it below that to hear what happens.
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
}
The full Playground can be downloaded on GitHub.
edited Apr 30 '16 at 20:43
answered Apr 30 '16 at 20:37
Cameron Lowell Palmer
14.4k47796
14.4k47796
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1399501%2fgenerate-dtmf-tones%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown