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

Thread: Added position offset to playSDraw

  1. #1
    Senior Member
    Join Date
    Dec 2014

    Added position offset to playSDraw

    Wanted to offer this to be added into the audio library but I am not fully understanding yet how to use github to do this.

    I attached the files here for you to consider merging

    adds playSkip, which allows the playback to begin from a time set by skip

  2. #2
    Senior Member
    Join Date
    Dec 2014
    also here is a function to generate a reversed copy of a file (should be small file dont get crazy now, takes a bit to render the reversed version)

    void reverseFile(char *from, char *to)
      long infile_offset;
      int bytes_read;
      uint16_t data[512];
      File fh_in;
      File fh_out;
      char debug[128];
      if (SD.exists(to)) {SD.remove(to);}
      fh_in =, FILE_READ);
      fh_out =, FILE_WRITE);
      Serial.println("generating debug string");
      sprintf(debug, "Reversing file %s, length %d\n", from, fh_in.size());
      infile_offset = (fh_in.size()/512)*512; /* should truncate to 512-byte boundary */
      while (infile_offset >= 0) {   ;
        bytes_read =, 512);
        reverseMem((uint16_t*)data, bytes_read/2);
        // sprintf(debug, "%d -> %d", infile_offset, fh_out.position());
        // Serial.println(debug);
        fh_out.write((char *)data, bytes_read);
        infile_offset -= 512;
    void reverseMem(uint16_t *data, int sampleCount)
      int i;
      uint16_t tmp;
      for (i=0; i<sampleCount/2-1; i++) {
        tmp = data[i];
        data[i] = data[sampleCount-i-1];
        data[sampleCount-i-1] = tmp;

  3. #3
    Senior Member
    Join Date
    Dec 2014
    It looks like receter posted some good stuff on the granular thread, I think you should actually adapt his loop object into the main play, but just have a loop enable

    it would be nice to have the loop start and end locked to nearest zero crossing as an option
    it could be useful to have a separate play start and play end variable so you can play a sound and have it start looping at a certain point after the beginning if wanted.
    Last edited by MacroMachines; 01-17-2016 at 03:05 PM.

Posting Permissions

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