Looping a sound in memory

Status
Not open for further replies.
I've revived my audio project (thanks to gentle nudging in another thread that convinced me to stick with the Audio board), and need to play some continuous sounds in a program (TL;DR: I'm making an electronic bagpipe practice chanter, and need to have one loop for the drones play constantly, and then a file for each note loop as long as the note is played).

I'm using wav2sketch to convert them to in-memory samples, and then naively thought I would do this
- start the sound as appropriate
- stop it when appropriate
- if it finishes but should keep playing, start it again (by checking !isPlaying()).

This sort of works, EXCEPT I realize that the sounds play in chunks of AUDIO_BLOCK_SAMPLES size, and (I assume) wav2sketch pads out the end of the data array with zeros if it's not the right size.

I've edited the sounds in Audacity to make them sound ok when they loop, but (obviously) a bit of silence between each loop causes pops.

My question, then, is: what's the appropriate way to deal with this? It would seem that the only way for the play_memory functions to work if I wanted to loop the audio is to ensure the input is a multiple of AUDIO_BLOCK_SAMPLES in size.

Intuitively, it would seem that I should ensure the audio file is a multiple of AUDIO_BLOCK_SAMPLES, since otherwise looping would be impossible. But, I just wanted to sanity check this, before redoing the audio.
 
To answer my own question: yes, ensuring the audio file is the exact length cleans up the looping.

The exact size needed is a function of the audio rate. In wav2sketch we see this:
Code:
        // AudioPlayMemory requires padding to 2.9 ms boundary (128 samples @ 44100)
        if (rate == 44100) {
                padlength = padding(length, 128);
                format = 1;
        } else if (rate == 22050) {
                padlength = padding(length, 64);
                format = 2;
        } else if (rate == 11025) {
                padlength = padding(length, 32);
                format = 3;
        }

So I needed 128.
 
Status
Not open for further replies.
Back
Top