Rockbox

This is the bug/patch tracker for Rockbox. Click here for more information.

Quick links: Bugs · Patches · Rockbox frontpage

Tasklist

FS#8768 - Instrument tuner plugin

Attached to Project: Rockbox
Opened by Lechner Michael (smoking_gnu) - Thursday, 20 March 2008, 20:40 GMT+1
Task Type Patches
Category Applications
Status Unconfirmed
Assigned To No-one
Player type SW-codec
Severity Low
Priority Normal
Reported Version current build
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Private No

Details

This plugin is an instrument tuner.
Currently, there's no real GUI, it just prints the note you're playing again and again until you press power.

Here's the c file:
   pitch.c (6.3 KiB)
This task depends upon

Comment by Lechner Michael (smoking_gnu) - Thursday, 20 March 2008, 21:52 GMT+1
OK, Now I've cleaned up the code a little bit.
Should be more readable now; no functional changes.
   pitch.c (9.2 KiB)
Comment by Linus Nielsen Feltzing (linusnielsen) - Friday, 21 March 2008, 17:02 GMT+1
Looks nice and simple. However, it violates quite a few of our coding guidelines, so it needs some more cleaning.
Furthermore, it uses quite a lot of floating point arithmetics, which we aren't too fond of. But I think we can let that pass, since it's only a plugin.

Good work!
Comment by Lechner Michael (smoking_gnu) - Friday, 21 March 2008, 19:19 GMT+1
Which coding guidelines does it violate?
Comment by Linus Nielsen Feltzing (linusnielsen) - Friday, 21 March 2008, 19:41 GMT+1
It mainly violates the guidelines regarding identifiers. From docs/CONTRIBUTING:

Identifiers
-----
We do not want mixed case identifiers.
Variables and function names should be all lower case.
Struct and enum names should be all lower case.
Preprocessor symbols and enum constants should be all upper case.

Comment by Lechner Michael (smoking_gnu) - Friday, 21 March 2008, 20:58 GMT+1
New version that does not violate any coding guidelines:

   pitch.c (9.3 KiB)
Comment by Nils Wallménius (nls) - Saturday, 22 March 2008, 15:25 GMT+1
Really nice, many people will love this :)

Another nitpick from CONTRIBUTING though,

"Keep lines below 80 columns length."
Comment by Lechner Michael (smoking_gnu) - Saturday, 22 March 2008, 22:56 GMT+1
OK, if this version violates the coding guidelines again, I'll start crying.
   pitch.c (9.1 KiB)
Comment by Linus Nielsen Feltzing (linusnielsen) - Sunday, 23 March 2008, 11:26 GMT+1
Better start crying then... :-)

schmittTriggered=0;

:-)
Comment by Lechner Michael (smoking_gnu) - Sunday, 23 March 2008, 22:44 GMT+1
*cry*

Well, I added a little bar that shows how 'wrong' your pitch is.
I also corrected that guideline violation, and if I find another one, I'll simply give up ;)

If the played note is loud enough, the tuner is now quite usable.
I'd be very grateful if someone actually tried my plugin and tell me any bugs/suggestions...

   pitch.c (10.3 KiB)
Comment by Lechner Michael (smoking_gnu) - Sunday, 23 March 2008, 23:30 GMT+1
Desowin tried it for me on his e200, and for some unexplainable reason it didn't even start recording !?!
Could anyone else with an player with a built-in mic try this for me?
Comment by Michael Sevakis (MikeS) - Monday, 24 March 2008, 06:14 GMT+1
This really needs to have recording used as the example plugins and core use it so that it operates with a periodic callback (ie. not constantly stopping and restarting recording). There's not much room to vary from those formulas and expect it to operate properly. No parts are optional.

The sample buffer should be 32-bit aligned BTW.
Comment by Lechner Michael (smoking_gnu) - Monday, 24 March 2008, 22:06 GMT+1
I tried a periodic callback that provides a new buffer for recording, but even after several days I couldn't get it to work properly: it always crashed after 0-10 seconds with some buffer overflow error, no matter how much buffer I gave it... It didn't help that there's no documentation at all, and the few plugins that use it are so complicated that I don't understand what I have to do...

32-bit aligned would be a signed int, right?

Also, the reason for the plugin not working on sansas has to do with the fact that they cannot record with a 44,1K sample rate - I'm working on it.
Comment by Linus Nielsen Feltzing (linusnielsen) - Tuesday, 25 March 2008, 10:02 GMT+1
I made an intrument tuner myself using the "proper" method of recording. I'll see if I can apply my recording code to your pitch detection algorithm.
Comment by Lechner Michael (smoking_gnu) - Tuesday, 25 March 2008, 20:01 GMT+1
Surely, why not?
Comment by Lechner Michael (smoking_gnu) - Friday, 04 April 2008, 19:42 GMT+1
New version, much better gui. Still doesn't work on Sansas though..
   pitch.c (15.5 KiB)
