Skip to content
Snippets Groups Projects
Commit cf382268 authored by Erik Strand's avatar Erik Strand
Browse files

Attempt to get songs to play

parent 7b56a163
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define clear(port,pin) (port &= (~pin)) // clear port pin #define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin #define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set #define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define bit_delay_time 8.5 // bit delay for 115200 with overhead #define bit_delay_time 8.4 // bit delay for 115200 with overhead
//#define bit_delay_time 31.82 // bit delay for 31250 with overhead //#define bit_delay_time 31.82 // bit delay for 31250 with overhead
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay #define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay #define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
...@@ -42,7 +42,11 @@ ...@@ -42,7 +42,11 @@
#define led_pin (1 << PB2) #define led_pin (1 << PB2)
void put_char(volatile unsigned char *port, unsigned char pin, char txchar) { #define note_on 144
#define note_off 128
void put_char(volatile unsigned char *port, unsigned char pin, uint8_t txchar) {
// send character in txchar on port pin // send character in txchar on port pin
// assumes line driver (inverts bits) // assumes line driver (inverts bits)
// //
...@@ -97,9 +101,15 @@ void put_char(volatile unsigned char *port, unsigned char pin, char txchar) { ...@@ -97,9 +101,15 @@ void put_char(volatile unsigned char *port, unsigned char pin, char txchar) {
bit_delay(); bit_delay();
// char delay // char delay
bit_delay(); char_delay();
} }
struct MidiEvent {
uint16_t tick;
uint8_t status;
uint8_t note;
uint8_t velocity;
};
int main(void) { int main(void) {
// Set the clock prescaler to 1. // Set the clock prescaler to 1.
...@@ -116,30 +126,118 @@ int main(void) { ...@@ -116,30 +126,118 @@ int main(void) {
// Configure led_pin as an output. // Configure led_pin as an output.
DDRB |= led_pin; DDRB |= led_pin;
// Blink the LED with ~1.0s half-period. uint16_t current_tick = 0;
// 100 * 200 * 1024 / 20M ~ 2.5s uint16_t max_tick = 960;
int count = 0; uint8_t event_index = 0;
// 120 ticks per quarter note
const struct MidiEvent events[] = {
// Stagefright
/*
{0, note_on, 40, 100},
{60, note_off, 40, 100},
{60, note_on, 40, 100},
{120, note_off, 40, 100},
{120, note_on, 40, 100},
{180, note_off, 40, 100},
{180, note_on, 42, 100},
{240, note_off, 42, 100},
{240, note_on, 43, 100},
{300, note_off, 43, 100},
{300, note_on, 43, 100},
{360, note_off, 43, 100},
{360, note_on, 44, 100},
{420, note_off, 44, 100},
{420, note_on, 44, 100},
{480, note_off, 44, 100},
//{480, note_on, 45, 100},
//{540, note_off, 45, 100},
{540, note_on, 45, 100},
{600, note_off, 45, 100},
{600, note_on, 45, 100},
{660, note_off, 45, 100},
{660, note_on, 47, 100},
{720, note_off, 47, 100},
{720, note_on, 48, 100},
{780, note_off, 48, 100},
{780, note_on, 48, 100},
{840, note_off, 48, 100},
{840, note_on, 51, 100},
{900, note_off, 51, 100},
{900, note_on, 51, 100},
{960, note_off, 51, 100},
*/
// Bb
{0, note_on, 58, 100},
{30, note_on, 62, 100},
{60, note_on, 65, 100},
{90, note_on, 69, 100},
{180, note_off, 69, 100},
{180, note_off, 65, 100},
{180, note_off, 62, 100},
{180, note_off, 58, 100},
{240 + 0, note_on, 58, 100},
{240 + 30, note_on, 61, 100},
{240 + 60, note_on, 64, 100},
{240 + 90, note_on, 67, 100},
{240 + 180, note_off, 67, 100},
{240 + 180, note_off, 64, 100},
{240 + 180, note_off, 61, 100},
{240 + 180, note_off, 58, 100},
{480 + 0, note_on, 60, 100},
{480 + 30, note_on, 64, 100},
{480 + 60, note_on, 65, 100},
{480 + 90, note_on, 69, 100},
{480 + 180, note_off, 69, 100},
{480 + 180, note_off, 65, 100},
{480 + 180, note_off, 64, 100},
{480 + 180, note_off, 60, 100},
{720 + 0, note_on, 60, 100},
{720 + 30, note_on, 63, 100},
{720 + 60, note_on, 65, 100},
{720 + 90, note_on, 69, 100},
{720 + 180, note_off, 69, 100},
{720 + 180, note_off, 65, 100},
{720 + 180, note_off, 63, 100},
{720 + 180, note_off, 60, 100},
// sentinel
{65535, note_off, 50, 100},
};
while (1) { while (1) {
// If it's been 10ms, reset the timer and increment count. if (TCNT0 >= 120) {
if (TCNT0 >= 200) {
TCNT0 = 0; TCNT0 = 0;
++count; ++current_tick;
// When count reaches 100, turn the LED on and send a note on command. while (events[event_index].tick <= current_tick) {
if (count == 100) { put_char(&serial_port, serial_pin_out, events[event_index].status);
PORTB |= led_pin; put_char(&serial_port, serial_pin_out, events[event_index].note);
put_char(&serial_port, serial_pin_out, 144); // note on put_char(&serial_port, serial_pin_out, events[event_index].velocity);
put_char(&serial_port, serial_pin_out, 70); // note (A4) ++event_index;
put_char(&serial_port, serial_pin_out, 100); // velocity
} }
// When count reaches 200, turn the LED off and send a note off command. if (current_tick == max_tick) {
else if (count == 200) { current_tick = 0;
PORTB &= ~led_pin; event_index = 0;
put_char(&serial_port, serial_pin_out, 128); // note off PORTB ^= led_pin;
put_char(&serial_port, serial_pin_out, 70); // note (A4)
put_char(&serial_port, serial_pin_out, 100); // velocity /*
count = 0; while (events[event_index].tick <= current_tick) {
put_char(&serial_port, serial_pin_out, events[event_index].status);
put_char(&serial_port, serial_pin_out, events[event_index].note);
put_char(&serial_port, serial_pin_out, events[event_index].velocity);
++event_index;
}
*/
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment