-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSound.cpp
More file actions
66 lines (56 loc) · 1.71 KB
/
Sound.cpp
File metadata and controls
66 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Sound.cpp
// Runs on MSPM0
// Sound assets in sounds/sounds.h
// Jackson Herleth
// JH77847
#include "Sound.h"
#include "../inc/DAC5.h"
#include "../inc/Timer.h"
#include "sounds.h"
#include <stdint.h>
#include <ti/devices/msp/msp.h>
volatile const uint8_t *soundPt = 0;
volatile uint32_t soundCount = 0;
uint32_t period = 0;
const uint8_t Waveform[2] = {0, 31}; // square wave
volatile uint32_t index = 0;
void SysTick_IntArm(uint32_t period, uint32_t priority) {
SysTick->CTRL = 0x00;
SysTick->LOAD = period - 1;
SysTick->VAL = 0;
SCB->SHP[1] = SCB->SHP[1] & (~0xC0000000); // set priority = 0 (bits 31,30)
SCB->SHP[1] = SCB->SHP[1] |= (priority << 30);
SysTick->CTRL = 0x07;
}
void Sound_Init(uint32_t p, uint32_t priority) {
soundPt = 0;
soundCount = 0;
period = p;
DAC5_Init();
SysTick->CTRL = 0; // Disable SysTick initially
}
void Sound_Start(const uint8_t *pt, uint32_t count) {
uint32_t status = SysTick->CTRL;
if (pt == 0 || count == 0)
return;
soundPt = pt;
soundCount = count;
SysTick_IntArm(period, 0); // Start SysTick interrupts
}
extern "C" void SysTick_Handler(void) {
if (soundCount > 0) {
DAC5_Out(*soundPt); // Output the current value to DAC
soundPt++; // Move to the next sample
soundCount--; // Decrement the sample count
} else {
SysTick->CTRL = 0; // Disable SysTick when sound is finished
soundPt = 0; // Clear the pointer
}
}
void Sound_Button(void) {
// Sound_Start(MarioJumpSound, sizeof(MarioJumpSound));
// Sound_Start(marioKartWinSound, sizeof(marioKartWinSound));
Sound_Start(MarioJumpSound, 11000);
}
void Sound_Win(void) { Sound_Start(invaderkilled, 3377); }
void Sound_Shoot(void) { Sound_Start(shoot, 4080); }