PaulS
Well-known member
Hooked up a PCM5102 board to a Teensy 3.1 to form a USB audio interface.
With the code below, my windows PC sees a USB Teensy Audio device and outputs audio via the PCM5102 board as expected.
To control the volume of the audio I use the windows volume slider:
Now the interesting part is that when the slider is at 50%, the value of variable "vol" = 0.63. I expected 0.50.
When I checked other slider settings, I see the following values for slider percentages:
My questions now are: where [and how] is this conversion done? And is there a reason it isn't linear?
I have been digging through the audio library sources but could not find it.
Any help and/or explanation is appreciated!
Thanks,
Paul
With the code below, my windows PC sees a USB Teensy Audio device and outputs audio via the PCM5102 board as expected.
Code:
// PCM5102 bd Teensy
// VCC 5V
// GND GND
// LRCK 23
// DATA 22
// BCK 9
// set Tools > USB Type to Audio (+ Serial if needed)
#include <Audio.h>
AudioInputUSB usb1;
AudioAmplifier amp2;
AudioAmplifier amp1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(usb1, 0, amp1, 0);
AudioConnection patchCord2(usb1, 1, amp2, 0);
AudioConnection patchCord3(amp2, 0, i2s1, 1);
AudioConnection patchCord4(amp1, 0, i2s1, 0);
void setup()
{
Serial.begin(9600);
AudioMemory(12);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop()
{
float vol = usb1.volume(); // read PC volume setting
amp1.gain(vol); // set gain according to PC volume
amp2.gain(vol);
delay(100);
Serial.println(vol);
}
To control the volume of the audio I use the windows volume slider:
Now the interesting part is that when the slider is at 50%, the value of variable "vol" = 0.63. I expected 0.50.
When I checked other slider settings, I see the following values for slider percentages:
My questions now are: where [and how] is this conversion done? And is there a reason it isn't linear?
I have been digging through the audio library sources but could not find it.
Any help and/or explanation is appreciated!
Thanks,
Paul