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

Thread: Getting values from objects

  1. #1

    Getting values from objects

    Hi, is it possible to read the output of lets say an ADSR object from the audio library?

  2. #2
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    102
    Yes, have a look at the AudioRecordQueue object:
    https://www.pjrc.com/teensy/gui/inde...dioRecordQueue

  3. #3
    Thanks, what is 128 samples of 16 bit integer that it returns? I would like something that returns a value say 0.023 eg the level of the envelope between something like 0.000-1.000.

    I have written a DAHDSR that returns a float between 0.0 and 1.0 and sends the value to Serial output to another teensy, but my coding skills are not so good so I really would like to take advantage of the objects from the Audio library.

  4. #4
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    102
    The audio lib processes the audio stream in blocks of 128 samples every 2.9ms. Sample rate is 44117.64706Hz and sample size is 16 bit integer.

    Normally you feed audio in the AudioEffectEnvelope object and it will adjust the audio's amplitude according to the programmed envelope. In your case you want to extract the envelope control signal.

    You do that by feeding an AudioSynthWaveformDc object with an amplitude level of 1.0 into the AudioEffectEnvelope object into the AudioRecordQueue object.

    AudioRecordQueue.readBuffer() will return a pointer to an array of 128 16bit integers. Since the envelope is unipolar, values will vary between 0 and 32767. Divide those values by 32767 to get an output between 0.0 and 1.0.

    Depending on what you want to do with that envelope signal you could get away by just sending the first element of each block over the serial port. This would avoid having to evenly (re)distribute those 128 samples over a 2.9ms time period to preserve the original sample rate.

  5. #5
    Senior Member
    Join Date
    May 2016
    Posts
    218
    Now there's a coincidence! Just today I uploaded to the forum (for another member) a couple of my AudioGrabber Audio Library objects that let you extract blocks of data from the internal audio data stream to your loop(). Is that what you asked about in the OP?

    Although I have a whole bunch with with different lengths and function, I only included length 256 real and complex "grabbers" in this initial upload. I'm in the process of uploading a library to GitHub.

    Here's the zip file attachment containing the code:Grabber256.zip

    AudioGrabberReal256 - extracts length 256 buffers from the data stream, while
    AudioGrabberComplex256 - extracts 256 complex (or quadrature) values in a 512 length buffer in arm_math complex format [real, imag, real, imag,...., ...]
    The data is returned as Q15.1 (int16_t) values.
    Each type has a example sketch to demonstrate the use.

    As an example of where I find them to be useful, I use a grabber to extract data for a real-time spectral display (panadapter) in my SDR work. Every 50 msec I grab a buffer from inside my loop(), then process and display the spectrum as a background task entirely within loop().

    I've used the grabbers on T3.2, T3.6 and T4.0.

    Derek

  6. #6
    Thanks for your help guys, I finally got my own DAHDSR library working so I'll stick to that for the moment.

Posting Permissions

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