Skip to content

Commit cbb58ac

Browse files
committedSep 13, 2017
Splash and ingame sounds + sound effects
1 parent 0366277 commit cbb58ac

14 files changed

+212
-447
lines changed
 

‎master/main.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ int main(void)
276276
{
277277
init();
278278

279+
uart_putc(0); // play title music
279280
// show splash screen until button A is pressed
280281
initial_level = eeprom_read_dword(&initial_level_stored);
281282
drawsplash(initial_level != 0);
@@ -339,7 +340,11 @@ int main(void)
339340
bombstruct = &bomb_;
340341

341342
left_door_open = true;
342-
right_door_open = true;
343+
right_door_open = true;
344+
345+
//ingame music
346+
uart_putc(1);
347+
343348
newgame();
344349

345350
while (1)
@@ -672,6 +677,7 @@ int main(void)
672677
{
673678
if (explode < getMsTimer())
674679
{
680+
uart_putc('e');
675681
uint8_t blast_x1;
676682
uint8_t blast_x2;
677683
uint8_t blast_y1;

‎music/Boss_Musik_1.mid

459 Bytes
Binary file not shown.

‎music/Boss_Musik_2.mid

357 Bytes
Binary file not shown.

‎music/Combat 2.mid

70.2 KB
Binary file not shown.

‎music/Ingame_Musik.mid

291 Bytes
Binary file not shown.

‎music/Ingame_Musik_Tief.mid

291 Bytes
Binary file not shown.

‎music/LILITH03.MID

86.7 KB
Binary file not shown.

‎music/SERAPHO.MID

3.69 KB
Binary file not shown.

‎music/bisque cuite.mid

11.2 KB
Binary file not shown.

‎music/sevenfortyam.mid

761 Bytes
Binary file not shown.

‎slave/main.c

+77-32
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <inttypes.h>
77
#include <util/delay.h>
88
#include <avr/interrupt.h>
9+
#include <math.h>
910
#include "uart.h"
1011
#include "timer.h"
1112
#include "music.h"
@@ -17,61 +18,105 @@ SIGNAL(TIMER1_COMPA_vect)
1718
PORTB ^= (1 << 1);
1819
}
1920

21+
const uint16_t* playing;
22+
uint16_t i;
23+
void play(const uint16_t* music)
24+
{
25+
while (1)
26+
{
27+
while (1)
28+
{
29+
uint16_t delay = pgm_read_word(&music[i]);
30+
if (i > 0 && delay == 0)
31+
break;
32+
reset_timer();
33+
while(getMsTimer() < delay && !uart_data_waiting());
34+
if (uart_data_waiting())
35+
break;
36+
OCR1A = pgm_read_word(&music[i+1]);
37+
i += 2;
38+
}
39+
OCR1A = 0;
40+
if (uart_data_waiting())
41+
break;
42+
i = 0;
43+
}
44+
}
45+
46+
void start_playing(const uint16_t* music)
47+
{
48+
i = 0;
49+
playing = music;
50+
play(music);
51+
}
52+
53+
void continue_playing()
54+
{
55+
play(playing);
56+
}
57+
2058
int main()
2159
{
2260
init();
23-
24-
/*while (1)
61+
62+
uint16_t j = 0;
63+
while (1)
2564
{
2665
while(!uart_data_waiting());
2766
switch (uart_getc())
2867
{
29-
case 's':
30-
// shoot
68+
case 0:
69+
start_playing(splash);
70+
break;
71+
case 1:
72+
start_playing(ingame);
73+
break;
74+
case 's': // shoot
3175
for (uint16_t i = 0; i < 10000; i += 15)
3276
{
3377
OCR1A = i;
3478
_delay_us(500);
3579
}
3680
OCR1A = 0;
3781
break;
82+
case 'e': // explosion
83+
if (j % 2)
84+
{
85+
for (uint16_t i = 50000; i > 5000; i -= 500)
86+
{
87+
OCR1A = i;
88+
_delay_ms(1);
89+
}
90+
for (uint16_t i = 5000; i < 50000; i += 40)
91+
{
92+
OCR1A = i;
93+
_delay_ms(1);
94+
}
95+
}
96+
else
97+
{
98+
for (uint16_t i = 5000; i < 40000; i *= 1.002)
99+
{
100+
OCR1A = i;
101+
_delay_us(1000);
102+
OCR1A /= 2;
103+
_delay_us(100);
104+
}
105+
}
106+
OCR1A = 0;
107+
j++;
108+
break;
38109
}
110+
if (!uart_data_waiting())
111+
continue_playing();
39112
}
40113

41-
// explosion
42-
for (uint16_t i = 5000; i < 40000; i *= 1.002)
43-
{
44-
OCR1A = i;
45-
_delay_us(1000);
46-
OCR1A /= 2;
47-
_delay_us(100);
48-
}
49-
OCR1A = 0;
50-
_delay_ms(1000);*/
51-
52114
// random
53115
/*while(1)
54116
{
55117
OCR1A = random() % 100 * 100 + 2000;
56118
_delay_ms(300);
57119
}*/
58-
59-
while (1)
60-
{
61-
uint8_t i = 0;
62-
while (1)
63-
{
64-
uint16_t delay = pgm_read_word(&elise[i]);
65-
if (i > 0 && delay == 0)
66-
break;
67-
reset_timer();
68-
while(getMsTimer() < delay);
69-
OCR1A = pgm_read_word(&elise[i+1]);
70-
i += 2;
71-
}
72-
OCR1A = 0;
73-
_delay_ms(100);
74-
}
75120
}
76121

77122
void init()

‎slave/music.c

+112-407
Large diffs are not rendered by default.

‎slave/music.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <inttypes.h>
55
#include <avr/pgmspace.h>
66

7-
extern const uint16_t elise[821] PROGMEM;
7+
extern const uint16_t elise[39] PROGMEM;
8+
9+
extern const uint16_t splash[95] PROGMEM;
10+
11+
extern const uint16_t ingame[83] PROGMEM;
812

913
#endif

‎slave/synth.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Synth():
1111
def __init__(self, hfile, cfile):
1212
self.hfile = hfile
1313
self.cfile = cfile
14-
def writeCArray(self,filename,arrayname,allow_pause=True,includeTracks=[]):
14+
def writeCArray(self,filename,arrayname,allow_pause=True,timescale=1,includeTracks=[],pitch=1):
1515
mid = MidiFile(filename)
1616
events=[]
1717
for i, track in enumerate(mid.tracks):
@@ -21,7 +21,7 @@ def writeCArray(self,filename,arrayname,allow_pause=True,includeTracks=[]):
2121
for message in track:
2222
t+=message.time
2323
if (message.type=="note_on" or message.type=="note_off") :
24-
e={}
24+
e={}
2525
if message.velocity==0:
2626
e["type"]="note_off"
2727
else:
@@ -53,20 +53,20 @@ def writeCArray(self,filename,arrayname,allow_pause=True,includeTracks=[]):
5353
if note not in notes or max(notes) > note:
5454
note = max(notes)
5555
t = e[0]
56-
delay = int((t - last_time) * 10 ** (-3) / 480. * tempo) # in ms
56+
delay = int(timescale*(t - last_time) * 10 ** (-3) / 480. * tempo) # in ms
5757
last_time = t
5858
freq = 2.0 ** ((note - 69) / 12.0) * 440.0 # in Hz
5959
period = 1.0 / freq # in seconds
6060
# value for compare register with prescaler=8
6161
# /2 because the timer counts up twice per period
62-
compare = F_CPU * period / 8 / 2
62+
compare = F_CPU * period / 8 / 2 / pitch
6363
if delay == 0 and len(changes) > 0:
6464
changes[-1]["freq"] = int(compare)
6565
else:
6666
changes.append({"delay": delay, "freq": int(compare)})
6767
elif allow_pause: # there is currently no note playing
6868
t = e[0]
69-
delay = int((t - last_time) * 10 ** (-3) / 480. * tempo) # in ms
69+
delay = int(timescale*(t - last_time) * 10 ** (-3) / 480. * tempo) # in ms
7070
last_time = t
7171
compare = 0 # sound off
7272
if delay == 0 and len(changes) > 0:
@@ -91,5 +91,10 @@ def writeCArray(self,filename,arrayname,allow_pause=True,includeTracks=[]):
9191
hfile.write("#ifndef MUSIC_H\n#define MUSIC_H\n\n#include <inttypes.h>\n#include <avr/pgmspace.h>\n\n")
9292
synth=Synth(hfile, cfile)
9393
# for ... in os.walk("../music"):
94-
synth.writeCArray("../music/sevenfortyam.mid", "elise", True)
94+
synth.writeCArray("../../bomb_explosion_1.wav.mid", "elise", True)
95+
#synth.writeCArray("../music/sevenfortyam.mid", "splash", True)
96+
#synth.writeCArray("../music/Combat 2.mid", "splash", True, 4, [3])
97+
#synth.writeCArray("../music/SERAPHO.MID", "splash", True, 1, [1], .5)
98+
synth.writeCArray("../music/Boss_Musik_2.mid", "splash", True)
99+
synth.writeCArray("../music/Ingame_Musik_Tief.mid", "ingame", True)
95100
hfile.write("#endif")

0 commit comments

Comments
 (0)
Please sign in to comment.