Comment by Steve Tucker (stevetuc) - Saturday, 05 April 2008, 20:31 GMT+1
I uncommented
print_int_xy(0,160,(int) *rb->rec_freq_sampr);
print_int_xy(0,200,(int) SAMPLE_RATE);

and both are reported as 22050 on the sansa e280 not 88200 as mentioned in the comments?
Comment by Lechner Michael (smoking_gnu) - Saturday, 05 April 2008, 21:50 GMT+1
Really? I could only test this in the simulator since I don't own a sansa...
Does the actual tuning work too? Does the GUI display correctly on the sansa's screen?

@MikeS: The sample buffer is now 32-bit aligned -> int32_t.
Comment by Steve Tucker (stevetuc) - Sunday, 06 April 2008, 00:35 GMT+1
The tuning doesnt work on the sansa - but its not down to the samplerate
The GUI does display correctly - and looks good
Comment by Lechner Michael (smoking_gnu) - Sunday, 06 April 2008, 14:25 GMT+1
Strange... Could you put a "rb->splash(0, "callback!");" into recording_callback() for testing purposes?
If recording works, it should display "callback" every second or so. If not, recording does not work at all.
Comment by Steve Tucker (stevetuc) - Sunday, 06 April 2008, 15:49 GMT+1
The callbacks are working- the splash pops up every sec or so
Comment by Steve Tucker (stevetuc) - Sunday, 06 April 2008, 22:13 GMT+1
some observations 9on the sansa):
tc is always 0 hence freq is 0

If I exit pitch and go to recording, the mic is not responsive. If I then exit
recording and restart it, the mic responds.

This suggests something in the code is preventing the mc responding to input

Comment by Lechner Michael (smoking_gnu) - Sunday, 06 April 2008, 22:32 GMT+1
My main problem is that there's no documentation at all, nowhere!
There are some plugins that use recording, but they just use some functions and do not explain what they do exactly...
I know for sure that I'm doing several things wrong, but nobody actually helps me fixing those problems.
So until I get some more information, I'm afraid I can't help you.
It seems to be working on most targets, and I don't own a sansa to "reverse engineer" the recording api.
Thanks for testing it nevertheless!
Comment by Linus Nielsen Feltzing (linusnielsen) - Tuesday, 08 April 2008, 08:43 GMT+1
I know I promised to help you with the recording code, I just haven't had time yet. Sorry about that. Regarding the documentation, it's a sad fact that we lack plenty of documentation on the Rockbox internals. We try to keep up as weel as we can, but it is hard enough to find the time for the coding itself, and the documentation always has lower priority.
Comment by Steve Tucker (stevetuc) - Tuesday, 08 April 2008, 19:57 GMT+1
I got recording working on the sansa by changing the gain values from 100 to 39 (the range is given in as3514.c as 0 to 39 with 23 default)

rb->sound_set(SOUND_MIC_GAIN, 39);
rb->audio_set_recording_gain(39,39, AUDIO_GAIN_MIC);

Im not convinced that the sound_set()ine is actually doing anything. I think the gain
is being set by the audio_set_recording_gain()

recording now works although the pitch indication jumps around a bit. maybe some averaging would help.
Comment by Lechner Michael (smoking_gnu) - Wednesday, 09 April 2008, 15:48 GMT+1
Good to hear! I only added sound_set() because some other plugin used it...
I can't work on the plugin right now because cygwin doesn't work anymore and I can't get the toolchain installed on AndLinux.
The 'jumpiness' of the tuner is due to the fact that the Schmitt trigger algorithm only works reliably when the tone is quite loud.
So if you play a loud note, it shouldn't jump so much. I intend to fix that when I can compile again.
Comment by Rani Hod (RaeNye) - Sunday, 13 April 2008, 00:58 GMT+1
Tested on iaudio X5.
Detection doesn't work too well using built-in microphone though;
[either that or my guitar is way off-tune ;-) ]
Comment by Steve Tucker (stevetuc) - Monday, 14 April 2008, 19:06 GMT+1
here is a version that works with sansa

I have removed rb->sound_set(SOUND_MIC_GAIN, 39);

gain is set at 39 instead of 100 as per as3514.c
rb->audio_set_recording_gain(39,39, AUDIO_GAIN_MIC);

I added some code in display_freq() that prevents the red bar set at -32 cents when freq=0 (no signal)

if ((int)freq == 0) /* prevents red bar at -32 cents when freq= 0*/
{ ldf = 0;
}


   pitch.c (15.8 KiB)
Comment by howard (howardh) - Friday, 15 August 2008, 09:24 GMT+1
It wouldn't compile unless I change line 500 to

enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
Comment by Jason Lyons (bipton) - Saturday, 30 August 2008, 05:54 GMT+1
I added and changed a couple things to get this to compile for my iHP-120, it has a grayscale lcd. Hope I didn't mess anything up.
   pitch.c (16.7 KiB)

Loading...