Problem with signal generation by two players

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with signal generation by two players

Andrey
This post was updated on .
Hello fred.

I have two usb sound cards connected.
I create two players and generate an audio signal for each usb card.
If I run only one player, everything works fine.
If I run both players, they interfere with each other.
What am I doing wrong?

Program code:

//Func for DSP (analog for two player)
function DSPAfter1,2(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
var aArfl: TDArFloat;
     i: integer;
begin
  setlength(aArfl,Data.OutFrames);
  //generate signal
  for i:=0 to Data.OutFrames-1 do
  aArfl[i]:=0.01*sin(2*pi*1000*i/12000);
  //
  result:=aArfl;
end;

//create player
Function CreatePlayer(aPlayer: integer; aFunc: TFunc)
begin
  uos_CreatePlayer(aIndex);
  InputIndex:=uos_AddFromEndlessMuted(aPlayer, 2, 480);
  if inputIndex<>-1 then DSPIndex:= uos_InputAddDSP(aPlayer, InputIndex,nil,aFunc, nil,nil);
  if DSPIndex<>-1 then uos_InputeSetDSP(aPlayer, InputIndex. DSPIndex, true);
  OutputIndex:=uos_AddIntoDevOut(aPlayer, -1, -1, 12000, 2, 0, 480, 512);
  if OutputIndex<>-1 then uos_OutputAddDSPVolume(aPlayer, OutputIndex, 1, 1);
  if "not Problems" then uos_play(aPlayer);

  //Redirecting sound card outputs
  runcommand('pactl move-sink-input (client index) (usb card out-port index)')
end;

//
Procedure RunPlayers;
begin
  CreatePlayer(0,DSPAfter1);
  CreatePlayer(1,DSPAfter2);

  //A loop for the console
  while not Terminated do
  begin
     CheckSynchronize(10);
     sleep(5);
  end;
  //
  uos_FreePlayer(0);
  uos_FreePlayer(1);
end;
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

Andrey
I tried to run it in different programs. The situation has not changed.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

fredvs
Administrator
Hello Andrey.

I am a few lost, I dont see uos_play(aplayer);
When you play each player individually is it working for both sound-cards?

I did not catch in your code what output you are using for each sound-card.
Is it the output of each sound-card or one output for the 2 sound cards and so you are using one output (card 1 or 2) for the 2 payers?

When you play both player together, you noted that they interfere with each other.
What does it mean?
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

fredvs
Administrator
Re-hello Andrey.

If you want to use the same output for both card, did you try with only one player and 2 uos_InputAddDSP, one from one card and the other form the other card?

Maybe if you explain better what is your goal I could help more.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

Andrey
In reply to this post by fredvs
"When you play each player individually is it working for both sound-cards?"  - It works for each sound individually.

I did not catch in your code what output you are using for each sound-card.
"Is it the output of each sound-card or one output for the 2 sound cards and so you are using one output (card 1 or 2) for the 2 payers?" - I use different sound cards for each player.

"When you play both player together, you noted that they interfere with each other.
What does it mean?" - Sound distortion occurs on both sound cards.

To configure the outputs of the sound cards, I use the linux command "pactl". But I tried to specify the device index in uos_AddIntoDevOut(), the situation has not changed. I ran for each sound card in a separate program, the situation has not changed, the sound is distorted on both cards.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

fredvs
Administrator
This post was updated on .
Did you try changing the latency of each player, for example 0.3 ?

uos_AddIntoDevOut(aPlayer, -1, 0.3, 12000, 2, 0, 1024, 512);

Also did you try with different resolution (integer or float) and with different size of buffer?
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

Andrey
Hello Fred.

I changed the Sample Rate, Sample Format, frameCount, Latency for each player. The problem remains.

It feels like the data from both players is mixed up. When you turn off one of the players, the distortion remains for a while. Then the signal is restored.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

Andrey
This post was updated on .
In reply to this post by fredvs
I found out what the problem is. I use two usb sound cards. They are connected via a shared USB hub. I connected them to different usb ports and everything worked.

The question is how to get around it?
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

fredvs
Administrator
Hello Andrey.

Hum, I not expert in those USB things, maybe you could find help via internet.

Even maybe ask it to ChatGPT sometimes there are good answers.

I hope you will find a solution.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

Andrey
Ok. Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

fredvs
Administrator
This post was updated on .
Hello Andrew.

I have asked this to ChatGPT:

Question:
I have 2 usb sound cards. When connecting the 2 usb sound cards in a usb hub the sound is bad. But if connecting the sound cards into the 2 independent usb port of the pc the sound is good.  What is the workaround to make work the 2 usb card via a usb hub?

Answer from ChatGPT:

The issue you're experiencing could be related to the power distribution or bandwidth limitations of the USB hub. Here are some steps you can take to try and improve the situation:

1. **Use a Powered USB Hub:**
   USB hubs come in both powered and unpowered variants. A powered USB hub has its own power source, which can help ensure that each connected device receives sufficient power. If you're currently using an unpowered hub, consider switching to a powered one.

2. **Check Bandwidth and Compatibility:**
   Ensure that the USB hub has enough bandwidth to support both USB sound cards simultaneously. USB hubs have their own limitations, and if multiple high-bandwidth devices are connected, it may affect performance. Also, make sure that the USB hub is compatible with your sound cards.

3. **Use a High-Quality USB Hub:**
   The quality of the USB hub can impact its performance. Investing in a higher-quality, well-reviewed USB hub might improve the stability of the connections and the quality of the sound.

4. **Connect to Different Ports on the Hub:**
   Experiment with connecting the USB sound cards to different ports on the hub. Sometimes, certain ports on the hub may have better performance than others.

5. **Update USB Hub Drivers:**
   Ensure that you have the latest drivers for your USB hub. Check the manufacturer's website for any available updates.

6. **Update Sound Card Drivers:**
   Make sure that you have the latest drivers for your USB sound cards. Visit the manufacturer's website to download and install the most recent drivers.

7. **Check USB Hub Compatibility with Audio Devices:**
   Some USB hubs may not be suitable for audio devices due to their design or limitations. Check the specifications of the USB hub to see if it explicitly supports audio devices.

8. **Reduce the Number of Connected Devices:**
   If possible, minimize the number of devices connected to the USB hub. This can reduce the overall load on the hub and may improve the performance of the connected sound cards.

9. **Use a Different USB Port on Your Computer:**
   If you're not already doing so, try connecting the USB hub to a different USB port on your computer. Some ports may have better power distribution and connectivity.

10. **Consider a Different Hub:**
    If the issue persists, consider trying a different USB hub. Some hubs may perform better than others with specific devices.

If you've tried these steps and still experience issues, it's possible that the USB hub may not be suitable for your specific use case, and using separate USB ports on your computer might be the most reliable solution.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with signal generation by two players

Andrey
This post was updated on .
Hello Fred.

The problem is that on the motherboard used, all usb ports use a usb hub (a design feature of the motherboard).
I ran the tests on another computer via a usb hub, without it, and on this motherboard.
The problem occurred when using a usb hub or on a special motherboard (It seems to me that the two audio signals are combined, as if they have a common buffer.).
When using a regular computer without a usb hub, the problem did not arise. I see the solution so far in using an additional USB expansion board.