Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Outputting a fixed tone
« previous next »
  • Print
Pages: [1]

Author Topic: Outputting a fixed tone  (Read 1768 times)

Offline mikeage

  • Member
  • *
  • Posts: 110
    • mikeage.net
Outputting a fixed tone
« on: April 05, 2007, 11:52:50 AM »
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
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8974
Re: Outputting a fixed tone
« Reply #1 on: April 05, 2007, 12:03:36 PM »
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?

Code: [Select]
int freq=1000;
digital_freq = freq/44100;
int num_samp = duration*44100;
unsigned short buf[num_samp];
for (i=0; ibuf[i]= cos(digital_freq*6*i);
}

//pass buf to audio driver

I don't know where you'd find the cos function.  The calculator has one, there might be a faster one you could use somewhere else.  

Edit:  Wow can't believe I did that formula wrong.  You need to normalize your frequency by teh sampling frequency or it won't work!
« Last Edit: April 05, 2007, 02:33:48 PM by saratoga »
Logged

Offline mikeage

  • Member
  • *
  • Posts: 110
    • mikeage.net
Re: Outputting a fixed tone
« Reply #2 on: April 05, 2007, 12:12:22 PM »
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: [Select]
cos(1000*6*i)

Shouldn't that be
Code: [Select]
cos(Freq * 2 * PI * i)?
« Last Edit: April 05, 2007, 12:41:00 PM by mikeage »
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8974
Re: Outputting a fixed tone
« Reply #3 on: April 05, 2007, 01:08:09 PM »
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.
Logged

Offline safetydan

  • Developer
  • Member
  • *
  • Posts: 248
Re: Outputting a fixed tone
« Reply #4 on: April 05, 2007, 06:32:08 PM »
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".
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Outputting a fixed tone
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.073 seconds with 15 queries.