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

Thread: Dynamic Audio Connection Bug?

  1. #1
    Senior Member
    Join Date
    Dec 2015
    Posts
    166

    Dynamic Audio Connection Bug?

    Hi all,

    A while back I looked into creating dynamic patch cords to connect audio components. I wrote a simple test program that took USB audio in, connected it directly to line out, then swapped left and right channels. It worked. I shelved it for awhile, then pulled it back out recently. Here's some relevant code:

    Code:
    // Dynamic Patch Definition
    AudioConnection*     pUSB1_0s;
    AudioConnection*     pUSB1_1s;
    
    AudioConnection*     pUSB1_0c;
    AudioConnection*     pUSB1_1c;
    
    void usb_in_setup()     // Setup USB in patches
    {
      pUSB1_0c = new AudioConnection(usb1, 0, i2s1, 1);
      pUSB1_1c = new AudioConnection(usb1, 1, i2s1, 0);
    
      pUSB1_0c -> disconnect();
      pUSB1_1c -> disconnect();
    
      pUSB1_0s = new AudioConnection(usb1, 0, i2s1, 0);
      pUSB1_1s = new AudioConnection(usb1, 1, i2s1, 1);
    
      pUSB1_0s -> disconnect();
      pUSB1_1s -> disconnect();
    }
    
    
    void usb_in_straight(void)  //USB input straight to output
    {
      if(pUSB1_0c && pUSB1_1c)
      {    
        pUSB1_0c -> disconnect();
        pUSB1_1c -> disconnect();
    
        pUSB1_0s -> connect();
        pUSB1_1s -> connect();
      }
    }
    
    
    void usb_in_cross(void)  //USB input cross to output
    {
      if(pUSB1_0s && pUSB1_1s)
      { 
        pUSB1_0s -> disconnect();
        pUSB1_1s -> disconnect();
      
        pUSB1_0c -> connect();
        pUSB1_1c -> connect();
      }
    }
    These functions worked ok.

    I'm now trying to integrate this functionality into a much more complex application, and I think I've found a problem. While I'm still fairly certain this is a problem with something I'm doing, what I'm finding is that if the device I'm trying to disconnect has a second patch cord attached to it things get a little more questionable. Sometimes it seems to work partially in that one of the two will disconnect.

    I'm still trying to properly characterize this, but so far every combination of static or dynamic patch cord has failed when paired with a dynamic patch on a single output terminal. So far it seems that this happens when I have one statically defined patch and one that I try to connect and disconnect. It happens when I have two dynamically defined patches but only try to connect/disconnect one of them. And it happens when I have two dynamically defined ones that both get connected and disconnected at the same time.

    I will report back as I learn more, but so far does this match anyone else's experience, or does anyone know of a reason why this is happening? I am really not sure what to try next, so for now I'm off to bed. I'm hoping someone can give me a bit of a steer, I feel a bit lost on this.

    Thank you!

  2. #2
    Senior Member
    Join Date
    Dec 2015
    Posts
    166
    A bit of further info:

    Adding the following code to the start causes the above code to fail:

    Code:
    AudioInputAnalogStereo   adcs1;          //xy=214,270
    AudioMixer4              mixer1;         //xy=407,264
    AudioConnection          patchCord1(adcs1, 0, mixer1, 0);
    AudioConnection          patchCord2(adcs1, 1, mixer1, 1);
    AudioConnection          patchCord3(usb1, 0, mixer1, 2);
    AudioConnection          patchCord4(usb1, 1, mixer1, 3);
    Really it's patchCord3 and patchCord4 that are the issue.

    I changed things a bit by inserting an amp:

    Code:
    AudioAmplifier    amp_input0;
    AudioAmplifier    amp_input1;
    
    AudioConnection          patchCord1(usb1, 0, amp_input0, 0);
    AudioConnection          patchCord2(usb1, 1, amp_input1, 0);
    So now the output of the usb1 object has two connections, one to mixer, and one to an amp. I am then dynamically reassigning the connections on the output of the amps, and that works as there is only a single connection on that terminal.

    I'll keep experimenting, but I think there might be a problem I'm not skilled enough to solve in the library code here.

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    320
    Perhaps AudioNoInterrupts() and AudioInterrupts() are required around the changes to make them atomic?

  4. #4
    Senior Member
    Join Date
    Dec 2015
    Posts
    166
    An interesting idea. I will have to experiment with it further. Though at one point I had pared things down to three objects and two patch cords, while only trying to change one of them. It still didn't work.

    Right now I'm rolling with my "insert an amp" method so that the movable patch is the only connection on that terminal.

    Thanks!

Posting Permissions

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