svenman wrote:Also, pope. Decree: Tell us a piece of music you'd like to be covered on the balthawavegenerator.
No.
But, if you want some music to be played by this you can do it yourself.
How?
Download this:
- ui.zip
- (27.37 KiB) Downloaded 250 times
Don't worry, you don't need to know about programming to do this.
You only need to understand notes.
The file you need is sheet.h
In the file you will see things like this
Code: Select all
const unsigned short sheet0 [] = {
//something
};
const unsigned short sheet1 [] = {
//something
};
const unsigned short sheet2 [] = {
//something
};
const unsigned short sheet3 [] = {
//something
};
Theses are the "sheets" which contain the notes for the 4 channels of the sound generator.
You put notes in it, like this:
Code: Select all
const unsigned short sheet0 [] = {
note1,
note2,
note3,
//...and so on..
STPP
};
One note in each line, ending with a comma ( , ).
at the end there should be a "STPP" (without coma) - it tells the sound generator that it's the end of the sheet.
But how to write a note?
each note needs its length and pitch.
So a note can be written like this:
How to select the length?
These are the available lengths: T16, T8, T4, T2, T1, N16, N8, N4, N2, N1, K16, K8, K4, K2, K1.
N1 is a full note. N2 is a half note, N4 is a 1/4 note N8 is 1/8, N16 is 1/6.
Notes with 'K' are
dotted. They are 3/2 as long as normal ones.
Notes with 'T' are
triplets. They are 2/3 as long as normal ones.
How to select the pitch?
The pitch notation is made of two letters and one digit.
The letters define which note it is and the digit in which octave.
For example CC4 is the C note in the 4th octave.
These are the white keys:
CC, DD, EE, FF, GG, AA, HH.
These are the black keys:
CD, DE, FG, GA, AH.
The lowest available note is CC0, the highest is FF8, that's 102 notes.
If you want a silent note you just specify the length.
But what if you need a
tie?
If you add " | CONT" to a note the interpreter will know that the note doesn't end but it's continued by the next one:
In this example
Code: Select all
//28
N8 | CD6,
N16 | GA5,
N16 ,
N16 | GA5,
N16 | GG5,
N16 | FF5,
N16 | GG5 | CONT,
N2 | GG5,
the g5 note has a total duration of 1/2 + 1/6.
That's all you need for writing the notes.
Other things,
the tempo.
At the beginning of the file you see
Code: Select all
volatile unsigned short tempo = 312;
It defines how fast the music plays. You can put there an integer between 0 and 4095.
How to choose the value.
If you want the speed to be X bpm (X 1/4 notes per minute) your value is (37500 / X )- 1.
You can change the speed in the middle of a music piece, like this:
Code: Select all
//18
N8 | DD6,
K4 | FF6,
N2,
CTMP | 273,
//19
N1 | DD5,
The CTMP command changes the speed for all 4 channels.
There must be at least one note between two CTMP commands, otherwise the second one will be interpreted as a note.
If you have a fragment that is repeated you dont't have to write it down multiple times. You can use the RPST and RPND commands.
Example:
Code: Select all
RPST| RP0 | 1,
//23
N8 | DD4,
N8 | AA4,
N8 | GG4,
N8 | AA4,
N8 | FF4,
N8 | AA4,
N8 | EE4,
N8 | AA4,
//24
N8 | CD4,
N8 | AA4,
N8 | GG4,
N8 | AA4,
N16 | AA4,
N16 | AH4,
N16 | AA4,
N16 | GG4,
N4 | AA4,
//25
N8 | AA4,
N8 | FF4,
N8 | CC5,
N8 | FF4,
N8 | AA4,
N8 | GG4,
N8 | FF4,
N8 | GG4,
//26
N8 | EE4,
N8 | CD4,
N8 | AA4,
N8 | CD4,
N16 | AA4,
N16 | AH4,
N16 | AA4,
N16 | GG4,
N4 | AA4,
RPND| RP0,
RPST | RP0 | 1,
RPST is the beginning of a repeat.
1 - is the number that defines how many times the repeated fragment will be played. It's one less. So 1 means that it will be played twice, 0 means that it will be played once, and so on.
Available values: 0 - 255.
RP0 is the "index", There are 4 available values RP0, RP1, RP2, RP3. This way you can have repeats inside repeats.
RPND is the end of a repeat, the index should be the same as with the corresponding RPST.
That's all needed to write music for it.
But how to hear it.
Unfortunately, it requires compiling wav.c
If you have gcc (and make) installed, it can be compiled by one command:
.
Or you can just send your sheet.h file to me.
ETA:
There is also this part at the end:
Code: Select all
volatile struct channel ch0 = {
.V=0x3e000000,
.A=0x00079e5a,
.D=0x00006184,
.S=0x1F000000,
.R=0x00028a1e,
.dist=2,
.sheetind=sheet0
};
volatile struct channel ch1 = {
.V=0x3e000000,
.A=0x00079e5a,
.D=0x00006184,
.S=0x1F000000,
.R=0x00028a1e,
.dist=2,
.sheetind=sheet1
};
volatile struct channel ch2 = {
.V=0x3e000000,
.A=0x00079e5a,
.D=0x00006184,
.S=0x1F000000,
.R=0x00028a1e,
.dist=2,
.sheetind=sheet2
};
volatile struct channel ch3 = {
.V=0x3e000000,
.A=0x00079e5a,
.D=0x00006184,
.S=0x1F000000,
.R=0x00028a1e,
.dist=2,
.sheetind=sheet3
};
What can you do with it?
These are parameters for configuring the
ADSR envelope generator. (except sheetind which is just a pointer to the sheet).
"dist" defines the distance between notes. It's how many 'ticks' before starting a new note the previous one is released:

It should be greater than 0. The value of 0 will confuse the envelope generator.
How long is one tick?
The 1/16 note is always 6 ticks long, the 1/8 note is 12 ticks long, and so on.
What do the other parameters do?
The envelope generation has 4 phases: A, D, S, R.

The parameters have the same names.
They are 32 bit values but only the two leftmost digits (the most signifficant byte) appears on the output.
The note begins with the A phase.
In the A phase, at each sample the sound level is increased by the value of the A parameter.
(the sampling frequency is 100kHz)
When the sound level reaches the value of the V parameter the D phase begins.
In the D phase at each sample the sound level is decreased by the value of the D parameter.
When the sound level reaches the value of the S parameter the S phase begins.
In the S phase the sound level has a constant value equal to the S parameter.
When the note ends the R phase begins (no matter which phase was before)
In the R phase at each sample the sound level is decreased by the value of the R parameter.
This happens until the sound level reaches 0.
The maximal value of V is 0x3fffffff for the .wav file generator and 0x3e000000 for the actual device.
A higher value can cause an overflow when all 4 notes start playing together.