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

Thread: Recorder code hack

  1. #1

    Recorder code hack

    Hi,

    I just got myself a teensy board and an audio shield.
    I'm new to programing so this project might be a bit over the top for me...

    My question is concerning this exemple code on the audio shield git:
    https://github.com/PaulStoffregen/Au...e9f7f4443cd3b5

    I want to add a potentiometer that set how many seconds de recording mode is recording and also i would like to implement a loop mode switch.
    Adding a "pitch/how fast the sample is read" potentiometer would also be great, would this be possible too?

    Can anyone point me the right direction to this project?

    kind regards,
    manatee

  2. #2
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Quote Originally Posted by manatee View Post
    I want to add a potentiometer that set how many seconds de recording mode is recording and also i would like to implement a loop mode switch.
    That should be fairly simple on both counts.

    Quote Originally Posted by manatee View Post
    Adding a "pitch/how fast the sample is read" potentiometer would also be great, would this be possible too?
    Not so easy; you can only record at 44.1xxxx kHz, which the library natively runs at.

    You'll need to process before storing it, or even better just play it back at a different frequency instead; the audio library is very young and this is not an easy task as it would be with DirectX.

    But yes, it is possible to pipe the recording buffer into a wavetable object and play it back at a different pitch.

  3. #3
    Senior Member
    Join Date
    Jan 2015
    Location
    frisia
    Posts
    285
    If you don't need to record and play back at the same time, you can adjust the sampling clock, to get a higher/lower pitch, using the code in https://forum.pjrc.com/threads/27736...ll=1#post64299

  4. #4
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    2 solutions!!!



    There's always a way

  5. #5
    hey also looking for something like this.

    changing the sampling clock would affect all the samples though?

    Looking at the mozzi sample code which can do this nicely, looks like it is implemented with a wavetable player too.
    How would you go about doing this?
    I am looking at the synth_waveform files to modify and looks like the wavetables are read from the AudioWaveformSine array? Do I have to make it read from the 'next' block off the sample player or can I load the whole sample as a wavetable?

    EDIT:
    oooh just noticed arbitraryWaveform(). But again how would I stream from AudioPlayMemory or AudioPlaySdWav?
    Last edited by poltergeist; 04-06-2015 at 10:41 AM.

  6. #6
    Haaah was as simple as adding a couple of lines in the play_memory.cpp file.
    phase_incr is a float multiplier of the playback speed. 1 is normal speed, 0.5 half speed, 2, double speed. Tried it with a square wave playing C note, seems to be okay.

    Code:
    index = phase;
    
    tmp32 = in[index];
    *out++ = (int16_t)(tmp32 & 65535);
    *out++ = (int16_t)(tmp32 >> 16);
    			
    phase += phase_incr;
    if(phase>=sampleSize-1){
     break;
    }
    so as far as I understand, length is the number of bytes left until the end of the sample? beginning is a pointer to the second byte of the sample and format is the first byte file header containing the encoder type and length?

    I'm little confused how length is working though.
    My sample has 6849 entries in the array. but length is reading 13656.
    Last edited by poltergeist; 04-08-2015 at 04:30 PM.

  7. #7
    Senior Member
    Join Date
    Jan 2015
    Location
    frisia
    Posts
    285
    Don't know the code you are talking about, but probably: each entry is 16 bit, the number of bytes is therefore double the amount of entries.

  8. #8
    Its here
    https://github.com/PaulStoffregen/Au...lay_memory.cpp

    https://youtu.be/NS1UVMhnrFA
    This is what I have so far. I had to use a filter on the kick to remove the horrible digital ring modulator effect when setting the sample speed below 1. But negative (reverse) speeds work nicely, with no 8bit noise sounds.. Bout should probably try to make it more proper, with a circular buffer and re sampling. What I am doing right now must be very unorthodox. Although I tried to implement linear interpolation too, I doubt I pulled it off correctly, but also having some issues with envelope and filters.. (probably should start a new thread about all this..)
    Last edited by poltergeist; 04-22-2015 at 10:58 PM.

  9. #9
    Wow! That's awesome. I'm personally building a small digital sampling / playback box for my live shows, could you possibly give a small example of the arduino code using your variable playback speed trick?

  10. #10
    also, where in "play_memory.cpp" should i drop your little additional bit of code? dropping it at the end of the code pulls errors when compiling

    in any event, any additional information at all would be greatly appreciated!
    Last edited by A. Williams; 05-08-2015 at 12:00 AM.

Posting Permissions

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