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

Thread: More Background for Writing Audio Objects in C++

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    5

    More Background for Writing Audio Objects in C++

    Hi!

    I was hoping someone could help me work out a more detailed description of some of the fundamental AudioStream elements. I am particularly interested in learning more than the given info on the "Creating New Audio Objects" page. I'd love to hear a deeper "how to use" description as well as a more technical explanation of the inner workings for a few of the basics such as audio_block_t, recieveReadonly()/recieveWritable() , transmit() and inputQueue().

    Specific Questions:
    I'm having trouble wrapping my head around what this means from the audio_block_t description:

    "The only member intended for use in update() is "data", an array of 16 bit integers representing the audio ... The data[] array is always 32 bit aligned in memory, so you can fetch pairs of samples by type casting the address as a pointer to 32 bit data"

    I am assuming that the 32 bit type cast is for getting left and right channel simultaneously, but I would love to know the logistics of how to grab a pair of samples with type casting as 32 bits as mentioned in that description.

    Also where might I find the audio_block_t struct definition to look at? In AudioStream.h I found a struct called audio_block_struct but no audio_block_t definition.
    Code:
    typedef struct audio_block_struct {
    	uint8_t  ref_count;
    	uint8_t  reserved1;
    	uint16_t memory_pool_index;
    	int16_t  data[AUDIO_BLOCK_SAMPLES];
    } audio_block_t;

    A few more questions:


    1. How often is update() called for an audio object? Is it called as a timer ISR after sampling 128 (or whatever the block size) number of times?
    2. Does the sgtl5000 input signal full voltage range map to a block sample value of 0-65535 ?
    3. Is the input queue filling up with new samples simultaneously as the previous block is being emptied to the DAC?
    4. Any external resource suggestions or explanation about how to work using real time block based DSP?

    Thank you so much! I hope this post isn't asking too many questions at once

    -Skyler

  2. #2
    Senior Member
    Join Date
    Feb 2015
    Posts
    217
    Here is another thread on the front page which answers a lot of what you're asking: https://forum.pjrc.com/threads/59212...-Router-Module

  3. #3
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,644
    Quote Originally Posted by skyler View Post

    Also where might I find the audio_block_t struct definition to look at? In AudioStream.h I found a struct called audio_block_struct but no audio_block_t definition.
    Code:
    typedef struct audio_block_struct {
    	uint8_t  ref_count;
    	uint8_t  reserved1;
    	uint16_t memory_pool_index;
    	int16_t  data[AUDIO_BLOCK_SAMPLES];
    } audio_block_t;
    If my C++ knowledge is correct, the statement defines both audio_block_t (via typedef) and audio_block_struct {} (via struct).

  4. #4
    Senior Member
    Join Date
    Feb 2017
    Posts
    399
    For me, the best way to learn this info was to dig into the source code of existing Audio Library classes. I had a need to develop custom versions of the I2S and DAC classes. Worked my way through it by literally having the source code open in one window and the K20 Reference Manual in another.

Posting Permissions

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