Add strophe 1 of the song
This commit is contained in:
parent
5581c3e1d9
commit
0a62b730f3
41
audio.c
41
audio.c
@ -31,36 +31,27 @@ static struct AudioState sAudioState;
|
|||||||
bool bPerformAudioStep()
|
bool bPerformAudioStep()
|
||||||
{
|
{
|
||||||
bool bSuccess = true;
|
bool bSuccess = true;
|
||||||
struct AudioState *psState = &sAudioState;
|
|
||||||
psState = psState;
|
|
||||||
|
|
||||||
sAudioState.highState = !sAudioState.highState;
|
sAudioState.highState = !sAudioState.highState;
|
||||||
if (sAudioState.highState)
|
if (sAudioState.highState)
|
||||||
{
|
{
|
||||||
DAC_SetValue(512);
|
|
||||||
if (sAudioState.u16RemainingWaves == 0)
|
|
||||||
{
|
|
||||||
LPC_TIM0->MR0 = sAudioState.u32EndBreak;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DAC_SetValue(0);
|
|
||||||
if (sAudioState.u16RemainingWaves > 0)
|
if (sAudioState.u16RemainingWaves > 0)
|
||||||
{
|
{
|
||||||
sAudioState.u16RemainingWaves--;
|
DAC_SetValue(512);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (FREQ(*sAudioState.cpu32NextAction) == 0)
|
if (FREQ(*sAudioState.cpu32NextAction) == 0)
|
||||||
{
|
{
|
||||||
sAudioState.highState = true;
|
// GOTO
|
||||||
|
sAudioState.highState = false;
|
||||||
sAudioState.cpu32NextAction = cppu32JumpLabels[*sAudioState.cpu32NextAction];
|
sAudioState.cpu32NextAction = cppu32JumpLabels[*sAudioState.cpu32NextAction];
|
||||||
bSuccess = false;
|
bSuccess = false;
|
||||||
}
|
}
|
||||||
else if (FREQ(*sAudioState.cpu32NextAction) == 1)
|
else if (FREQ(*sAudioState.cpu32NextAction) == 1)
|
||||||
{
|
{
|
||||||
sAudioState.highState = true;
|
// CALL
|
||||||
|
sAudioState.highState = false;
|
||||||
sAudioState.cpu32Stack[sAudioState.u32StackPointer] = sAudioState.cpu32NextAction + 1;
|
sAudioState.cpu32Stack[sAudioState.u32StackPointer] = sAudioState.cpu32NextAction + 1;
|
||||||
sAudioState.cpu32NextAction = cppu32JumpLabels[WAVES(*sAudioState.cpu32NextAction)];
|
sAudioState.cpu32NextAction = cppu32JumpLabels[WAVES(*sAudioState.cpu32NextAction)];
|
||||||
sAudioState.u32StackPointer++;
|
sAudioState.u32StackPointer++;
|
||||||
@ -68,13 +59,22 @@ bool bPerformAudioStep()
|
|||||||
}
|
}
|
||||||
else if (FREQ(*sAudioState.cpu32NextAction) == 2)
|
else if (FREQ(*sAudioState.cpu32NextAction) == 2)
|
||||||
{
|
{
|
||||||
sAudioState.highState = true;
|
// RETURN
|
||||||
|
sAudioState.highState = false;
|
||||||
sAudioState.u32StackPointer--;
|
sAudioState.u32StackPointer--;
|
||||||
sAudioState.cpu32NextAction = sAudioState.cpu32Stack[sAudioState.u32StackPointer];
|
sAudioState.cpu32NextAction = sAudioState.cpu32Stack[sAudioState.u32StackPointer];
|
||||||
bSuccess = false;
|
bSuccess = false;
|
||||||
}
|
}
|
||||||
|
else if (FREQ(*sAudioState.cpu32NextAction) == 3)
|
||||||
|
{
|
||||||
|
// PAUSE
|
||||||
|
sAudioState.highState = false;
|
||||||
|
LPC_TIM0->MR0 = WAVES(*sAudioState.cpu32NextAction) << 12;
|
||||||
|
sAudioState.cpu32NextAction++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
DAC_SetValue(512);
|
||||||
uint32_t u32Frequency = FREQ(*sAudioState.cpu32NextAction);
|
uint32_t u32Frequency = FREQ(*sAudioState.cpu32NextAction);
|
||||||
LPC_TIM0->MR0 = u32Frequency * 2;
|
LPC_TIM0->MR0 = u32Frequency * 2;
|
||||||
uint32_t u32Waves = WAVES(*sAudioState.cpu32NextAction);
|
uint32_t u32Waves = WAVES(*sAudioState.cpu32NextAction);
|
||||||
@ -84,6 +84,15 @@ bool bPerformAudioStep()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DAC_SetValue(0);
|
||||||
|
sAudioState.u16RemainingWaves--;
|
||||||
|
if (sAudioState.u16RemainingWaves == 0)
|
||||||
|
{
|
||||||
|
LPC_TIM0->MR0 = sAudioState.u32EndBreak;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
}
|
}
|
||||||
@ -100,7 +109,7 @@ void TIMER0_IRQHandler()
|
|||||||
// Initializes the interrupt-driven audio output
|
// Initializes the interrupt-driven audio output
|
||||||
void vStartAudio()
|
void vStartAudio()
|
||||||
{
|
{
|
||||||
sAudioState.highState = true;
|
sAudioState.highState = false;
|
||||||
sAudioState.u16RemainingWaves = 0;
|
sAudioState.u16RemainingWaves = 0;
|
||||||
sAudioState.cpu32NextAction = cpu32EntryPoint;
|
sAudioState.cpu32NextAction = cpu32EntryPoint;
|
||||||
sAudioState.u32StackPointer = 0;
|
sAudioState.u32StackPointer = 0;
|
||||||
|
103
melody.c
103
melody.c
@ -14,6 +14,9 @@ This file contains the main app function and init.
|
|||||||
// duration: total duration as multiple of 40ns
|
// duration: total duration as multiple of 40ns
|
||||||
#define TONE(freq, duration) ((((uint32_t)freq & 0xffff) << 16) | (((uint32_t)duration / (uint32_t)freq) & 0xffff))
|
#define TONE(freq, duration) ((((uint32_t)freq & 0xffff) << 16) | (((uint32_t)duration / (uint32_t)freq) & 0xffff))
|
||||||
|
|
||||||
|
// duration: pause duration as multiple of 40ns
|
||||||
|
#define PAUSE(duration) (0x30000 | ((duration >> 10) & 0xffff))
|
||||||
|
|
||||||
const uint32_t TACT = 2120 * 1000 * 25; // 2.12 seconds for one tact
|
const uint32_t TACT = 2120 * 1000 * 25; // 2.12 seconds for one tact
|
||||||
|
|
||||||
const uint32_t GIS2 = 30098;
|
const uint32_t GIS2 = 30098;
|
||||||
@ -29,14 +32,20 @@ const uint32_t RETURN = 0x20000;
|
|||||||
|
|
||||||
const uint32_t refrain[];
|
const uint32_t refrain[];
|
||||||
const uint32_t quadrupel[];
|
const uint32_t quadrupel[];
|
||||||
const uint32_t *cpu32EntryPoint = refrain;
|
const uint32_t strophe1[];
|
||||||
|
const uint32_t main_melody[];
|
||||||
|
const uint32_t *cpu32EntryPoint = main_melody;
|
||||||
|
|
||||||
const uint32_t GOTO_REFRAIN = 0;
|
const uint32_t CALL_REFRAIN = CALL + 0;
|
||||||
const uint32_t CALL_QUADRUPEL = CALL + 1;
|
const uint32_t CALL_QUADRUPEL = CALL + 1;
|
||||||
|
const uint32_t CALL_STROPHE1 = CALL + 2;
|
||||||
|
const uint32_t GOTO_MAIN_MELODY = 3;
|
||||||
|
|
||||||
const uint32_t *jumplabels[] = {
|
const uint32_t *jumplabels[] = {
|
||||||
refrain,
|
refrain,
|
||||||
quadrupel,
|
quadrupel,
|
||||||
|
strophe1,
|
||||||
|
main_melody,
|
||||||
};
|
};
|
||||||
const uint32_t **cppu32JumpLabels = jumplabels;
|
const uint32_t **cppu32JumpLabels = jumplabels;
|
||||||
|
|
||||||
@ -96,5 +105,93 @@ const uint32_t refrain[] = {
|
|||||||
TONE(DIS, TACT / 4),
|
TONE(DIS, TACT / 4),
|
||||||
TONE(CIS, TACT / 2),
|
TONE(CIS, TACT / 2),
|
||||||
|
|
||||||
GOTO_REFRAIN,
|
RETURN,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t strophe1[] = {
|
||||||
|
PAUSE(TACT / 4),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(C, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
|
||||||
|
TONE(C, TACT * 3 / 16), // 1/8 tact before, 1/16 tact after
|
||||||
|
|
||||||
|
TONE(B, TACT / 16),
|
||||||
|
TONE(GIS, TACT * 7 / 8),
|
||||||
|
|
||||||
|
PAUSE(TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(C, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
PAUSE(TACT / 8),
|
||||||
|
TONE(GIS, TACT / 8),
|
||||||
|
|
||||||
|
TONE(GIS2,TACT / 4),
|
||||||
|
TONE(GIS2,TACT / 8),
|
||||||
|
TONE(DIS, TACT * 5 / 8),
|
||||||
|
|
||||||
|
PAUSE(TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(C, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
|
||||||
|
PAUSE(TACT / 8),
|
||||||
|
TONE(C, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(C, TACT / 16),
|
||||||
|
TONE(B, TACT / 16),
|
||||||
|
TONE(GIS, TACT / 2),
|
||||||
|
|
||||||
|
PAUSE(TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(C, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(GIS, TACT / 4),
|
||||||
|
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(F, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 2),
|
||||||
|
|
||||||
|
TONE(CIS, TACT * 5 / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(F, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
TONE(F, TACT / 8),
|
||||||
|
TONE(DIS, TACT / 4),
|
||||||
|
TONE(GIS, TACT / 4),
|
||||||
|
|
||||||
|
PAUSE(TACT / 4),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
TONE(C, TACT / 8),
|
||||||
|
TONE(CIS, TACT / 8),
|
||||||
|
TONE(B, TACT / 8),
|
||||||
|
PAUSE(TACT / 8),
|
||||||
|
TONE(DIS, TACT / 8),
|
||||||
|
|
||||||
|
TONE(F, TACT / 8),
|
||||||
|
TONE(DIS, TACT * 3 / 8),
|
||||||
|
|
||||||
|
RETURN,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t main_melody[] = {
|
||||||
|
CALL_STROPHE1,
|
||||||
|
CALL_REFRAIN,
|
||||||
|
GOTO_MAIN_MELODY,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user