PDA

View Full Version : how to make a frequency generator?


wootbean
11-24-2009, 12:01 PM
I found an app called "FreqGen" that's a frequency generator, I'm wondering if anybody here knows if there are any audio APIs or something along those lines that can be used to make one? Basically how do you generate a continuous tone and how can you vary the frequency of the tone?

mobile1up
11-26-2009, 12:27 AM
I found an app called "FreqGen" that's a frequency generator, I'm wondering if anybody here knows if there are any audio APIs or something along those lines that can be used to make one? Basically how do you generate a continuous tone and how can you vary the frequency of the tone?

you need to roll your own wave generator. its not that difficult to do - google for "PCM tone generation" - as you can see in the application, there are many ways, square wave, sine wave, saw wave.. you programmatically adjust the PCM output for this. no API that i am aware of exists for this - but it isn't hard to write up.


... (initialization) ...

g_pcm_sfx -> tonegen.min = 0;
g_pcm_sfx -> tonegen.max = 0;
g_pcm_sfx -> tonegen.cycle = 1;
g_pcm_sfx -> tonegen.index = 0;
g_pcm_sfx -> tonegen.count = 0;
g_pcm_sfx -> tonegen.state = false;

... (tone configuration) ...

g_pcm_sfx -> tonegen.index = 0;
g_pcm_sfx -> tonegen.count = ((cyc_freq * duration) / 1000);
g_pcm_sfx -> tonegen.cycle = (int16)(min_freq / freq);

val_s = (int16)((32767L*volume*volume)/10000L);
g_pcm_sfx -> tonegen.max = (int16) val_s;
g_pcm_sfx -> tonegen.min = (int16)-val_s;

... (audio call back) ...

// simple square wave, write value
valu = (g_pcm_sfx -> tonegen.state)
? g_pcm_sfx -> tonegen.max : g_pcm_sfx -> tonegen.min;


piece of cake :) - this is c+p from our code base for doing this. we dont use tone generation often tho; because you can get better sampled audio.