Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Read analog input value in Volts

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    3

    Read analog input value in Volts

    Hello all,
    I own an Euroshield mounting a Teensy 3.2 that works with Audio libraries. I am fairly new to Teensy programming and I need some help on a very basic task that apparently I can't figure out.

    I would like to read the DC value in Volts from the two inputs of the board, ideally I would like to have a float value as when I am doing an analogRead(X) from a knob (but I guess for DC IN it would be between -1 and 1?) . I would like something similar to the following, but instead of using AudioAnalyzeRMS object, I'd like to use a different object that lets me .read() the current value, similarly to this:
    Code:
    AudioInputI2S            audioInput;
    AudioAnalyzeRMS          input_1;
    AudioAnalyzeRMS          input_2;
    AudioConnection          patchCord1(audioInput, 0, input_1, 0);
    AudioConnection          patchCord2(audioInput, 1, input_2, 0);
    
    ...
    
    last_input_1 = input_1.read();
    last_input_2 = input_2.read();
    I would like to perform some modifications on the input value before sending it to output, treating it as a DC value (between -1 and 1) rather than audio level signals. I think this should be as easy as reading a knob value, but I really can't figure it out. Any suggestion or pointer to some reading material would be highly appreciated.

    Thanks

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    977
    The inputs are likely to be AC coupled.

  3. #3
    Junior Member
    Join Date
    Mar 2021
    Posts
    3
    Quote Originally Posted by MarkT View Post
    The inputs are likely to be AC coupled.
    Dear Mark,
    they are not. Quoting from their user guide:
    “DC coupling allows audio ins and outs to be used as control voltage connections”.

    So, how do I do that?

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    977
    Ah, those prominent caps must be decouplers then...
    I think there is indeed a gap for a DC analysis object, AudioAnalyzePeak takes the absolute value, and of course
    RMS cannot be negative.

    Probably easy to knock one up, by adding a mean() method to AudioAnalyzePeak perhaps?

    [ edit: yes, try the analyze_peak.h from this branch: https://github.com/MarkTillotson/Audio/tree/dc_average
    it adds a readDcAverage() method to AudioAnalyzePeak ]

    Note tha audio library doesn't deal in volts, its -1.0 to +1.0 full scale always.

  5. #5
    Junior Member
    Join Date
    Mar 2021
    Posts
    3
    Quote Originally Posted by MarkT View Post
    Ah, those prominent caps must be decouplers then...
    I think there is indeed a gap for a DC analysis object, AudioAnalyzePeak takes the absolute value, and of course
    RMS cannot be negative.

    Probably easy to knock one up, by adding a mean() method to AudioAnalyzePeak perhaps?

    [ edit: yes, try the analyze_peak.h from this branch: https://github.com/MarkTillotson/Audio/tree/dc_average
    it adds a readDcAverage() method to AudioAnalyzePeak ]

    Note tha audio library doesn't deal in volts, its -1.0 to +1.0 full scale always.
    Hey man, I can thank you enough for this.

    I actually managed to do exactly what I wanted. Basically I read a CV in signal that I alter through some controlled randomness. Here is a pic depicting my output (yellow) compared to the input signal into audioIN2 on Euroshield (blue) while simultaneously altering the scale of noise:
    Click image for larger version. 

Name:	Schermata 2021-03-02 alle 22.18.00.png 
Views:	9 
Size:	75.2 KB 
ID:	23896

    EDIT: btw yes, the value is using .readDcAverage() between -1 and 1.


    You just fixed something it would have taken me ages to figure out. If I can buy you a beer or something for this, I'd be happy to!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •