mirror of https://github.com/radex/radmatrix.git
audio and video
parent
0a6ba79e8d
commit
f46da1e22c
|
@ -46,3 +46,14 @@ bool gfx_decoder_loadNextFrame() {
|
|||
free(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long frameLastChangedAt = 0;
|
||||
|
||||
bool gfx_decoder_handleLoop() {
|
||||
auto now = millis();
|
||||
if (now - frameLastChangedAt > MS_PER_FRAME) {
|
||||
frameLastChangedAt = now;
|
||||
return gfx_decoder_loadNextFrame();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -9,5 +9,6 @@ extern uint16_t frameCount;
|
|||
extern uint8_t gfxFrameBuffer[2048];
|
||||
|
||||
bool gfx_decoder_loadNextFrame();
|
||||
bool gfx_decoder_handleLoop();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,10 +20,6 @@ inline void outputEnable(uint8_t pin, bool enable) {
|
|||
gpio_put(pin, !enable);
|
||||
}
|
||||
|
||||
uint16_t frameIndex = 0;
|
||||
uint16_t lastRenderedFrameIndex = 0;
|
||||
unsigned long frameLastChangedAt;
|
||||
|
||||
// we have 4-bit color depth, so 16 levels of brightness
|
||||
// we go from phase 0 to phase 3
|
||||
uint8_t brightnessPhase = 0;
|
||||
|
@ -61,10 +57,6 @@ void leds_init() {
|
|||
clearShiftReg(ROW_SRCLK, ROW_SRCLR);
|
||||
pulsePin(ROW_RCLK);
|
||||
|
||||
// clear frames
|
||||
frameIndex = 0;
|
||||
frameLastChangedAt = millis();
|
||||
|
||||
/*
|
||||
// launch core1
|
||||
// NOTE: For some reason, without delay, core1 doesn't start?
|
||||
|
|
|
@ -23,10 +23,7 @@ void setup() {
|
|||
|
||||
setupSD();
|
||||
|
||||
// // sd_getAudio();
|
||||
// sd_getGfx();
|
||||
|
||||
// return;
|
||||
sd_loadAudio();
|
||||
|
||||
if (!sd_loadGfxFrameLengths()) {
|
||||
Serial.println("Failed to load gfx frame lengths");
|
||||
|
@ -40,26 +37,24 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() > 0) {
|
||||
char c = Serial.read();
|
||||
if (c == 'p') {
|
||||
Serial.println("Paused. Press any key to continue.");
|
||||
leds_disable();
|
||||
while (Serial.available() == 0) {
|
||||
Serial.read();
|
||||
delay(50);
|
||||
}
|
||||
Serial.println("Continuing...");
|
||||
}
|
||||
}
|
||||
sd_loadNextAudio();
|
||||
|
||||
// if (Serial.available() > 0) {
|
||||
// char c = Serial.read();
|
||||
// if (c == 'p') {
|
||||
// Serial.println("Paused. Press any key to continue.");
|
||||
// leds_disable();
|
||||
// while (Serial.available() == 0) {
|
||||
// Serial.read();
|
||||
// delay(50);
|
||||
// }
|
||||
// Serial.println("Continuing...");
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!gfx_decoder_loadNextFrame()) {
|
||||
if (!gfx_decoder_handleLoop()) {
|
||||
Serial.println("Failed to load frame...");
|
||||
}
|
||||
|
||||
leds_render();
|
||||
leds_render();
|
||||
leds_render();
|
||||
leds_render();
|
||||
}
|
||||
|
|
|
@ -156,55 +156,54 @@ void printSDStats(RP2040_SdVolume volume) {
|
|||
Serial.println((float)volumesize / 1024.0);
|
||||
}
|
||||
|
||||
File file;
|
||||
File audioFile;
|
||||
|
||||
void sd_getAudio() {
|
||||
void sd_loadAudio() {
|
||||
if (!SD.exists("/badapple/audio.bin")) {
|
||||
Serial.println("Audio not found :(");
|
||||
return;
|
||||
}
|
||||
|
||||
if (file) {
|
||||
file.close();
|
||||
if (audioFile) {
|
||||
audioFile.close();
|
||||
}
|
||||
|
||||
file = SD.open("/badapple/audio.bin", FILE_READ);
|
||||
audioFile = SD.open("/badapple/audio.bin", FILE_READ);
|
||||
Serial.println("Audio file opened");
|
||||
|
||||
audio_stop();
|
||||
|
||||
// load two buffers' worth of audio
|
||||
if (file.read(&wav_buffer_0, BUFFER_LEN) < BUFFER_LEN) {
|
||||
if (audioFile.read(&wav_buffer_0, BUFFER_LEN) < BUFFER_LEN) {
|
||||
Serial.println("Could not read first sample");
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.read(&wav_buffer_1, BUFFER_LEN) < BUFFER_LEN) {
|
||||
if (audioFile.read(&wav_buffer_1, BUFFER_LEN) < BUFFER_LEN) {
|
||||
Serial.println("Could not read second sample");
|
||||
return;
|
||||
}
|
||||
|
||||
audio_start();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
void sd_loadNextAudio() {
|
||||
if (!next_buffer_requested) {
|
||||
delay(50);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
next_buffer_requested = false;
|
||||
|
||||
auto next_buffer = wav_buffer1_active ? &wav_buffer_0 : &wav_buffer_1;
|
||||
auto bytesRead = file.read(next_buffer, BUFFER_LEN);
|
||||
auto bytesRead = audioFile.read(next_buffer, BUFFER_LEN);
|
||||
|
||||
if (bytesRead < BUFFER_LEN) {
|
||||
Serial.println("End of audio file");
|
||||
file.seek(0);
|
||||
Serial.println("End of audio file, rewinding...");
|
||||
audioFile.seek(0);
|
||||
} else {
|
||||
Serial.print("Read ");
|
||||
Serial.print(bytesRead);
|
||||
Serial.println(" bytes from audio file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool sd_loadGfxFrameLengths() {
|
||||
|
|
|
@ -5,7 +5,8 @@ void setupSD();
|
|||
|
||||
bool isSDCardInserted();
|
||||
|
||||
void sd_getAudio();
|
||||
void sd_loadAudio();
|
||||
void sd_loadNextAudio();
|
||||
bool sd_loadGfxFrameLengths();
|
||||
bool sd_loadGfxBlob();
|
||||
int32_t sd_loadNextFrame();
|
||||
|
|
Loading…
Reference in New Issue