It seems that streaming music and saving/loading data using SDFilesystem interfere with each other:
The music starts streaming but as soon as something is loaded/saved to the SD card the loading of the music file stops and the part that already has been loaded is repeated…
Test program (basicly this is the SDCardFileIO with 2 extra lines of code to stream music):
bitburnr.snd
main.cpp
#pragma GCC diagnostic ignored "-Wwrite-strings"
#include "Pokitto.h"
#ifdef POK_SIM
#include "io.h"
#else
#include "SDFileSystem.h"
#endif
Pokitto::Core mygame;
FILE *filep = NULL;
const int32_t blockSize = 1000;
const int32_t totalFileSize = 200000;
char bufferOrg[blockSize];
char buffer[blockSize];
int32_t len = 0;
//uint32_t start_us = 0;
//uint32_t stop_us = 0;
uint32_t start_ms = 0;
uint32_t stop_ms = 0;
int main () {
mygame.sound.playMusicStream("music/bitburnr.SND");
mygame.begin();
mygame.sound.playMusicStream();
mygame.display.persistence = true;
mygame.display.println("Testing...");
while (mygame.isRunning()) {
if (mygame.update()) {
mygame.update();
break;
}
}
// *** Test SDFileSystem
mygame.display.println("*SDFS*");
#ifdef POK_SIM
char* filePathAndNamePFFS = "sdtest/200KB.txt";
char* filePathAndNameSDFS = "sdtest/200KB.txt";
char* dirNameSDFS = "sdtest";
mkdir(dirNameSDFS);
#else
SDFileSystem sd(/*MOSI*/P0_9, /*MISO*/P0_8, /*SCK*/P0_6, /*CS*/P0_7, /*Mountpoint*/"sd");
char* filePathAndNamePFFS = "sdtest/200KB.txt";
char* filePathAndNameSDFS = "/sd/sdtest/200KB.txt";
char* dirNameSDFS = "/sd/sdtest";
mkdir(dirNameSDFS, 0777);
#endif
// Write to a directory in SD.
filep = fopen(filePathAndNameSDFS, "wb");
if(filep == NULL) {
mygame.display.println("Could not open file for write!"); goto draw_loop;
}
// Init buffer
for(int32_t i=0;i<blockSize; i++) bufferOrg[i] = (char)i;
// Create 1MB file
start_ms = mygame.getTime();
for(int32_t i=0; i<totalFileSize; i+=blockSize) {
// read the block into the buffer:
len = fwrite (bufferOrg , sizeof(char), blockSize, filep);
if( len != blockSize ) {mygame.display.println("Could not write!"); goto draw_loop;}
}
fclose(filep);
stop_ms = mygame.getTime();
mygame.display.print("Wrote:");
if( stop_ms-start_ms > 0 )
mygame.display.print( totalFileSize/(stop_ms-start_ms) ); // b/ms == kb/s
else
mygame.display.print( 0 ); // b/ms == kb/s
mygame.display.println(" kb/s");
// Open file
filep = NULL;
filep = fopen(filePathAndNameSDFS, "rb");
if(filep == NULL) {
mygame.display.println("Could not open file for read"); goto draw_loop;
}
// Read from SD
start_ms = mygame.getTime();
for(int32_t i=0;; i+=blockSize) {
// read the block into the buffer:
len = fread (buffer, sizeof(char), blockSize, filep);
if (len != blockSize) break;
}
stop_ms = mygame.getTime();
fclose(filep);
// Check the result
for(int32_t i=0;i<blockSize; i++)
if(buffer[i] != bufferOrg[i]) {mygame.display.println("Invalid data!"); goto draw_loop;}
mygame.display.print("Read:");
if( stop_ms-start_ms > 0 )
mygame.display.print( totalFileSize/(stop_ms-start_ms) ); // b/ms == kb/s
else
mygame.display.print( 0 ); // b/ms == kb/s
mygame.display.println(" kb/s");
draw_loop:
while (mygame.isRunning()) {
if (mygame.update()) {
}
}
}
My_settings.h
#ifndef MY_SETTINGS_H
#define MY_SETTINGS_H
#define PROJ_HIRES 0 //1 = high resolution (220x176) , 0 = low resolution fast mode (110x88)
#define PROJ_ENABLE_SOUND 1 // 0 = all sound functions disabled
#define PROJ_STREAMING_MUSIC 1 // 1 = enable streaming music from SD card
#define PROJ_AUD_FREQ 11025
#define PROJ_STREAM_TO_DAC 1 // 1 use DAC for stream, 0 = use PWM for stream
#define PROJ_GBSOUND 0 // 1 = use Gamebuino-compatible sound interrupt
#define PROJ_ENABLE_SYNTH 0 // 1 = use Rboy-compatible sound interrupt
#define PROJ_USE_PWM 0 // 0 = Use only DAC for output
#endif