aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md49
1 files changed, 49 insertions, 0 deletions
diff --git a/README.md b/README.md
index 071659e05..395b4a552 100644
--- a/README.md
+++ b/README.md
@@ -377,6 +377,55 @@ You can currently send 4 hex digits with your OS-specific modifier key (RALT for
377 377
378Enable the backlight from the Makefile. 378Enable the backlight from the Makefile.
379 379
380## Driving a speaker - audio support
381
382Your keyboard can make sounds! If you've got a Planck, Preonic, or basically any keyboard that allows access to the C6 port, you can hook up a simple speaker and have it beep. You can use those beeps to indicate layer transitions, modifiers, special keys, or just to play some funky 8bit tunes.
383
384The audio code lives in [quantum/audio/audio.h](/quantum/audio/audio.h) and in the other files in the audio directory. It's enabled by default on the Planck [stock keymap](/keyboard/planck/keymaps/default/keymap.c). Here are the important bits:
385
386```
387#include "audio.h"
388```
389
390Then, lower down the file:
391
392```
393float tone_startup[][2] = {
394 ED_NOTE(_E7 ),
395 E__NOTE(_CS7),
396 E__NOTE(_E6 ),
397 E__NOTE(_A6 ),
398 M__NOTE(_CS7, 20)
399};
400```
401
402This is how you write a song. Each of these lines is a note, so we have a little ditty composed of five notes here.
403
404Then, we have this chunk:
405
406```
407float tone_qwerty[][2] = SONG(QWERTY_SOUND);
408float tone_dvorak[][2] = SONG(DVORAK_SOUND);
409float tone_colemak[][2] = SONG(COLEMAK_SOUND);
410float tone_plover[][2] = SONG(PLOVER_SOUND);
411float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
412
413float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
414float goodbye[][2] = SONG(GOODBYE_SOUND);
415```
416
417Wherein we bind predefined songs (from [audio/song_list.h](/audio/song_list.h)) into named variables. This is one optimization that helps save on memory: These songs only take up memory when you reference them in your keymap, because they're essentially all preprocessor directives.
418
419So now you have something called `tone_plover` for example. How do you make it play the Plover tune, then? If you look further down the keymap, you'll see this:
420
421```
422PLAY_NOTE_ARRAY(tone_plover, false, 0); // Signature is: Song name, repeat, rest style
423```
424
425This is inside one of the macros. So when that macro executes, your keyboard plays that particular chime.
426
427"Rest style" in the method signature above (the last parameter) specifies if there's a rest (a moment of silence) between the notes.
428
380## MIDI functionalty 429## MIDI functionalty
381 430
382This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile. 431This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.