Shop OBEX P1 Docs P2 Docs Learn Events
64014_HDAudio_ADCtoDAC_Demo.spin2 - One Question — Parallax Forums

64014_HDAudio_ADCtoDAC_Demo.spin2 - One Question

masselonmasselon Posts: 51
edited 2023-01-25 07:39 in PASM2/Spin2 (P2)

Hello All there

It is possible to run the 2 methods bellow simultaneously or sequencialy? (ie, mix all four input signals in the Right and Left DAC channal? - I do have played its in alternated way but I would like to play its simultanously):

pub DemoLineIn(delaysize) | left, right

  ' Optional - set alternative DAC base drive strength (impedance). Default is 124R, equating to ~31ohms- ideal for many headphones
  ' ak5704.setDAC_BaseImpedance(P_DAC_124R_3V) ' P_DAC_990R_3V, P_DAC_600R_2V, P_DAC_124R_3V, P_DAC_75R_2V

  ' Start the audio driver
  ak5704.start(BASEPIN_ADC, BASEPIN_DAC)

  repeat

    ' Read left and right samples from Line in jack
    left, right := ak5704.getSampleFromADC(ak5704.INPUT_LINE)

    ' Optional, insert audio processing / effect
    if delaysize > 0
      left, right := addDelay(delaysize, left, right)

    ' Write the sample to the DAC output queue
    ak5704.sendSampleToDAC(left, right)   


pub DemoMicIn(delaysize) | left, right

  ' Start the audio driver
  ak5704.start(BASEPIN_ADC, BASEPIN_DAC)

  ' Optionally set microphone phantom power, and enable the output
  ' Note: Without enabling the output, the mic input behaves like a second line input channel!

  ak5704.setMicSensitivity(128, ak5704.INPUT_MIC, ak5704.CH_LR) ' value of 128 is default with 0dB gain

  ak5704.setMicPower(ak5704.MICPWR_1800mV)              ' MICPWR_2800mV, MICPWR_2500mV, MICPWR_1800mV, MICPWR_3000mV
  ak5704.setMicPowerOnOff(ak5704.CH_LR, ak5704.ON)      ' Phantom power can be enabled on either CH_L, CH_R or both channels with CH_LR


  repeat

   ' Read left and right samples from MIC in jack
    left, right := ak5704.getSampleFromADC(ak5704.INPUT_MIC)

    ' Optional, insert audio processing / effect
    if delaysize > 0
      left, right := addDelay(delaysize, left, right)

    ' Write the sample to the DAC output queue
    ak5704.sendSampleToDAC(left, right)

Comments

  • VonSzarvasVonSzarvas Posts: 3,278
    edited 2023-01-25 07:56

    Try adding the Microphone read command after the Line read command, and experiment from there.

    Like this...

    pub DemoLineIn(delaysize) | left, right, left2, right2
    
      ' Optional - set alternative DAC base drive strength (impedance). Default is 124R, equating to ~31ohms- ideal for many headphones
      ' ak5704.setDAC_BaseImpedance(P_DAC_124R_3V) ' P_DAC_990R_3V, P_DAC_600R_2V, P_DAC_124R_3V, P_DAC_75R_2V
    
      ' Start the audio driver
      ak5704.start(BASEPIN_ADC, BASEPIN_DAC)
    
      ' Set mic channel as line input
      ak5704.setMicPowerOnOff(ak5704.CH_LR, ak5704.OFF)
    
      repeat
    
        ' Read left and right samples from Line in jack
        left, right := ak5704.getSampleFromADC(ak5704.INPUT_LINE)
    
        ' Read left and right samples from Mic in jack
        left2, right2 := ak5704.getSampleFromADC(ak5704.INPUT_MIC)
    
        ' Optional, insert audio processing / effect
        if delaysize > 0
          left, right := addDelay(delaysize, left, right)
    
        ' Write the sample to the DAC output queue
        ' - Uncomment only one of the following two lines! Either to hear the line output or the mic output
        ak5704.sendSampleToDAC(left, right)
        ' ak5704.sendSampleToDAC(left2, right2)  
    
        ' In the real world, probably want to experiment with mixing the two audio signals/channels together before outputting them!
    
    
Sign In or Register to comment.