OK, file updated with proper m4v.h file, anyway, here's how the music works:
The decoder uses the following value to IPC note table:
Code: Select all
int pitch_table[] = {
41, /* A */
38, /* A# */
36, /* B */
33, /* Middle C */
31, /* C# */
28, /* D */
26, /* D# */
24, /* E */
22, /* F */
20, /* F# */
19, /* G */
17, /* G# */
15, /* A */
14, /* A# */
12, /* B */
11, /* C */
10, /* C# */
9, /* D */
8, /* D# */
7, /* E */
6, /* F */
5, /* F# */
4, /* G */
3 /* G# */
};
#define DURATION_FRAMES 3
#define NOTE_DURATION 1600
So, the encoder merely has to store the offset in this table in the video file. You'll also note that each music tick is actually 3 frames long. The 1600 is the multiplier for the duration of the note as given to the IPC. The docs say that the BEEP duration is a multiple of 72ms but I'm not sure that this is correct.
The actual music itself is currently hard coded into the encoder as two arrays, one holding the musical note table offset and the other the duration in music ticks.
Code: Select all
unsigned int notes[] = {
6,8,9,11,13,18,16,13,6,13,11,9,8,
6,8,9,11,13,11,9,8,6,8,9,8,6,8,9,
6,8,9,11,13,18,16,13,6,13,11,9,8,
6,8,9,11,13,11,9,8,6,8,9,8,6,8,9
};
unsigned int duration[] = {
2,1,1,1,2,1,1,2,2,1,1,1,1,
1,1,1,1,2,1,1,1,1,1,1,1,1,1,2,
1,1,1,1,2,1,1,2,2,1,1,1,1,
1,1,1,1,2,1,1,1,1,1,1,1,1,1,2
};
The encoder only sets the value in the audio byte in the frame header of the frame which should play a note, so the decoder doesn't have to do this calculation, only do what it's told.