i want to do playback speed slower/faster in realtime without affect pitch. by search in google i found it is possible thru granular.
as below simple sketch i wrote my 2sec audio files are loaded to PSRAM . Then they are played well by
i tried very much to find simple use of granular in Arrayplayback . but i could not found simple or not understand complex use of this object
could you please reply how to add
thank you.....
as below simple sketch i wrote my 2sec audio files are loaded to PSRAM . Then they are played well by
playArray from serial INPUT.
C++:
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
AudioPlaySdResmp playSdWav1;
AudioPlaySdResmp playSdWav2;
AudioPlayArrayResmp playArrayWav1;
AudioPlayArrayResmp playArrayWav2;
AudioPlayArrayResmp playArrayWav3;
AudioPlayArrayResmp playArrayWav4;
AudioPlayArrayResmp *playArray[] = {
&playArrayWav1,
&playArrayWav2,
&playArrayWav3,
&playArrayWav4};
AudioMixer4 mixer1;
AudioMixer4 mixer2;
AudioOutputI2S i2s2;
AudioConnection patchCord1(playSdWav1, 0, mixer2, 0);
AudioConnection patchCord2(playSdWav1, 0, mixer2, 1);
AudioConnection patchCord3(playArrayWav1, 0, mixer1, 0);
AudioConnection patchCord4(playArrayWav2, 0, mixer1, 1);
AudioConnection patchCord5(playArrayWav3, 0, mixer1, 2);
AudioConnection patchCord6(playArrayWav4, 0, mixer1, 3);
AudioConnection patchCord7(mixer1, 0, i2s2, 1);
AudioConnection patchCord8(mixer1, 0, i2s2, 0);
AudioControlSGTL5000 audioShield;
#define NUM_WAVS 16 // avoid silly mistakes
float Speed = 1.00;
const char *SMP_WAV[NUM_WAVS] = { "01.WAV", "02.WAV", "03.WAV", "04.WAV", "05.WAV", "06.WAV", "07.WAV", "08.WAV", "09.WAV", "10.WAV", "11.WAV", "12.WAV", "13.WAV", "14.WAV", "15.WAV", "16.WAV" };
File x_File;
int16_t *SMP_addr[NUM_WAVS];
uint32_t sizes[NUM_WAVS];
void setup() {
Serial.begin(57600);
if (!(SD.begin(BUILTIN_SDCARD))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
AudioMemory(128);
audioShield.enable();
audioShield.volume(0.5);
for (int i = 0; i < 4; i++) {
playArray[i]->enableInterpolation(true);
}
RAM_LOAD ();
}
void loop() {
//----------------------SERIAL.AVALABLE CODE-------------------------
if (Serial.available() > 0) {
String incomingByte = Serial.readString();
incomingByte.trim(); //
if ( incomingByte == "1") { playArray[1]->playWav(SMP_addr[1]);
playArray[1]->setLoopType(looptype_repeat);
}
if ( incomingByte == "2") { playArray[2]->playWav(SMP_addr[2]); }
if ( incomingByte == "0") { playArray[1]->stop(); playArray[2]->stop(); }
if ( incomingByte == "8") {
Speed = Speed+0.05;
// APPLY GRANULAR SPEED
}
if ( incomingByte == "9") {
Speed = Speed-0.05;
// APPLY GRANULAR SPEED
}
}
//----------------------SERIAL.AVALABLE-CODE------------------------
}
void RAM_LOAD () {
int SMP_FILE_NUM=0;
for (int i = 0; i < NUM_WAVS; i++) {
x_File = SD.open(SMP_WAV[i], FILE_READ);
if (x_File)
{
sizes[i] = x_File.size();
SMP_addr[i] = (int16_t*) extmem_malloc(sizes[i]);
if (nullptr == SMP_addr[i])
Serial.printf("Failed to allocate %d in EXTMEM for %s\n", sizes[i], SMP_WAV[i]);
else {
if (sizes[i] != x_File.read(SMP_addr[i], sizes[i]))
{
Serial.printf("Failed to read in %s - wrong length\n", SMP_WAV[i]);
extmem_free(SMP_addr[i]); // free memory
SMP_addr[i] = nullptr; // mark as "not loaded"
}
else
Serial.printf("Read %s into memory at %08X; %d bytes\n", SMP_WAV[i], SMP_addr[i], sizes[i]);
}
x_File.close();
}
else
Serial.printf("Failed to open %s\n", SMP_WAV[i]);
}
}
could you please reply how to add
Granular object in my code to get playback slower / faster with variable Speed in my code. thank you.....