Playback working (timing is a bit lopsided for some reason; next step is to implementing stop recording with P1.3 button.
This commit is contained in:
parent
9c6f171102
commit
1e7089feae
936
lab3/piano.asm
936
lab3/piano.asm
File diff suppressed because it is too large
Load Diff
88
lab3/piano.c
88
lab3/piano.c
|
@ -1,22 +1,22 @@
|
||||||
#include "msp430.h"
|
#include "msp430.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define c 1000
|
#define c 3822
|
||||||
#define dflat 950
|
#define dflat 3608
|
||||||
#define d 900
|
#define d 3405
|
||||||
#define eflat 850
|
#define eflat 3214
|
||||||
#define e 800
|
#define e 3034
|
||||||
#define f 750
|
#define f 2863
|
||||||
#define gflat 720
|
#define gflat 2703
|
||||||
#define g 670
|
#define g 2551
|
||||||
#define aflat 625
|
#define aflat 2408
|
||||||
#define a 600
|
#define a 2273
|
||||||
#define bflat 570
|
#define bflat 2145
|
||||||
#define b 535
|
#define b 2025
|
||||||
#define cc 500
|
#define cc 1911
|
||||||
#define n 0
|
#define n 0
|
||||||
|
|
||||||
int hbd[30] = {
|
unsigned int hbd[30] = {
|
||||||
c, n, c,
|
c, n, c,
|
||||||
d, c, f,
|
d, c, f,
|
||||||
e, c, n, c,
|
e, c, n, c,
|
||||||
|
@ -27,7 +27,7 @@ int hbd[30] = {
|
||||||
a, f, g,
|
a, f, g,
|
||||||
f, n
|
f, n
|
||||||
};
|
};
|
||||||
int hbd_lengths[30] = {
|
unsigned int hbd_lengths[30] = {
|
||||||
1, 1, 1,
|
1, 1, 1,
|
||||||
3, 3, 3,
|
3, 3, 3,
|
||||||
6, 1, 1, 1,
|
6, 1, 1, 1,
|
||||||
|
@ -39,18 +39,18 @@ int hbd_lengths[30] = {
|
||||||
6, 3
|
6, 3
|
||||||
};
|
};
|
||||||
|
|
||||||
int scale[13] = {
|
unsigned int scale[13] = {
|
||||||
c, dflat, d, eflat, e, f, gflat, g, aflat, a, bflat, b, cc
|
c, dflat, d, eflat, e, f, gflat, g, aflat, a, bflat, b, cc
|
||||||
};
|
};
|
||||||
int scale_lengths[13] = {
|
unsigned int scale_lengths[13] = {
|
||||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
|
||||||
};
|
};
|
||||||
|
|
||||||
int whole[8] = {
|
unsigned int whole[8] = {
|
||||||
c, d, e, f, g, a, b, cc
|
c, d, e, f, g, a, b, cc
|
||||||
};
|
};
|
||||||
|
|
||||||
void play(int note) {
|
void play(unsigned int note) {
|
||||||
if (note != 0) {
|
if (note != 0) {
|
||||||
CCR0 = note;
|
CCR0 = note;
|
||||||
CCR1 = 100;
|
CCR1 = 100;
|
||||||
|
@ -59,16 +59,18 @@ void play(int note) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sing(int* song, int* song_lengths, int length) {
|
void sing(unsigned int* song, unsigned int* song_lengths, unsigned int length) {
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
int note = song[i];
|
play(song[i]);
|
||||||
play(note);
|
|
||||||
for (int j = 0; j < song_lengths[i]; j++) {
|
for (int j = 0; j < song_lengths[i]; j++) {
|
||||||
__delay_cycles(0x3000);
|
__delay_cycles(0x200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int us = 0;
|
||||||
|
unsigned int cs = 0;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
|
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
|
||||||
|
|
||||||
|
@ -76,22 +78,44 @@ void main(void) {
|
||||||
P1SEL |= BIT6; // P1.6 to TA0.1
|
P1SEL |= BIT6; // P1.6 to TA0.1
|
||||||
|
|
||||||
CCTL1 = OUTMOD_7; // CCR1 reset/set
|
CCTL1 = OUTMOD_7; // CCR1 reset/set
|
||||||
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
|
TACTL = TASSEL_2 | MC_1; // SMCLK, up to CCR0
|
||||||
|
TACCTL0 = CCIE; // enable interrupt
|
||||||
|
__enable_interrupt();
|
||||||
|
|
||||||
int recording[10] = {n};
|
unsigned int rec[10] = {n, b, b, b, b, b, b, b, b, b};
|
||||||
int recording_lengths[10] = {0};
|
unsigned int rec_len[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||||
int position = 1;
|
unsigned int position = 1;
|
||||||
|
TAR = 0;
|
||||||
while (position < 10) {
|
while (position < 10) {
|
||||||
if (whole[P1IN] != recording[position - 1]) {
|
if (whole[P1IN & 0xF] != rec[position - 1]) {
|
||||||
recording[position] = whole[P1IN];
|
rec_len[position - 1] = cs + (us + TAR)/10000;
|
||||||
recording_lengths[position] = 1;
|
rec[position] = whole[P1IN & 0xF];
|
||||||
play(recording[position]);
|
play(rec[position]);
|
||||||
|
cs = us = TAR = 0;
|
||||||
position++;
|
position++;
|
||||||
}
|
}
|
||||||
|
__delay_cycles(0x200);
|
||||||
}
|
}
|
||||||
|
|
||||||
sing(recording, recording_lengths, 10);
|
sing(rec, rec_len, 10);
|
||||||
//clear();
|
//clear();
|
||||||
//sing(hbd, hbd_lengths, 30);
|
//sing(hbd, hbd_lengths, 30);
|
||||||
//sing(scale, scale_lengths, 13);
|
//sing(scale, scale_lengths, 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__TI_COMPILER_VERSION__)
|
||||||
|
#pragma vector=TIMER0_A0_VECTOR
|
||||||
|
__interrupt void timer0_a0_isr(void)
|
||||||
|
#else
|
||||||
|
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) timer0_a0_isr (void)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
unsigned int us_left = 60000 - us; // count up to 60 000 microseconds in us
|
||||||
|
if (us_left > TACCR0) {
|
||||||
|
cs += 6; // add six centiseconds to count
|
||||||
|
us = TACCR0 - us_left; // save overflow
|
||||||
|
} else {
|
||||||
|
us += TACCR0;
|
||||||
|
}
|
||||||
|
TACCTL0 &= ~CCIFG; // set interrupt flag to 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue