|
Rockbox mail archiveSubject: My first patch [to use halftones for pitch shifting]My first patch [to use halftones for pitch shifting]
From: Alessandro Polselli <alessandro.polselli_at_gmail.com>
Date: Sat, 9 Sep 2006 02:13:37 +0200 Hi! My name is Alessandro. I've discovered rockbox only a couple of days ago, but I loved it so much that I've soon built up a cross-compiling environment on my Mac and started playing with the source.. ..and now I've just completed my first nicely-working patch :) This patch adds a little feature to the pitch menu, by enabling to use of halftone values instead of just percentage ones for pitch shifting. It should be useful to a musician to transpose a song into a different key to play along with it.. I set the PLAY/PAUSE button on my iPod mini to switch between percentage and halftones pitch shifting, by adding a new ACTION_PS_PLAY keymap row and by coding a little logic for inc/dec the pitch in this new way, with the same gestures as before, when in the "halftones" mode. I wrote and tested the code only on my iPod mini, but it should be quickly portable -by adding a similar keymap row- to all other players. I hope you'll like it. Bye, Alessandro. *** That's the patch code: Index: apps/action.h =================================================================== RCS file: /cvsroot/rockbox/apps/action.h,v retrieving revision 1.12 diff -u -r1.12 action.h --- apps/action.h 22 Aug 2006 13:21:13 -0000 1.12 +++ apps/action.h 8 Sep 2006 23:34:58 -0000 _at__at_ -173,6 +173,7 _at__at_ ACTION_PS_NUDGE_LEFTOFF, ACTION_PS_NUDGE_RIGHTOFF, ACTION_PS_RESET, + ACTION_PS_PLAY, ACTION_PS_EXIT, /* _STD_* isnt going to work here */ /* yesno screen */ Index: apps/screens.c =================================================================== RCS file: /cvsroot/rockbox/apps/screens.c,v retrieving revision 1.169 diff -u -r1.169 screens.c --- apps/screens.c 3 Sep 2006 11:35:24 -0000 1.169 +++ apps/screens.c 8 Sep 2006 23:35:03 -0000 _at__at_ -356,7 +356,7 _at__at_ 0 if no key was pressed 1 if USB was connected */ -void pitch_screen_draw(struct screen *display, int pitch) +void pitch_screen_draw(struct screen *display, int pitch, bool tones, int halftones) { unsigned char* ptr; unsigned char buf[32]; _at__at_ -375,14 +375,16 _at__at_ { /* UP: Pitch Up */ - ptr = str(LANG_SYSFONT_PITCH_UP); + if(tones) ptr = "1/2 Tone Up"; + else ptr = str(LANG_SYSFONT_PITCH_UP); display->getstringsize(ptr,&w,&h); display->putsxy((display->width-w)/2, 0, ptr); display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow], display->width/2 - 3, h, 7, 8); /* DOWN: Pitch Down */ - ptr = str(LANG_SYSFONT_PITCH_DOWN); + if(tones) ptr = "1/2 Tone Down"; + else ptr = str(LANG_SYSFONT_PITCH_DOWN); display->getstringsize(ptr,&w,&h); display->putsxy((display->width-w)/2, display->height - h, ptr); display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], _at__at_ -401,25 +403,86 _at__at_ display->putsxy(0, (display->height-h)/2, ptr); display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], w+1, (display->height-h)/2, 7, 8); - - /* "Pitch" */ - snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH)); - display->getstringsize(buf,&w,&h); - display->putsxy((display->width-w)/2, (display->height/2)-h, buf); - /* "XX.X%" */ - snprintf((char *)buf, sizeof(buf), "%d.%d%%", - pitch / 10, pitch % 10 ); - display->getstringsize(buf,&w,&h); - display->putsxy((display->width-w)/2, display->height/2, buf); + + if(!tones){ + /* "Pitch" */ + snprintf((char *)buf, sizeof(buf), str (LANG_SYSFONT_PITCH)); + display->getstringsize(buf,&w,&h); + display->putsxy((display->width-w)/2, (display->height/ 2)-h, buf); + /* "XX.X%" */ + snprintf((char *)buf, sizeof(buf), "%d.%d%%", + pitch / 10, pitch % 10 ); + display->getstringsize(buf,&w,&h); + display->putsxy((display->width-w)/2, display->height/2, buf); + } + else { + /* "Tones" */ + snprintf((char *)buf, sizeof(buf), "Halftones"); + display->getstringsize(buf,&w,&h); + display->putsxy((display->width-w)/2, (display->height/ 2)-h, buf); + /* "XX.X%" */ + if(halftones >= 0) snprintf((char *)buf, sizeof(buf), "+% d", + halftones ); + else snprintf((char *)buf, sizeof(buf), "%d", + halftones ); + display->getstringsize(buf,&w,&h); + display->putsxy((display->width-w)/2, display->height/2, buf); + } + } display->update(); } +int set_pitch_with_halftones(int halftones){ + int pitch; + switch (halftones) { + case 0: + pitch = 1000; + sound_set_pitch(pitch); + break; + case 1: + pitch = 1060; + sound_set_pitch(pitch); + break; + case 2: + pitch = 1122; + sound_set_pitch(pitch); + break; + case 3: + pitch = 1189; + sound_set_pitch(pitch); + break; + case 4: + pitch = 1260; + sound_set_pitch(pitch); + break; + case -4: + pitch = 794; + sound_set_pitch(pitch); + break; + case -3: + pitch = 841; + sound_set_pitch(pitch); + break; + case -2: + pitch = 891; + sound_set_pitch(pitch); + break; + case -1: + pitch = 944; + sound_set_pitch(pitch); + break; + } + return pitch; +} + bool pitch_screen(void) { int button; int pitch = sound_get_pitch(); + int halftones = 0; + bool tones = false; bool exit = false; int i; _at__at_ -431,17 +494,24 _at__at_ while (!exit) { FOR_NB_SCREENS(i) - pitch_screen_draw(&screens[i],pitch); + pitch_screen_draw(&screens[i],pitch,tones,halftones); button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK); switch (button) { case ACTION_PS_INC_SMALL: - if ( pitch < 2000 ) + if(tones){ + if(halftones < 4) halftones++; + pitch = set_pitch_with_halftones(halftones); + } + else { + if ( pitch < 2000 ) pitch++; - sound_set_pitch(pitch); + sound_set_pitch(pitch); + } break; case ACTION_PS_INC_BIG: + tones = false; if ( pitch < 1990 ) pitch += 10; else _at__at_ -450,12 +520,19 _at__at_ break; case ACTION_PS_DEC_SMALL: - if ( pitch > 500 ) - pitch--; - sound_set_pitch(pitch); + if(tones){ + if(halftones > -4) halftones--; + pitch = set_pitch_with_halftones(halftones); + } + else { + if ( pitch > 500 ) + pitch--; + sound_set_pitch(pitch); + } break; case ACTION_PS_DEC_BIG: + tones = false; if ( pitch > 510 ) pitch -= 10; else _at__at_ -464,36 +541,49 _at__at_ break; case ACTION_PS_NUDGE_RIGHT: + tones = false; if ( pitch < 1980 ) { - pitch += 20; + pitch +=20; sound_set_pitch(pitch); FOR_NB_SCREENS(i) - pitch_screen_draw(&screens[i],pitch); + pitch_screen_draw(&screens [i],pitch,tones,halftones); } break; case ACTION_PS_NUDGE_RIGHTOFF: + tones = false; pitch -= 20; sound_set_pitch(pitch); break; case ACTION_PS_NUDGE_LEFT: + tones = false; if ( pitch > 520 ) { - pitch -= 20; + pitch -=20; sound_set_pitch(pitch); FOR_NB_SCREENS(i) - pitch_screen_draw(&screens[i],pitch); + pitch_screen_draw(&screens [i],pitch,tones,halftones); } break; case ACTION_PS_NUDGE_LEFTOFF: + tones = false; pitch += 20; sound_set_pitch(pitch); break; + case ACTION_PS_PLAY: + if(!tones) { + tones = true; + halftones = 0; + pitch = set_pitch_with_halftones(halftones); + } + else tones = false; + break; + case ACTION_PS_RESET: - pitch = 1000; - sound_set_pitch( pitch ); + tones = false; + pitch = set_pitch_with_halftones(0); break; case ACTION_PS_EXIT: Index: apps/keymaps/keymap-ipod.c =================================================================== RCS file: /cvsroot/rockbox/apps/keymaps/keymap-ipod.c,v retrieving revision 1.11 diff -u -r1.11 keymap-ipod.c --- apps/keymaps/keymap-ipod.c 23 Aug 2006 08:53:38 -0000 1.11 +++ apps/keymaps/keymap-ipod.c 8 Sep 2006 23:35:05 -0000 _at__at_ -144,6 +144,7 _at__at_ { ACTION_PS_NUDGE_RIGHTOFF, BUTTON_RIGHT|BUTTON_REL, BUTTON_NONE }, { ACTION_PS_RESET, BUTTON_MENU, BUTTON_NONE }, { ACTION_PS_EXIT, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_PS_PLAY, BUTTON_PLAY, BUTTON_NONE }, LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) }; /* button_context_pitchscreen */ Received on 2006-09-09 Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy |