Audio Delay line

Store Forums Audio Hacker Discussion and Project Ideas Audio Delay line

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by  Michael Krumpus 9 months, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #720

    Daveed
    Member

    I want to build a simple delay line. I figure I would repurpose the sketch for the Echo Effect http://nootropicdesign.com/projectlab/2013/07/05/echo-effect/

    I just need to get rid of the direct signal (dry) and the echos.

    I tried commenting the following block.

    // mix = signal-2048;<br />
    // echo = echo >> 1; // attenuate echo<br />
    mix += (echo - 1024); // since we are dividing echo by 2, decrement by 1024<br />
    // if (mix < -2048) {<br />
    //   mix = -2048;<br />
    // } else {<br />
    //   if (mix > 2047) {<br />
    //     mix = 2047;<br />
    //   }<br />
    // }<br />
    playbackBuf = mix + 2048;

    It gets rid of the dry signal but I still get the echos. How can I get rid of the echos?

    Also:

    Can I assign the buttons on S1, S2 on the shield to change the echo delay in ms, How?

    And the last step is, I would like to output the delay value in milliseconds to a LCD display, any help with any of this item would be very much appreciated.

    • This topic was modified 1 year ago by  Michael Krumpus. Reason: fixed link
    #2039

    Michael Krumpus
    Keymaster

    When you say you hear “echoes” (plural), what do you mean? There is the original signal in realtime and it is mixed with the delay read from memory (this is variable “echo”). I think you just want to hear the delay.

    You should replace this code:

    mix = signal-2048;
    echo = echo >> 1; // attenuate echo
    mix += (echo - 1024); // since we are dividing echo by 2, decrement by 1024
    if (mix < -2048) {
    mix = -2048;
    } else {
    if (mix > 2047) {
    mix = 2047;
    }
    }
    playbackBuf = mix + 2048;

    with this simple code:


    playbackBuf = echo;

    As for using the switches to set the delay, yes, it’s easy to use Arduino digitalRead(pin) to read whether a button is pressed or not. You could use one button to increase the delay, and another to decrease.


    setup() {
    ...
    pinMode(5, INPUT_PULLUP);
    pinMode(6, INPUT_PULLUP);
    }
    ...

    loop() {
    if (digitalRead(5) == LOW) {
    delay++;
    }
    if (digitalRead(6) == LOW) {
    delay--;
    }
    ...
    }

    You probably are not going to be able to drive an LCD while processing audio. The timing of the audio processing must be precise, and peripheral communication using interrupts will mess it up.

    #2046

    Daveed
    Member

    Wow, that is perfect, thanks.
    That code seems pretty straight forward and does what I want, a simple echo.

    When I tried this code for the buttons to increment the delay:

     pinMode(5, INPUT_PULLUP);
    pinMode(6, INPUT_PULLUP);
    }
    ...

    loop() {
    if (digitalRead(5) == LOW) {
    delay++;
    }
    if (digitalRead(6) == LOW) {
    delay--;
    }
    ...
    }

    I get:

    “error: ISO C++ forbids incrementing a pointer of type ‘void (*)(long unsigned int)'”

    but I changed to:



    Global variable

    int a = 25; // make a variable I can control with buttons and ++

    setup() {
    ...
    pinMode(5, INPUT_PULLUP);
    pinMode(6, INPUT_PULLUP);
    }
    ...

    loop()


    delay(300);
    // echoDelay is number of memory slots back into the past to read for the echo.
    // must be a factor of 3 because we pack 2 samples into each 3-byte sequence of SRAM.


    int delayValue = 3 * a; //mulyply by 3 for 3-byte SRAM

    echoDelay = analogRead(0) * delayValue;

    {
    if (digitalRead(5) == LOW) {

    a++;


    }
    if (digitalRead(6) == LOW) {

    a--;

    }

    // code for two buttons press at the same tim
    if (digitalRead(5) == LOW && digitalRead(6) == LOW){
    Serial.println();
    Serial.print("BOTH SWITCHES");

    Serial.println();
    }


    }

    and that works well.
    Although I am sure they are more elegant ways to do that.

    Do you think is possible just to query the system to get the delay value to the LCD ? Pressing both buttons, for example, just to send the data to the LCD once, without affecting the the delay too much

    #2047

    Michael Krumpus
    Keymaster

    Ok, sounds like you have your delay working.

    I haven’t ever interfaced with an LCD and don’t have one, so I can’t comment on how well it would work. I think it would work, but you need lots of pins. The Audio Hacker uses pins 5-13, so you have pins 2,3,4 and the analog pins A0-A5 which can be used as digital pins if you refer to them as 14-19. Have a look at this:
    http://arduino.cc/en/Tutorial/LiquidCrystal

    #8777

    jlast
    Participant

    I need an audio delay line; read audio input and send it to the output with a programmable delay (up to 1 sec). Can I do this with a sampling rate of 16 kHz?

    #8779

    Michael Krumpus
    Keymaster

    Yes, you should be able to record and then playback delayed at 16KHz.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.