Rolfdegen
Well-known member
When loading a new sample, the _bytesavailable variable doesn't seem to be reset. I've changed that in the code. Additionally, the framebuffer function for the display is disabled before loading a sample and enabled again after loading. Everything seems to be working now. Hope dies last ;-)
C:
// press patch list on page1 -----------------------------------
void press_patch_list_page1()
{
uint8_t new_index = 0;
static uint8_t old_index = 0;
static uint8_t old_key_index = 1;
new_index = touch_patch_list();
if (new_index != old_index)
{
old_index = new_index;
if (new_index >= 1 && new_index <= 7)
{
if (new_index != old_key_index)
{
old_key_index = new_index;
// stop all samples
for (size_t i = 0; i < 8; i++)
{
sampleOsc[i].stop();
}
sample_busy_flag = false;
extmem_free(Sample->sampledata);
delete Sample;
Sample = nullptr;
print_file_List(new_index - 1);
tft.updateScreenAsync(false); // update screen
tft.useFrameBuffer(false); // disabled Frame Buffer
tft.updateChangedAreasOnly(false);
// loading new Sample
String Folder = "Samples/";
String name_ = Folder + fileNames[new_index - 1];
char *_filename = const_cast<char *>(name_.c_str());
Sample = loader.loadSample(_filename);
sample_busy_flag = true;
// enabled frame buffer
tft.useFrameBuffer(true);
tft.updateChangedAreasOnly(true);
}
}
else if (new_index == 0)
{
for (size_t i = 0; i < 7; i++)
{
TK_state_List_P1[i] = false; // clear touch state
}
}
}
if (new_index > 0)
{
Reset_screensaver();
}
}
C:
#ifndef PSRAMLOADER_H
#define PSRAMLOADER_H
#include <Arduino.h>
#include <SD.h>
extern "C" uint8_t external_psram_size;
namespace newdigate {
const uint32_t flashloader_default_sd_buffersize = 4 * 1024;
struct audiosample {
int16_t *sampledata;
uint32_t samplesize;
};
class Psramloader {
public:
Psramloader() {
_bytesavailable = external_psram_size * 1048576;
}
uint32_t _bytesavailable = 0;
audiosample * loadSample(const char *filename);
};
};
#endif
C:
#include "psramloader.h"
#include <Audio.h>
namespace newdigate {
audiosample * Psramloader::loadSample(const char *filename ) {
uint8_t *data = nullptr;
_bytesavailable = external_psram_size * 1048576;
Serial.printf("Reading %s\n", filename);
File f = SD.open(filename, O_READ);
if (f) {
if (f.size() < _bytesavailable) {
AudioNoInterrupts();
uint32_t total_read = 0;
data = (uint8_t*)extmem_malloc(f.size());
uint8_t *index = data;
while (f.available()) {
size_t bytesRead = f.read(index, flashloader_default_sd_buffersize);
if (bytesRead == 0)
break;
total_read += bytesRead;
index += bytesRead;
}
AudioInterrupts();
_bytesavailable -= total_read;
audiosample *sample = new audiosample();
sample->sampledata = (int16_t*)data;
sample->samplesize = f.size();
Serial.printf("\tsample start %x\n", (uint32_t)data);
Serial.printf("\tsample size %d\n", sample->samplesize);
Serial.printf("\tavailable: %d\n", _bytesavailable);
return sample;
}
}
Serial.printf("not found %s\n", filename);
return nullptr;
}
}
Last edited: