Author Topic: Bug(s?) in SoundSystem OpenAL Library  (Read 3444 times)

Offline quack

  • bit
  • Posts: 1
    • View Profile
Bug(s?) in SoundSystem OpenAL Library
« on: April 17, 2013, 02:01:37 AM »
I encountered a bug with feedRawAudioData when using OpenAL.

When a new buffer is added, the method will occasionally replay previously added buffers, this is caused here:

In ChannelLWJGLOpenAL.feedRawAudioData:
Code: newbielink:javascript:void(0); [nonactive]
        // Clear out any previously queued buffers:
        int processed = AL10.alGetSourcei( ALSource.get( 0 ),
                                           AL10.AL_BUFFERS_PROCESSED );
        if( processed > 0 )
        {
            intBuffer = BufferUtils.createIntBuffer( processed );
            AL10.alGenBuffers( intBuffer );
            if( errorCheck( checkALError(),
                "Error clearing stream buffers in method 'feedRawAudioData'" ) )
                return -1;
            AL10.alSourceUnqueueBuffers( ALSource.get( 0 ), intBuffer );
            if( errorCheck( checkALError(),
               "Error unqueuing stream buffers in method 'feedRawAudioData'" ) )
                return -1;
            if( AL10.alIsBuffer( intBuffer.get( 0 ) ) )
                millisPreviouslyPlayed += millisInBuffer( intBuffer.get( 0 ) );
            checkALError();
        }
        else
        {
            intBuffer = BufferUtils.createIntBuffer( 1 );
            AL10.alGenBuffers( intBuffer );
            if( errorCheck( checkALError(),
                 "Error generating stream buffers in method 'preLoadBuffers'" ) )
                return -1;
        }

        AL10.alBufferData( intBuffer.get(0), ALformat, byteBuffer, sampleRate );
        if( checkALError() )
            return -1;

        AL10.alSourceQueueBuffers( ALSource.get( 0 ), intBuffer );
        if( checkALError() )
            return -1;

When processed is greater than 1 it's using the buffers allocated in the first conditional to queue the new buffer, causing it to re-play the previous (processed-1) buffers after the new buffer.

If you change the else to if (processed != 1) then it works as expected (only queueing the new buffer.) Alternately I guess you could create a new IntBuffer with only the first element.

Also, I don't know if this has any negative side effects or not, but none of the OpenAL buffers you create with alGenBuffers (in feedRawAudioData, or preLoadBuffers) are ever deleted with a corresponding call to alDeleteBuffers. I'm guessing the consequences of this are platform/driver specific, and I haven't really noticed anything on Windows or Linux.
« Last Edit: April 17, 2013, 02:58:27 AM by quack »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Bug(s?) in SoundSystem OpenAL Library
« Reply #1 on: April 17, 2013, 08:11:48 AM »
Thanks, I'll take a closer look at this.
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 Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Bug(s?) in SoundSystem OpenAL Library
« Reply #2 on: April 17, 2013, 08:28:41 AM »
Hmm.. another way might be to call intBuffer.limit( 1 ) at the end of the first conditional.
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 Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Bug(s?) in SoundSystem OpenAL Library
« Reply #3 on: April 17, 2013, 01:31:20 PM »
Also, I don't know if this has any negative side effects or not, but none of the OpenAL buffers you create with alGenBuffers (in feedRawAudioData, or preLoadBuffers) are ever deleted with a corresponding call to alDeleteBuffers.

I suppose the best place to call alDeleteBuffers is when they are unqueued.  I can probably just call this at the end of that conditional block, and then remove the else entirely (always do an alGenBuffers, regardless of the number processed).

I also see a potential logic error here WRT the milliseconds calculation.  It is only checking the first buffer, which would be incorrect if processed were greater than 1.

I must have been half asleep when I wrote this section, LOL
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