Dear all,
This audio library astonished me, so much functionality which is so easy to use.
Last couple of days I have been trying to use the library for my specific purpose. I want to use cheap and lightweight hardware to record sound from a tape. The choices for hardware result in velocity variations up to 400Hz. By using an 800 ppr encoder, I are able to measure velocity and compensate these variations. I made a post-processing implementation and it works, now I would like to implement a real-time using the Teensy 3.6. I want to compensate the velocity variations by changing the samplerate of the Teensy 3.6 + SGTL5000 accordingly. I would like to use the Teensy as an USB audio device with a fixed sample rate.
It's is perfect if the nominal sample rate is constant, thus the sample rate of the audio device is fixed, say the default 44117 Hz. However , the momentarily sample rate of the SGTL5000 (i2c) will change accordingly with the measured variations. So if the tape is going to fast, we increase the sample rate and vice versa. I will need to buffer the incoming samples and pass them to the USB at the desired nominal rate.
I am pretty sure the audio library implements all required functionalities already, including a buffer using the audio memory pool. However, when I change the sample rate of the i2c, I get distorted sound. For a lower i2c sample rate, I clearly see zeros in the recording in Audacity, telling me there were no samples available when the USB requested them.
I must be overlooking something or I must have lack in some understanding. I have searched around the forum and I've even been on page 2 of google. I am stuck, who has some suggestions? The USB request interrupt is not based on the i2c clock, is it?
I included some example code. I am forwarding the i2c to USB with the queue objects in between. My basic test would be to first fill the audio memory pool by adding a delay and the lower the sample rate, which should result in a draining buffer.
Justin
This audio library astonished me, so much functionality which is so easy to use.
Last couple of days I have been trying to use the library for my specific purpose. I want to use cheap and lightweight hardware to record sound from a tape. The choices for hardware result in velocity variations up to 400Hz. By using an 800 ppr encoder, I are able to measure velocity and compensate these variations. I made a post-processing implementation and it works, now I would like to implement a real-time using the Teensy 3.6. I want to compensate the velocity variations by changing the samplerate of the Teensy 3.6 + SGTL5000 accordingly. I would like to use the Teensy as an USB audio device with a fixed sample rate.
It's is perfect if the nominal sample rate is constant, thus the sample rate of the audio device is fixed, say the default 44117 Hz. However , the momentarily sample rate of the SGTL5000 (i2c) will change accordingly with the measured variations. So if the tape is going to fast, we increase the sample rate and vice versa. I will need to buffer the incoming samples and pass them to the USB at the desired nominal rate.
I am pretty sure the audio library implements all required functionalities already, including a buffer using the audio memory pool. However, when I change the sample rate of the i2c, I get distorted sound. For a lower i2c sample rate, I clearly see zeros in the recording in Audacity, telling me there were no samples available when the USB requested them.
I must be overlooking something or I must have lack in some understanding. I have searched around the forum and I've even been on page 2 of google. I am stuck, who has some suggestions? The USB request interrupt is not based on the i2c clock, is it?
I included some example code. I am forwarding the i2c to USB with the queue objects in between. My basic test would be to first fill the audio memory pool by adding a delay and the lower the sample rate, which should result in a draining buffer.
Code:
#include <Audio.h>
#include <Wire.h>
#include <AudioTiming.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=497.00000381469727,367.0000057220459
AudioRecordQueue rqueue2; //xy=653.0000076293945,386.0000057220459
AudioRecordQueue rqueue1; //xy=655.0000076293945,348.0000057220459
AudioPlayQueue pqueue1; //xy=769,348
AudioPlayQueue pqueue2; //xy=769.0000114440918,385.0000057220459
AudioOutputUSB usb1; //xy=902.0001106262207,364.5000057220459
AudioConnection patchCord1(i2s1, 0, rqueue1, 0);
AudioConnection patchCord2(i2s1, 1, rqueue2, 0);
AudioConnection patchCord3(pqueue1, 0, usb1, 0);
AudioConnection patchCord4(pqueue2, 0, usb1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=710.0000076293945,465.00000953674316
// GUItool: end automatically generated code
short array1[AUDIO_BLOCK_SAMPLES];
short array2[AUDIO_BLOCK_SAMPLES];
AudioTiming audiotiming;
int ret=0;
void setup() {
audiotiming.init();
audiotiming.begin();
AudioMemory(900);
sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
sgtl5000_1.volume(0.6);
audiotiming.setI2S_freq(AUDIO_SAMPLE_RATE_EXACT);
Serial.begin(9600);
rqueue1.begin();
rqueue2.begin();
Serial.println("Begin Teensy with SGTL5000");
Serial.print(" Audio block samples:");
Serial.println(AUDIO_BLOCK_SAMPLES);
Serial.print("Exact samplerate:");
Serial.println(AUDIO_SAMPLE_RATE_EXACT);
// Let audio pool fill up a little to account for lower sampling rates
delay(1000);
// Set sample rate lower, now the buffer should drain (but its not)
audiotiming.setI2S_freq(AUDIO_SAMPLE_RATE_EXACT - 1000);
}
void loop() {
ret=rqueue1.available();
if(ret >= 1)
{
// Get input channel 1 and store in array 1
memcpy(&array1[0], rqueue1.readBuffer(), 2*AUDIO_BLOCK_SAMPLES);
rqueue1.freeBuffer();
// Get input channel 2 and store in array 2
memcpy(&array2[0], rqueue2.readBuffer(), 2*AUDIO_BLOCK_SAMPLES);
rqueue2.freeBuffer();
memcpy(pqueue1.getBuffer(), &array1[0], 2*AUDIO_BLOCK_SAMPLES);
pqueue1.playBuffer();
memcpy(pqueue2.getBuffer(), &array2[0], 2*AUDIO_BLOCK_SAMPLES);
pqueue2.playBuffer();
Serial.println(AudioMemoryUsage());
}
}
Justin