Rockbox Development > Starting Development and Compiling
Outputting a fixed tone
(1/1)
mikeage:
Hi,
I'm not sure if this is the right place; is there a forum (besides for IRC) for development questions?
I'm working on my first plugin; a morse output for Rockbox (currently reading text files). However, I'm having some trouble with the actual tones.
Is there any way I can generate a tone in code? The examples I saw, such as metronome and rockdoom rely on loading precomputed MP3 frame(s) or raw PCM data and playing that. I'd like to be able to configure the frequency (and duration) at runtime. Is there any way to do this?
Alternatively, how exactly can I translate raw audio data (that I've created in Audacity, for example) to an array for use as either an MP3 frame or PCM data?
Thanks
saratoga:
--- Quote ---Is there any way I can generate a tone in code? The examples I saw, such as metronome and rockdoom rely on loading precomputed MP3 frame(s) or raw PCM data and playing that. I'd like to be able to configure the frequency (and duration) at runtime. Is there any way to do this?
--- End quote ---
--- Code: ---int freq=1000;
digital_freq = freq/44100;
int num_samp = duration*44100;
unsigned short buf[num_samp];
for (i=0; i
mikeage:
Thanks for the quick answer!
Can this be used on targets using HW codecs?
I noticed that metronome uses a buffer like this (converted to interleaved stereo) and the pcm_play_data function for targets that are SWCODEC, and mp3_play_data for !SWCODEC targets?
Is the only difference (in metronome) the memory required?
Edit: Never mind, I see these functions are only defined for SWCODEC.
And just to clarify:
You wrote:
--- Code: ---cos(1000*6*i)
--- End code ---
Shouldn't that be
--- Code: ---cos(Freq * 2 * PI * i)?
--- End code ---
saratoga:
I don't know how the rockbox sin functions handle floats, so I assumed you would want to use all ints. 6 is close enough to 2*PI that you probably wouldn't care what the difference is. If there is a fixed point or fp emulated cos function, then 2*PI would be correct.
safetydan:
There is a actually a fixed point fsincos function available to plugins. It's the same one that's used by the equalizer so it's reasonably accurate for audio work. Not sure if it's fast enough for real-time tone generation, but you could always use a precomputed table.
Anyway, to use the function in your plugin you'll need to include "fixedpoint.h".
Navigation
[0] Message Index
Go to full version