PaulStoffregen / Audio

Teensy Audio Library
http://www.pjrc.com/teensy/td_libs_Audio.html
1.07k stars 398 forks source link

Bad LineOut audio when muteHeadPhone() is called #467

Open nodemand opened 11 months ago

nodemand commented 11 months ago

Description

When I call the AudioControlSGTL5000::volume() function with a value of 0.00 which in effect calls the muteHeadPhone() function, the LineOut audio goes bad.

Steps To Reproduce Problem

A call to AudioControlSGTL5000::volume(0.00) will make the LineOut audio go bad. When I remove the call to muteHeadPhone() from AudioControlSGTL5000::volumeInteger(), the problem is gone and the LineOut audio is ok again.

Hardware & Software

Board: Teensy 4.0 Shields / modules used: Teensy Audio Shield Rev. D2 Arduino IDE version: 2.2.1 Teensyduino version: 1.58.1 Operating system & version: macOS Ventura 13.6

Arduino Sketch


#include <Audio.h>
#include <utility/imxrt_hw.h>

AudioInputI2S            in;           //xy=184,239
AudioOutputI2S           out;           //xy=556,246
AudioConnection          patchCord1(in, 0, out, 0);
AudioConnection          patchCord2(in, 1, out, 1);
AudioControlSGTL5000     codec;     //xy=416,138

void setup() {
  AudioMemory(1024);
  setI2SFreq(192000);
  codec.muteLineout();
  codec.enable();
  codec.inputSelect(AUDIO_INPUT_LINEIN);
  codec.volume(0.8);
  codec.unmuteLineout();
}

void loop() {
  codec.volume(0.00); // THIS IS WHERE IT GOES SOUTH!
}

void setI2SFreq(int freq) {  //Teensy 4
  // PLL between 27*24 = 648MHz und 54*24=1296MHz
  int n1 = 4;  //SAI prescaler 4 => (n1*n2) = multiple of 4
  int n2 = 1 + (24000000 * 27) / (freq * 256 * n1);
  double C = ((double)freq * 256 * n1 * n2) / 24000000;
  int c0 = C;
  int c2 = 10000;
  int c1 = C * c2 - (c0 * c2);
  set_audioClock(c0, c1, c2, true);
  CCM_CS1CDR = (CCM_CS1CDR & ~(CCM_CS1CDR_SAI1_CLK_PRED_MASK | CCM_CS1CDR_SAI1_CLK_PODF_MASK))
               | CCM_CS1CDR_SAI1_CLK_PRED(n1 - 1)   // &0x07
               | CCM_CS1CDR_SAI1_CLK_PODF(n2 - 1);  // &0x3f
}