The sound API of gamebuino library incorporates a mechanism like Amiga mod and it is made not to consume much memory.
Even though I saw an official forum etc, though speculation has fluttered and references are not prepared, it is hard to use, so I can not see examples that I am using very often Sound API, reflecting the result of examining the bit composition by reading the code . There may still be mistakes, continue to investigate.
HISTORY
Macro correction 11.07.17
pattern
Pattern set
truck
Assemble songs using these three.
The pattern is equivalent to one bar of a part in musical score. The length is free.
It is easy to understand that the pattern set is for attaching an ID to an existing pattern.
It is for arranging the songs by arranging the pattern IDs registered in the pattern set.
Although it is a maximum of 4 sounds, in the initial state, no matter what it does, only 1 sound comes out.
It is in game.buino library setting.c
#define NUM_CHANNELS 1
If you edit this number with 0 ~ 4, you can get up to 4 sounds.
As a preliminary knowledge, it is a trade-off with processing speed because it is heavy work to emit sound with the MCU.
Let's make a series of codes that actually sounds using patterns, pattern sets, and tracks.
Here we will use two channels to try out the sound.
A useful macro before that.
#define NOTE(pitch, duration) ((uint16_t)duration << 8) + ((uint16_t)pitch << 2)
#define PAUSE(duration) NOTE(63, duration)
#define END() 0x0000
#define EFFECT(cmd,x,y) ((0x0F & cmd)<<2)|((0x1f & x)<<6)|((0x1f & y)<<11)| 1
enum NOTE
{
_Bb2, _B2, _C3, _Db3, _D3, _Eb3, _E3, _F3, _Gb3, _G3, _Ab3, _A3,
_Bb3, _B3, _C4, _Db4, _D4, _Eb4, _E4, _F4, _Gb4, _G4, _Ab4, _A4,
_Bb4, _B4, _C5, _Db5, _D5, _Eb5, _E5, _F5, _Gb5, _G5, _Ab5, _A5,
_Bb5, _B5, _C6, _Db6, _D6, _Eb6, _E6, _F6, _Gb6, _G6, _Ab6, _A6,
_Bb6, _B6, _C7, _Db7, _D7, _Eb7, _E7, _F7, _Gb7, _G7, _Ab7, _A7,
_Bb7, _B7, _OFF
};
This is a super cheap code that I saw in the game post on the gamebuino forum and it is supplemented with a macro of effect. Let's play sound using this.
※ Originally handled semitones flat. Sharp is easier to understand if I say something. I think that this is perfectly a matter of taste, but I will fix everything so that people using it are easy to use. Because it is only the question of notation.
The effect is
/ *
EFFECT
0: setVolume x: 0 to 9
1: Instrument x: 0 = square wave 1 = noise
2: Volume Slide x: step duration y: step depth
3: Arpeggio x: step duration y: step depth
4: Tremolo x: step duration y: step depth
* /
Such content.
y can handle minus. However, because it is sign + 4 bit, it can not be written in the usual way of writing.
Of the 5 bits, MSB is a sign flag, so if you want to handle minus, add 0x10. It seems to be mainly used for volume slide and Arpeggio.
Patterns first. PAUSE is the treatment of rests.
const uint16_t pt1[] PROGMEM = {
EFFECT(0,8,0),EFFECT(4,1,2),
NOTE(_C4,4),
NOTE(_D4,4),
NOTE(_E4,3),PAUSE(1),
NOTE(_D4,4),
NOTE(_E4,4),
NOTE(_F4,3),PAUSE(1),
END()
};
const uint16_t pt2[] PROGMEM ={
EFFECT(0,5,0),EFFECT(4,1,7),
NOTE(_E5,4),
NOTE(_F5,4),
NOTE(_G5,4),
NOTE(_F5,4),
NOTE(_G5,4),
NOTE(_A5,4),
END()
};
Next, the pattern set
const uint16_t* const ps[] PROGMEM={pt1,pt2};
Register pt 1 and pt 2 that registered patterns, which will appear as IDs 0, 1 from Track.
And the important track
const uint16_t t1[] PROGMEM ={0,1,0xFFFF};
const uint16_t t2[] PROGMEM ={1,0,0xFFFF};
Pattern set 0 and 1 are sounded and 0xFFFF is terminated.
I also made t 2 that sounds in the opposite pattern.
Here is the code to really sound this in practice.
gb.sound.changePatternSet(ps,0); //ch1 patternset
gb.sound.changePatternSet(ps,1); //ch2 patternset
gb.sound.playTrack(t2, 0); //play channel 1
gb.sound.playTrack(t1, 1); //play channel 2
Register the pattern set in each channel, and play the track. Flow.
When it actually sounds, a sound (feels good) comes out that it is a difference of clouds from the time of a single note. I am a little happy.
About duration.
Not limited to the gamebuino library, the tracker is made with vertical sync set to 1, and how many times to synchronize as duration (sound length). There is no idea like 16-part notes that is easy to understand.
In the case of gamebuino, how many times update will come, it becomes a way of thinking.
The length is determined by 2 ^ n with reference to the shortest sound and how long it sounds.
For example, if the shortest note is treated as a sixteenth note as duration 2,
8 minutes = 4
4 minutes = 8
2 minutes = 16
All note = 32
The duration is determined.
It may be a good idea to write a macro as this is troublesome.
From now on, matters under investigation
About bit composition of pattern.
0000 0000 0000 000x
Effect when x is 1, note otherwise. If it is all zero pattern end.
Bit configuration of effect
YYYY Y XXX XX CC CC 01
C = cmd
X = X
Y = Y (msb is like sign flag)
I wish I could read the code more firmly from the beginning.
Bit configuration of note
DDDD DDDD NNNN NN 00
N = NOTE
D = Duration