Store › Forums › Audio Hacker › Discussion and Project Ideas › Changing the delay time
Tagged: Audio Hacker
- This topic has 13 replies, 3 voices, and was last updated 7 years, 11 months ago by Photoflash.
-
AuthorPosts
-
October 26, 2016 at 6:22 pm #8533CharlesMParticipant
Hi — I’m working to build a delay line with the Audio Hacker like the one mentioned a few topics back.
Unfortunately, this is my first project and I’m quite a noobie.I’m confused as to how to control the length of the delay.
Do I need to change:
delayValue
and does that change theechoDelay
?Any guidance would be helpful.
Thanks, Charles
October 27, 2016 at 5:13 pm #8539MichaelKeymasterHi Charles,
I think you are referring to this post: https://nootropicdesign.com/store/forums/topic/audio-delay-line/The original poster wanted to use buttons to control the delay amount instead of a pot, so that’s why he introduced the delayValue variable.
To control the delay amount, change echoDelay and make sure it is a multiple of 3. You may choose to control echoDelay with a pot on A0. The original code is:
echoDelay = analogRead(0) * 30;
and that means that echoDelay will have a value from 0-30690.
October 28, 2016 at 6:02 pm #8543CharlesMParticipantThanks very much for your help…
I’ll give this a try and maybe try buttons later. So far, I’m delaying a radio signal and it sounds fine at the default sampling rate.
December 5, 2016 at 5:22 pm #8625PhotoflashParticipantHowdy, Michael —
I’m still having a bit of trouble changing the length of the delay to more than the 2 seconds it produced originally.
I change
echoDelay = 24000
but that has no effect. Is there another delay modification that I’m not finding?Any help would be appreciated.
Thanks, Charles
December 6, 2016 at 8:33 am #8628MichaelKeymasterThat should be the only variable you change, replacing the analogRead(0) line. Please post your whole code surrounded by the code tags so it is formatted.
December 6, 2016 at 9:23 am #8629PhotoflashParticipantHere’s the code:
#include <AudioHacker.h> #define DEBUG unsigned int playbackBuf; unsigned int sampleRate; unsigned int readBuf[2]; unsigned int writeBuf; boolean evenCycle = true; unsigned int timer1Start; volatile unsigned int timer1EndEven; volatile unsigned int timer1EndOdd; unsigned long lastDebugPrint = 0; volatile long address = 0; unsigned int echoDelay; boolean echoWrapped = false; void setup() { #ifdef DEBUG Serial.begin(115200); // connect to the serial port #endif playbackBuf = 2048; sampleRate = DEFAULT_RECORDING_SAMPLE_RATE; timer1Start = UINT16_MAX - (F_CPU / sampleRate); AudioHacker.begin(); #ifdef DEBUG Serial.print("sample rate = "); Serial.print(sampleRate); Serial.print(" Hz"); Serial.println(); #endif } void 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. echoDelay = 24000; #ifdef DEBUG if ((millis() - lastDebugPrint) >= 1000) { lastDebugPrint = millis(); //each 3 echoDelay2 is 2 samples. unsigned int delayMillis = (float)(((float)((echoDelay * 2) / 3)) / (float)(sampleRate/1000.0)); Serial.print("echo delay = "); Serial.print(delayMillis); Serial.print(" ms even cycles remaining = "); Serial.print(UINT16_MAX - timer1EndEven); Serial.print(" odd cycles remaining = "); Serial.print(UINT16_MAX - timer1EndOdd); Serial.println(); } } #endif ISR(TIMER1_OVF_vect) { TCNT1 = timer1Start; unsigned int signal; unsigned int echo; int mix; AudioHacker.writeDAC(playbackBuf); // Read ADC signal = AudioHacker.readADC(); if (evenCycle) { long echoAddress = address - echoDelay; if (echoAddress < 0) { echoAddress += MAX_ADDR; } AudioHacker.readSRAMPacked(0, echoAddress, readBuf); if ((!echoWrapped) && (echoAddress > address)) { // avoid reading from unwritten memory echo = 2048; readBuf[1] = 2048; } else { echo = readBuf[0]; } } else { echo = readBuf[1]; } if (echoDelay == 0) { echo = 2048; } if (evenCycle) { writeBuf = signal; } else { AudioHacker.writeSRAMPacked(0, address, writeBuf, signal); address += 3; if (address > MAX_ADDR) { address = 0; echoWrapped = true; } } playbackBuf = echo; #ifdef DEBUG if (evenCycle) { timer1EndEven = TCNT1; } else { timer1EndOdd = TCNT1; } #endif evenCycle = !evenCycle; }
December 7, 2016 at 9:26 am #8633MichaelKeymasterSo, changing echoDelay to different values has no effect at all? How long is the delay when you use a value of 24000? What do you hear? What happens when you change it to 9000? It must be divisible by 3.
December 7, 2016 at 3:36 pm #8635PhotoflashParticipantChanging the echoDelay value seems to have no audible effect at all. I’ve tried many different values from around 300 to 48000 (all divisible by 3), and I can’t hear, or measure with a stopwatch, any significant change in the delay, which is consistently around 2 sec.
But when I use a very high value, such as 90000, it produces a lot of feedback-like noise, so there definitely is a maximum limit.
I’m not using any pots, but just changing the value in the code and uploading to the Audio Hacker to test it out.
December 7, 2016 at 10:04 pm #8636MichaelKeymasterHmm. This is strange. I don’t see anything wrong with this code. Did you ever use this echo example with a potentiometer? Did it ever work?
I’m not home right now (on a business trip), but will try this code when I get back to my lab.December 9, 2016 at 4:08 pm #8644PhotoflashParticipantI have the DJ Shield (unassembled, unfortunately) so I’ll put that together and try using a pot with the echo example. Hopefully, I’ll get to it this weekend.
December 10, 2016 at 11:54 am #8645MichaelKeymasterPhotoflash, I have tried your code above and it works fine for me. A small value for echoDelay gives a small delay, and a large value gives a longer delay. I do not know why this would not work for you. Are you sure you are making the code change then uploading the change successfully to the device?
With the variable echoDelay declared as unsigned int, the max value is 65535. But for longer delays change the declaration of echoDelay to an unsigned long:
unsigned long echoDelay;
Then you can use a maximum delay value of 131067 which gives a day of about 4 seconds.
December 14, 2016 at 10:22 am #8654PhotoflashParticipantThanks for the tip… I changed echoDelay to
unsigned long echoDelay;
and now have a 4 second delay maximum.Do you have any thoughts on how I can reach the 8.6 second maximum, as in the documentation?
December 14, 2016 at 7:43 pm #8657MichaelKeymasterThe echo example only uses one of the chips for simplicity. That is why the delay is only 4 seconds. If you want it to use both chips, you’d have to modify the code, but the logic becomes more complex to use both chips.
December 15, 2016 at 9:36 am #8658PhotoflashParticipantWell, that is disappointing.
Thanks anyway…
-
AuthorPosts
- You must be logged in to reply to this topic.