How to erase/unload samples from PSRAM or Flash using flashloader

Cardinen

Member
Hi all,

I would like to know if there is a way to delete previously loaded samples in PSRAM or Flash using the Flashloader library. Here

I am working on a sampler based on this library but I have a problem, after loading several kits it seems that teensy crashes, it seems a memory related problem.

I searched on the library page but I did not find information on how to do this.

Thank you!
 
The library seems to only be able to load samples into PSRAM, but not delete them. I haven't used this library, but here is something you can try.

The library example contains this code to create flashloader and load a sample into PSRAM.
Code:
    newdigate::flashloader loader;
    kicksample = loader.loadSample("KICK.RAW");

where "kicksample" is declared like this:
Code:
newdigate::audiosample *kicksample;

You should have a variable like "kicksample", for each sample that you load into PSRAM. Let's say you have sample1, sample2, sample3, and you load them all into PSRAM using loadSample(). You can delete them all with the following code:
Code:
extmem_free(Sample1);
extmem_free(Sample2);
extmem_free(Sample3);

The PSRAM is being allocated dynamically, but I think if you delete all of the samples you have created, you should be back to the starting point and be able to load another set of samples. Let us know how it goes.
 
The flashloader library shows every sign of having been hacked together to fill an immediate need, without ever being properly finished ;). We've all been there ...

Unfortunately @joepasquariello hasn't quite finished the job, so the above fragment won't do what you want either. Here's my untested and possibly-not-working suggestion:D:
C++:
newdigate::flashloader myLoader;
newdigate::audiosample* mySample;

mySample = myLoader.loadSample("sampleFile.RAW"); // could be nullptr on failure - CHECK!
// now play the sample, then when you're done...
extmem_free(mySample->sampledata); // free the sample memory
delete mySample; // delete the structure created by loadSample()
mySample = nullptr; // indicate the sample isn't valid

A couple more points on the loader library. The ReadMe suggests you can't use WAV files, which is untrue (assuming you're also using the most recent TeensyVariablePlayback, which is 1.1.0 at the time of writing). And ... it calls itself a Flash loader, but as far as I can see doesn't support Flash memory at all!
 
I want to update you that the solution given by @h4yn0nnym0u5e works perfectly!
Now the samples are deleted correctly before reloading and Teensy does not crash anymore :)

I am currently playing Raw samples as I am having trouble updating the TeensyVariablePlayback library to 1.1.0.
After updating to v1.1.0 I was no longer able to compile with Teensyduino, so I have now reverted to the previous version.
I have reported the issue on Github

Thanks everyone for the support!
 
Glad to hear that’s working :)

I looked at your issue report, and it won’t get fixed if you can’t provide a simple example sketch to reproduce it. If you can do that, you’ll be doing future users a service - we may be able to fix a bug.

Oh, and err on the side of disbelieving anything that AI says about coding. You’d think it’d be good at that, but … no.
 
Ok thank you very much, then I will prepare an example sketch so you can see the error.

Yes I understand what you mean about AI with code
 
Hmmm … just looked again at your report, and this time spotted that you’re still on Teensyduino 1.57. That’s nearly 3 years old (the update cycle is more glacial than seasonal…), and more to the point, the gcc toolchain was updated in 1.58. I’d suggest you update at least to the latest release, 1.59, or if you’re feeling slightly brave, to the 1.60 beta.
 
Ahahah Ok! I will try to update Teensyduino and then I will try the library update, I will let you know... thanks again for the support! :)
 
Back
Top