Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Memory allocation for short sample playback

  1. #1
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    99

    Memory allocation for short sample playback

    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!

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    666
    Follow the forum rule and we'll likely find the bug...

  3. #3
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    99
    Fair enough, thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •