newdigate / teensy-variable-playback

Firmware library: variable playback rate for teensy audio library
MIT License
54 stars 7 forks source link

AudioPlayResm common interface for AudioPlayArrayResmp and AudioPlaySDResmp #40

Closed atoktoto closed 3 years ago

atoktoto commented 3 years ago

I added a common class to both AudioPlayArrayResmp and AudioPlaySDResmp to make switching between those two easier. They already shared most of the API. I left the playWav and playRaw out of the interface and did not change them.

This change should be API-compatibile and not add too much of rigidity to the codebase.

The way I use it is to keep 3 pointers side-by-side:

    AudioPlayArrayResmp *arrayPlayer = NULL;
    AudioPlaySdResmp *sdPlayer = NULL;
    AudioPlayResmp *player = NULL;

Next, I assign them based on what is needed during construction:

    if(directPlay) {
        sdPlayer = new AudioPlaySdResmp();
        player = sdPlayer;
    } else {
        arrayPlayer = new AudioPlayArrayResmp();
        player = arrayPlayer;
    }

Thanks to this change I can keep the rest of the code independent of the source and only branch out the actual playWav:

    if(arrayPlayer != NULL) {
        playing = arrayPlayer->playWav((unsigned int *)sample->buf, sample->fileSize / 2);
    } else {
        playing = sdPlayer->playWav(sample->filename);
    }
newdigate commented 3 years ago

Perfect! That is great work!!! Thanks -- really appreciate your pull-requests! :)

newdigate commented 3 years ago

@atoktoto... Just let me know if you want me to push a new version to the Arduino Library Manager index...

atoktoto commented 3 years ago

I don't use Library Manager - I have it pulled as a git submodule.