Hi, I had a hack at a set of files for you to work on. They will do a basic reverser like your Nootropic link in post #1.
The example is set up to take audio through line in but you should be able to change to a mic.
There is no crossfading so you'll get some pops and clicks.
Cheers, Paul
example.ino
Code:
#include <Audio.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <Wire.h>
#include "effect_reverser.h"
// GUItool: begin automatically generated code
AudioInputI2S i2s1; // xy=188,102
AudioEffectReverser reverser; // xy=408,104
AudioOutputI2S i2s2; // xy=619,107
AudioConnection patchCord1(i2s1, 0, reverser, 0);
AudioConnection patchCord2(reverser, 0, i2s2, 0);
AudioConnection patchCord3(reverser, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; // xy=211,214
// GUItool: end automatically generated code
#define DELAYLINE_MAX_LEN 80000 // number of samples at 44100 samples a second
int16_t delay_line[DELAYLINE_MAX_LEN] = {};
void setup() {
// Enable the audio shield and set the output volume.
sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
sgtl5000_1.volume(0.5);
// alocate some audio memory, don't need much as passing an array to the effect
AudioMemory(15);
// start up the effect and pass it an array to store the samples
reverser.begin(delay_line, DELAYLINE_MAX_LEN);
}
void loop() {
// do stuff
}
header file for custom effect
effect_reverser.h
Code:
#ifndef effect_reverser_h_
#define effect_reverser_h_
#include "Arduino.h"
#include "AudioStream.h"
class AudioEffectReverser : public AudioStream {
public:
AudioEffectReverser(void) : AudioStream(1, inputQueueArray) {}
// initialise the delay line
void begin(int16_t *delay_line, uint32_t max_delay_length);
// main update routine
virtual void update(void);
void inspect(void) { dump_samples = true; };
private:
audio_block_t *inputQueueArray[1];
uint32_t max_delay_length_samples, half_delay_length_samples; // lenght of the delay line in samples
uint32_t write_index; // write head position
uint32_t read_index; // read_index
int16_t *sample_delay_line; // pointer to delay line
boolean buffer_filled = false;
boolean dump_samples = false;
};
#endif
effect_reverser.cpp
Code:
#include <Arduino.h>
#include "effect_reverser.h"
void AudioEffectReverser::begin(int16_t *delay_line, uint32_t max_delay_length) {
sample_delay_line = delay_line;
max_delay_length_samples = max_delay_length - 1;
read_index = half_delay_length_samples = max_delay_length_samples / 2;
write_index = 0;
}
void AudioEffectReverser::update(void) {
audio_block_t *block;
int16_t *block_pointer;
// check if have a delay line
if (sample_delay_line == NULL) return;
// grab the block of samples as writeable
block = receiveWritable();
if (block) {
block_pointer = block->data;
// process each smaple in the block
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
// write the sample to a buffer
sample_delay_line[write_index++] = *block_pointer;
// if enought in the buffer start reversing
if (write_index >= half_delay_length_samples) buffer_filled = true;
if (buffer_filled) *block_pointer = sample_delay_line[read_index--];
// wrap round the write index
if (write_index >= max_delay_length_samples) write_index = 0;
// wrap round the read index
if (read_index == 0) read_index = max_delay_length_samples;
// move the block_pointer on
block_pointer++;
}
// transmit the block out on channel 0
transmit(block, 0);
release(block);
}
}