Memory allocation for short sample playback

Status
Not open for further replies.

blakeAlbion

Well-known member
Hello,
Let’s call what I am working on a “drum machine”.
My drum machine needs to allow the user to select a short 16 bit mono pcm wav file from a library of sounds on the SD card. If possible I would like to load the sound once and retain it in memory. I borrowed the nice wav parser in the SD wav playback component and I am able to play the data chunk from memory.
Here’s my problem. The memory seams to be *volatile*. All I have to do is load another sample to hear my previous sample fragmented or overwritten.
What is the correct way to do this? I am simply declaring an array as an auto-variable on the heap, so I think it goes out of scope when my load function exits. Do I need to use a new() to create a pointer as a member variable to my class, and memcpy() into that buffer?
I’m naive about memory best practices for this little computer slab.

I know this is a case where seeing some code helps. It’s likely just reviewing my own code enough to post it will help me, so I will do that when I have time later this week.

Thanks!
 
Status
Not open for further replies.
Back
Top