spritemusketeer
Member
Hi everyone,
I have just started using Teensy after years of pics and Arduino, loving the the ability to work with audio!
I have just been trying to see if its possible to play an audiofile along side a synced midi clock. I figured it could be accurately done by adapting the "Blink While Playing" sketch and grabbing the time from positionMillis() and then using this to send a clock message through a midi breakout (which I have had working in another sketch just using a delay). But when I recreate it with a serial debug it seems the messages are not every 21ms . There is lots of skipping so maybe this is not a good way of doing it at all.
Start playing
Playing, now at 63 ms
Playing, now at 84 ms
Playing, now at 147 ms
Playing, now at 252 ms
Playing, now at 336 ms
Playing, now at 420 ms
Playing, now at 504 ms
Playing, now at 588 ms
Playing, now at 609 ms
Playing, now at 693 ms
Playing, now at 777 ms
Playing, now at 861 ms
If anyone has tried to do this or knows a good way to sync the audio with a midi clock I would love to know.
Code is below.
Many thanks
Simon
void loop() {
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("HELLO2.WAV");
delay(10); // wait for library to parse WAV info
}
if (playSdWav1.positionMillis()%21 == 0 && clockSent == 0) {
// print the play time offset
Serial.print("Playing, now at ");
Serial.print(playSdWav1.positionMillis());
Serial.println(" ms");
clockSent = 1;
}
if (playSdWav1.positionMillis()%22 == 0) {
// clock
clockSent = 0;
}
// read the knob position (analog input A2)
/*
int knob = analogRead(A2);
float vol = (float)knob / 1280.0;
sgtl5000_1.volume(vol);
Serial.print("volume = ");
Serial.println(vol);
*/
}
I have just started using Teensy after years of pics and Arduino, loving the the ability to work with audio!
I have just been trying to see if its possible to play an audiofile along side a synced midi clock. I figured it could be accurately done by adapting the "Blink While Playing" sketch and grabbing the time from positionMillis() and then using this to send a clock message through a midi breakout (which I have had working in another sketch just using a delay). But when I recreate it with a serial debug it seems the messages are not every 21ms . There is lots of skipping so maybe this is not a good way of doing it at all.
Start playing
Playing, now at 63 ms
Playing, now at 84 ms
Playing, now at 147 ms
Playing, now at 252 ms
Playing, now at 336 ms
Playing, now at 420 ms
Playing, now at 504 ms
Playing, now at 588 ms
Playing, now at 609 ms
Playing, now at 693 ms
Playing, now at 777 ms
Playing, now at 861 ms
If anyone has tried to do this or knows a good way to sync the audio with a midi clock I would love to know.
Code is below.
Many thanks
Simon
void loop() {
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("HELLO2.WAV");
delay(10); // wait for library to parse WAV info
}
if (playSdWav1.positionMillis()%21 == 0 && clockSent == 0) {
// print the play time offset
Serial.print("Playing, now at ");
Serial.print(playSdWav1.positionMillis());
Serial.println(" ms");
clockSent = 1;
}
if (playSdWav1.positionMillis()%22 == 0) {
// clock
clockSent = 0;
}
// read the knob position (analog input A2)
/*
int knob = analogRead(A2);
float vol = (float)knob / 1280.0;
sgtl5000_1.volume(vol);
Serial.print("volume = ");
Serial.println(vol);
*/
}