Author Topic: Need help with 3D Sound System & Xuggler  (Read 5675 times)

Offline NeatMonster

  • bit
  • Posts: 6
    • View Profile
Need help with 3D Sound System & Xuggler
« on: April 12, 2013, 12:39:43 PM »
Hello Paul,

I need your help on that one. :P

I'm using Xuggler to read videos stored on the Internet. Of course, I want the audio to be played by your 3D Sound System (because it is used by Minecraft). So, I created a RawDataStreaming source and fed it with the samples I'm receiving. But I have an issue : the sound is only played 50% of the time. You hear the sound, then nothing, then the sound again, etc. So, the audio is delayed. I thought first it was an issue with the packets, but using the default line system of Java, it works just fine. Then I thought it might be an issue with stereo/mono channels but I have manually changed the numbers of channels and it went worse.

Here is the code I've written:
Code: [Select] [nofollow]
[...]
// Called when the streaming begins.
final AudioFormat audioFormat = new AudioFormat(audioStreamCoder.getSampleRate(), 16, audioStreamCoder.getChannels(), true, false);
final Entity player = Minecraft.getMinecraft().thePlayer;
SoundManager.sndSystem.rawDataStream(audioFormat, true, "youtube", (float) player.posX, (float) player.posY, (float) player.posZ, 2, 64);
[...]
// Called when samples are received.
final byte[] data = samples.getData().getByteArray(0, samples.getSize());
SoundManager.sndSystem.feedRawAudioData("youtube", data);
[...]

Thanks in advance, NeatMonster.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Need help with 3D Sound System & Xuggler
« Reply #1 on: April 12, 2013, 02:22:19 PM »
The first thing that comes to mind is there could be gaps in the data.  One of the library plug-ins (I think the OpenAL ones, but can't remember) will stop playback if it runs out of data.  This could be causing the stream to pause if it reaches the end of the available data and has to wait for more to arrive.

I would start by filling up a large buffer of data before beginning the raw data stream (tinker around with how large of a buffer - the larger it is, the less likely there will be gaps, but the more latency you will have).  Feed that initial large buffer to the raw data stream, begin playback on the source, and continue as normal.

If that is what is causing the problem, note that if the audio data is not arriving over time at full speed, you will eventually run out of buffer and the problem will reappear if the stream runs long enough.  This is similar to the same behavior you would see on YouTube or Netflix when the internet connection is too slow (periodic buffering).

If that doesn't help, let me know and I can do some more digging.  Another thing you could try is to increase the size of the individual buffers of data you are feeding the raw data stream (in case it is taking longer to dequeue them than it does to play them, if they happen to be very tiny).
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline NeatMonster

  • bit
  • Posts: 6
    • View Profile
Re: Need help with 3D Sound System & Xuggler
« Reply #2 on: April 12, 2013, 03:22:35 PM »
-snip-
Thank you for your quick answer.

I tried using a buffer (containing the 100 first samples received). The audio was smooth, but the samples were played twice. For example, if the buffer contains 5 seconds of sound, those 5 seconds will be played twice, one after the other. I still think it has something to do with the stereo/mono channels, because the second time you hear the audio, it might be the second channel.

By the way, you can find the source of my decoding thread here [nofollow].

Thanks in advance, NeatMonster.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Need help with 3D Sound System & Xuggler
« Reply #3 on: April 12, 2013, 03:44:11 PM »
What value is getting returned by audioStreamCoder.getChannels()?  Is it something larger than 2?  What happens if you manually enter a value of 1 or 2 in both of the places where that method is called? (i.e. both the call to "new AudioFormat" and to "IAudioSamples.make")

You could also try doubling the value returned by audioStreamCode.getChannels() for the "new AudioFormat" call.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline NeatMonster

  • bit
  • Posts: 6
    • View Profile
Re: Need help with 3D Sound System & Xuggler
« Reply #4 on: April 12, 2013, 04:09:08 PM »
-snip-
The method returns 2.

(1, 1), (1, 2) -> no sound at all
(2, 1), (2, 2) -> same issue

Offline NeatMonster

  • bit
  • Posts: 6
    • View Profile
Re: Need help with 3D Sound System & Xuggler
« Reply #5 on: April 14, 2013, 04:51:46 AM »
Any other idea Paul? I can't find what's wrong.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Need help with 3D Sound System & Xuggler
« Reply #6 on: April 17, 2013, 08:32:14 AM »
I'm pretty sure this is related to this bug.  I'll post an update this evening with it fixed.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline NeatMonster

  • bit
  • Posts: 6
    • View Profile
Re: Need help with 3D Sound System & Xuggler
« Reply #7 on: April 17, 2013, 11:40:17 AM »
-snip-
Thank you Paul, I hope it'll solve my issue!

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Need help with 3D Sound System & Xuggler
« Reply #8 on: April 17, 2013, 08:49:45 PM »
Posted the update.  Let me know if it corrects the problem or not.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline NeatMonster

  • bit
  • Posts: 6
    • View Profile
Re: Need help with 3D Sound System & Xuggler
« Reply #9 on: April 19, 2013, 09:29:27 AM »
-snip-
Looks like it solved my issue, thank you Paul!