Amazing work here, thanks for all of your efforts.
I've been having trouble returning lengthMillis and positionMillis using this library. They always return zero no matter what I try. Looking at playsdresmp.cpp I see AudioPlaySdResmp::lengthMillis() and AudioPlaySdResmp:: positionMillis() differs from play_sd_wav.cpp in the Audio library (I can get the Audio library to work as expected).
Has anyone had success returning millis? Sample sketch below.
Thanks for any ideas. I'm brand new to Teensy and having loads of fun so far.
Code:
// Plays a Wav (16-bit signed) PCM audio file at slower or faster rate
// this example requires an uSD-card inserted to teensy 3.6 with a file called DEMO.WAV
// https://github.com/newdigate/teensy-variable-playback
// Unable to return lentgthMillis and positionMillis?
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <Bounce.h>
#include <TeensyVariablePlayback.h>
int mode = 0; // 0=stopped, 1=recording, 2=playing
// GUItool: begin automatically generated code
AudioPlaySdResmp playSdWav1; //xy=324,457
AudioOutputI2S i2s2; //xy=840.8571472167969,445.5714416503906
AudioConnection patchCord1(playSdWav1, 0, i2s2, 0);
AudioConnection patchCord2(playSdWav1, 0, i2s2, 1);
AudioControlSGTL5000 audioShield;
// GUItool: end automatically generated code
//#define A14 10
char* _filename = "SDTEST1.WAV";
const int analogInPin = A14;
unsigned long lastSamplePlayed = 0;
double getPlaybackRate(int16_t analog) { //analog: 0..1023
return (analog - 512.0) / 512.0;
}
Bounce buttonMillis = Bounce(29, 8);
Bounce buttonPlay = Bounce(31, 8);
void setup() {
pinMode(29, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
analogReference(0);
pinMode(analogInPin, INPUT); // i.e. Analog
Serial.begin(57600);
if (!(SD.begin(BUILTIN_SDCARD))) {
// stop here if no SD card, but print a message
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
AudioMemory(24);
audioShield.enable();
audioShield.volume(0.5);
playSdWav1.enableInterpolation(true);
int newsensorValue = analogRead(analogInPin);
playSdWav1.setPlaybackRate(getPlaybackRate(newsensorValue));
}
void loop() {
buttonMillis.update();
buttonPlay.update();
if (buttonMillis.fallingEdge()) {
Serial.println("Millis Pressed");
getMillis();
}
if (buttonPlay.fallingEdge()) {
Serial.println("Play Pressed");
if (mode == 0) startPlaying();
}
int newsensorValue = analogRead(analogInPin);
playSdWav1.setPlaybackRate(getPlaybackRate(newsensorValue));
}
void startPlaying() {
Serial.println("Start Playback");
playSdWav1.playWav(_filename);
mode = 2;
}
void getMillis(){
Serial.print("positionMillis() = ");
Serial.println(playSdWav1.positionMillis());
Serial.print("lengthMillis() = ");
Serial.println(playSdWav1.lengthMillis());
}
namespace std {
void __throw_bad_function_call() {}
void __throw_length_error(char const*) {}
}