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

Thread: Dynamic Audio Connections

  1. #1

    Dynamic Audio Connections

    Hi all,

    Since my mixer object is a bit stalled for the moment, I'm looking to try out dynamically changeable connections to accomplish some of what I was going for. I know this is possible, I'm just not finding a ton of examples online, and I want to make sure I'm not going about this the wrong way.

    I saw an example from an old forum post that defines connections at the start like this:

    Code:
    AudioConnection * DynamicPatchCord1;
    Then in the setup the connection is created like this:
    Code:
    DynamicPatchCord1 = new AudioConnection(*input1, 0, *mixer1, 0);
    then connects and disconnects them like this:

    Code:
    DynamicPatchCord1->connect();
    DynamicPatchCord1->disconnect();
    I have some questions (I know you're shocked). First off, can I define the connection initially like the gui does (in this case AudioConnection DynamicPatchCord1(input1, 0, mixer, 0), then connect/disconnect as needed? Or is it better to leave the definition of what the connection is to the code so it can be modified while the program runs?

    I saw on another post a passing reference to .connect() and .disconnect(), but I haven't seen it used. Does anyone have any code that shows this method in use?

    Thank you!

  2. #2
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    98
    I just do "new AudioConnection(...), like you show. You don't have to call ->connect(). If you don't need it, just "delete". It disconnects.
    Having them "pre-made" is a pain, as you need to give each a new name.

    I just have an std::list of connections, add all of them to connect things, then delete them when done and make new ones.
    Then you don't have to keep track of them and they don't use memory if not connected.

    In the header:
    std::list<AudioConnection*> _cords;

    In CPP file:
    void AudioBoard::setupMixers() {
    // Connect 4 input mixers to 2 output mixers
    _cords.push_back(new AudioConnection(_mixer1, 0, _outMixer1, 0));
    _cords.push_back(new AudioConnection(_mixer1, 0, _outMixer2, 0));
    _cords.push_back(new AudioConnection(_mixer2, 0, _outMixer1, 1));
    _cords.push_back(new AudioConnection(_mixer2, 0, _outMixer2, 1));
    _cords.push_back(new AudioConnection(_mixer3, 0, _outMixer1, 2));
    _cords.push_back(new AudioConnection(_mixer3, 0, _outMixer2, 2));
    _cords.push_back(new AudioConnection(_mixer4, 0, _outMixer1, 3));
    _cords.push_back(new AudioConnection(_mixer4, 0, _outMixer2, 3));

    // 2 (stereo) output mixers go to the audio output
    _cords.push_back(new AudioConnection(_outMixer1, 0, _audioOutput, 0));
    _cords.push_back(new AudioConnection(_outMixer2, 0, _audioOutput, 1));
    }

    To disconnect:
    for(auto cord : _cords)
    delete cord;
    _cords.clear();

    Then you can connect what you need again.

  3. #3
    Hi Andy, thank you for the reply!

    I understand what you're doing on a basic level, but I'm not that experienced with c++ so I'll need to study it a bit further.

    In my case, I want to basically be able to select between one of two outputs connected to the input of another block. Do you think it would be better to create two connections (but disconnect them) so I can just connect/disconnect, or completely disconnect and reassign each time? Or does disconnect break the relationship anyway and I'd have to reassign each time?

    Thank you!

  4. #4
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    98
    Any way will work.
    You define the connecting points when you create the connection and can only connect/disconnect later. You cannot change the points of an existing connection.
    If you delete/create a new connection each time, like in my example, you can define new points and connect.

    Spend a couple of hours on C++ basics, like constructor/destructor and new/delete, and it all will be clear.
    You'll need it anyway.

    You can do the same in .ino file, just define the "std::list<AudioConnection*> _cords;" at the top and add "#include <list>" before that.

  5. #5
    Senior Member
    Join Date
    Feb 2017
    Posts
    369
    Quote Originally Posted by jkoffman View Post
    In my case, I want to basically be able to select between one of two outputs connected to the input of another block.
    You seem to be trying to solve a non-existent problem. Why don't you just use a Mixer block? That's what it's for.

  6. #6
    Quote Originally Posted by Andy Belov View Post
    Any way will work.
    You define the connecting points when you create the connection and can only connect/disconnect later. You cannot change the points of an existing connection.
    If you delete/create a new connection each time, like in my example, you can define new points and connect.
    Interesting. I will do some experiments to see if I am allowed to have two connections that technically conflict, but aren't both active at the same time.


    Spend a couple of hours on C++ basics, like constructor/destructor and new/delete, and it all will be clear.
    You'll need it anyway.

    You can do the same in .ino file, just define the "std::list<AudioConnection*> _cords;" at the top and add "#include <list>" before that.
    That's my plan. I do have a bit extra time now....

    Thank you!

  7. #7
    Quote Originally Posted by gfvalvo View Post
    You seem to be trying to solve a non-existent problem. Why don't you just use a Mixer block? That's what it's for.
    In my attempt to simplify what I'm doing, I haven't fully explained the issue. The better analogy would be that I'm making a phase reverse. So it's two sources, and two destinations. sometimes I want 1-1 and 2-2, and sometimes it will be 1-2 and 2-1.

    To do this with mixers will use two mixers for each input, and in my case that would mean like 10-12 mixers. I had been trying to make a mixer with 2 outputs so that I could eventually make a 2x2 audio router, but I haven't been able to get it to work without glitching. I'll keep plugging away at that, but for the moment I'm pretty stuck.

    I think reconfiguring the connections between my blocks is a good alternative solution. I'm going to do some experiments today and see what I can do!

Posting Permissions

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