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

Thread: Question about creating new audio objects

  1. #1
    Junior Member
    Join Date
    Oct 2021
    Posts
    5

    Question about creating new audio objects

    Hi, first post here.

    I have a question about creating a new audio object.

    I've read https://www.pjrc.com/teensy/td_libs_...ewObjects.html and it looks like the update function is called on an interrupt. I am familiar with an audio callback that gets called when the audio buffer needs to be filled. Does the update function operate in the same way?

    Louie

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,081
    Quote Originally Posted by rcon View Post
    I am familiar with an audio callback that gets called when the audio buffer needs to be filled. Does the update function operate in the same way?
    Yes, it's basically the same idea. Except instead of getting the buffer pointers passed as function inputs, you call receiveReadOnly(channel) or receiveWritable(channel) to get the buffers of incoming samples, and you can allocate more buffers as you need. Then after you've done whatever DSP work you like, you call transmit(buffer, channel) function rather than putting the data into a buffer you got as a function input, and call release(buffer) when you're done.

    The interrupts have priority levels, so your update() function runs as a relatively low interrupt priority where it still blocks the main program, but does not block most other time-sensitive interrupts.

  3. #3
    Junior Member
    Join Date
    Oct 2021
    Posts
    5
    Paul thanks for the quick reply and info! Most of my code is in C, is there a way to create an audio object in C or do I just need to wrap those functions in a AudioStream class?

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,333
    No, you have to use the audio class.

    A tip: remember that you can also get back a NULL pointer for the audio blocks at any time. On T4, you have to add cache-handling, too (If it is an input or output object)

    Easiest is to just copy the code from the existing objects...

  5. #5
    Junior Member
    Join Date
    Oct 2021
    Posts
    5
    Thanks Frank I did exactly as you suggested and got it working pretty easily. I have another questions (sorry I'm new ), is it possible to create audio objects on the fly? Like after the program is running be able to create a new audio object, wire it up and then use it? Then destroy it and create new ones as you please?

  6. #6
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by rcon View Post
    is it possible to create audio objects on the fly? Like after the program is running be able to create a new audio object, wire it up and then use it? Then destroy it and create new ones as you please?
    That's a question i'd like an answer to as well. I'd like to create an audio analyser tool that can switch between different 'screens', each screen having a different function. When one screen is showing i'd like the other audio objects to not be running (e.g. turn off FFT1024 when the Peak or RMS objects are running), so creating them on the fly when they are needed would be the best way to implement that.

    Thanks

    NM
    Last edited by NuttyMonk; 10-12-2021 at 04:07 PM.

  7. #7
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    124
    Quote Originally Posted by rcon View Post
    Thanks Frank I did exactly as you suggested and got it working pretty easily. I have another questions (sorry I'm new ), is it possible to create audio objects on the fly? Like after the program is running be able to create a new audio object, wire it up and then use it? Then destroy it and create new ones as you please?
    Not using the official core and Audio library, but I've done some work on that - please see this thread which has links to my github repositories. I've not had any reports of bugs / difficulties using, but I suspect that's because it's a bit of a niche use case.

    Please note that the recent update added the ability to turn updates on and off for audio objects not connected to the "main" update list (see page 7 of the Dynamic Audio Library pdf), and by default the updates are on and thus consume CPU without contributing to audible output. This change was to preserve compatibility with the standard "static" audio library. Obviously if you destroy an audio object then it doesn't consume CPU...

    Cheers

    Jonathan

  8. #8
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    124
    Quote Originally Posted by NuttyMonk View Post
    That's a question i'd like an answer to as well. I'd like to create an audio analyser tool that can switch between different 'screens', each screen having a different function. When one screen is showing i'd like the other audio objects to not be running (e.g. turn off FFT1024 when the Peak or RMS objects are running), so creating them on the fly when they are needed would be the best way to implement that.
    As noted above, I've done a dynamic audio library. With that, creating and destroying on the fly is one approach, but you could also switch to "don't update if not connected to the main update list" mode, and then just use the connect() / disconnect() functions to control CPU usage, and leave all audio and connection objects in existence. That would reduce the possibility of heap fragmentation.

    Cheers

    Jonathan

  9. #9
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Thanks Jonathan, that sounds exactly like what i need, especially the connect/disconnect part.

    I'll give it a go and update you on any problems if i find them.

    Cheers

    NM

Posting Permissions

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