Forum Rule: Always post complete source code & details to reproduce any issue!
-
Teensy-Based Sampler: "dynamic" Memory Allocation?
I have a Teensy with some extra RAM soldered on. I can play a modest amount of uncompressed WAV samples I load from SD.
This is a multitimbral sampler and I want to be able to switch samples quickly: I want to have Voice One load a sample, play it, and then if I switch to another "kit" I want it load another sample at runtime.
I can define blocks of memory to load my samples from SD.
EXTMEM char MEM_BLOCK_1[MAX_EXTMEM];
EXTMEM char MEM_BLOCK_2[MAX_EXTMEM];
EXTMEM char MEM_BLOCK_3[MAX_EXTMEM]; etc
But, this is not efficient because some samples are short, and some are long. I tend to waste memory by giving each "sample voice" in my multitimbral sample and equal amount of fixed memory.
I think I'm missing something. It looks like some folks use Flash memory to hold samples, and thereby eliminate the need for a "Teensy Memory Manager" that can malloc and free EXTMEM without fragmentation. But I'm not quite seeing the connection.
So I have two questions.
1) Can I quickly load, and then swap a sample from flash memory? Can I do it a thousand times without a hitch?
2) Just curious, are there "memory management libraries" you can use in a Teensy without embracing a complete RTOS paradigm?
( I would expect I could pass a big block of EXTMEM into a library and it would handle allocation/deallocation. )
I know these are multiple divergent questions, but I would appreciate any ideas.
Thanks,
Ben
-
...What I'm implying is I want it to act like a sampler that can pull in samples from SD at runtime without hard-coding any samples as constants or as resources that get loaded in on setup().
-
Senior Member+
Dynamic allocation is with sm_alloc() given external QSPI RAM
Some info here: forum.pjrc.com/threads/63695-malloc-free-for-EXTMEM-and-DTCM?highlight=sm_malloc
It has some smarts about maintaining the memory pool integrity ... that thread even had a graphic display IIRC across some test allocations.
-
Awesome, thank you. I'll give it a try.
-
-
Senior Member+

Originally Posted by
blakeAlbion
Good heavens!
It works.
Awesome indeed!
-
Hi blakeAlbion!
Could you share code for your solution, I have been battling the exact same problem with sample playing from SD, but memory allocation is still a bit too much for my skills at the moment.
It would be super-helpful if I could get a working example code of how you got it working.
At the moment, I have been using WaveplayerEx library for playing straight from the SD card, but that has still some limitations regarding polyphony. What kind of polyphony are you achieving with your code?
Best,
Miro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules