logo       


PING: Queueing fails for buffers with streamed sources: msg#00051

Subject: PING: Queueing fails for buffers with streamed sources
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Did send this a while ago just pinging for comments:

Using svn revision 1426 under linux when running something like:

alGenBuffers( 2, vorbbuf );
alGenSources( 1, &vorbsource );
alSourceQueueBuffers(vorbsource,2,vorbbuf);
alutLoadVorbisp( vorbbuf[i], data, size );
alSourcePlay( vorbsource );

openal plays the first buffer in an endless loop.

Testcase and a patch to fix it is attached. There is probably a better
way to do this but this seems to work.

regards DevH


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGRJ0gCbmO6P7mspMRCs3JAJ45sE38l6KtViNbcXl7B4Cm3DWONgCfY4Tl
4YzGAsuBzRK8nAzUSal9K0c=
=M6tn
-----END PGP SIGNATURE-----
#include <AL/al.h>
#include <AL/alc.h>
//#include <AL/alut.h>
#include <AL/alext.h>

#include <errno.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>

#define DATABUFSIZE 4096
#define VORBIS_FILE    "boom.ogg"
#define VORBIS_FUNC    "alutLoadVorbis_LOKI"
#define MP3_FUNC    "alutLoadMP3_LOKI"
#define NUMSOURCES  1
  
ALboolean sourceIsPlaying( ALuint sid )
{
  ALint state;
  if( alIsSource( sid ) == AL_FALSE ) {
    return AL_FALSE;
  }
  alGetSourceiv( sid, AL_SOURCE_STATE, &state );
  return ( ( state == AL_PLAYING )
           || ( state == AL_PAUSED ) ) ? AL_TRUE : AL_FALSE;
}

static void init( void );

static ALuint vorbbuf[2];               /* our buffers */
static ALuint vorbsource = ( ALuint ) -1;

static time_t start;

static ALCcontext *context;

/* our vorbis extension */
typedef ALboolean ( dataLoader ) ( ALuint, ALvoid *, ALint );
dataLoader *alutLoadVorbisp = NULL;
dataLoader *alutLoadMP3p = NULL;

static void init( void )
{
        start = time( NULL );

        alGenBuffers( 2, vorbbuf );
        alGenSources( 1, &vorbsource );

        alSourceQueueBuffers(vorbsource,2,vorbbuf);     
        alSourcei( vorbsource, AL_ROLLOFF_FACTOR, 1 );
        alSourcei( vorbsource, AL_SOURCE_RELATIVE, AL_TRUE );
}

int main( int argc, char *argv[] )
{
        ALCdevice *device;
        FILE *fh;
        struct stat sbuf;
        void *data;
        char *fname;
        int size;
        int i;

        device = alcOpenDevice( NULL );
        if( device == NULL ) {
                return EXIT_FAILURE;
        }

        /* Initialize ALUT. */
        context = alcCreateContext( device, NULL );
        if( context == NULL ) {
                alcCloseDevice( device );

                return EXIT_FAILURE;
        }

        alcMakeContextCurrent( context );

        init(  );

        alutLoadVorbisp =
            ( dataLoader * ) alGetProcAddress( ( ALchar * ) VORBIS_FUNC );
        if( alutLoadVorbisp == NULL ) {


                fprintf( stderr, "Could not GetProc %s\n",
                         ( ALubyte * ) VORBIS_FUNC );
                exit( EXIT_FAILURE );
        }

        alutLoadMP3p =
            ( dataLoader * ) alGetProcAddress( ( ALchar * ) MP3_FUNC );
        if( alutLoadMP3p == NULL ) {


                fprintf( stderr, "Could not GetProc %s\n",
                         ( ALubyte * ) MP3_FUNC );
                exit( EXIT_FAILURE );
        }

        for(i = 0; i < 2; i++)
          {
            fname = ( argc == (1+i) ) ? VORBIS_FILE : argv[1+i];
            
            if( stat( fname, &sbuf ) == -1 ) {
              perror( fname );
              return errno;
            }
            
            size = sbuf.st_size;
            data = malloc( size );
            if( data == NULL ) {
              exit( EXIT_FAILURE );
            }
            
            fh = fopen( fname, "rb" );
            if( fh == NULL ) {
              fprintf( stderr, "Could not open %s\n", fname );
              
              free( data );
              
              exit( EXIT_FAILURE );
            }
            
            fread( data, size, 1, fh );
            if(1)
              {
                if( alutLoadVorbisp( vorbbuf[i], data, size ) != AL_TRUE ) {
                  fprintf( stderr, "alutLoadVorbis failed\n" );
                  exit( EXIT_FAILURE );
                }
              }
            else
              {
                if( alutLoadMP3p( vorbbuf[i], data, size ) != AL_TRUE ) {
                  fprintf( stderr, "alutLoadMP3 failed\n" );
                  exit( EXIT_FAILURE );
                }
              }
            free( data );
          }
        
        ALuint queued = 0;
        alGetSourcei(vorbsource,AL_BUFFERS_QUEUED,&queued);
        printf("%ld files queued\n", queued);
        alSourcePlay( vorbsource );

        while( sourceIsPlaying( vorbsource ) == AL_TRUE ) {
          ALuint queued1 = 0;
          alGetSourcei(vorbsource,AL_BUFFERS_QUEUED,&queued1);
          if(queued != queued1)
            {
              queued = queued1;
              printf("%ld files queued", queued);             
            }
          alSourcePause( vorbsource );
          alSourcePlay( vorbsource );
          sleep( 1 );
        }

        alcDestroyContext( context );
        alcCloseDevice( device );

        return EXIT_SUCCESS;
}


Index: src/al_mixer.c
===================================================================
--- src/al_mixer.c      (revision 1426)
+++ src/al_mixer.c      (working copy)
@@ -309,7 +309,6 @@
                                AL_buffer *samp = _alGetBuffer(bid);
 
                                assert(samp);
-                               assert(src->srcParams.soundpos < samp->size);
                        }
 #endif
 
Index: src/al_source.c
===================================================================
--- src/al_source.c     (revision 1426)
+++ src/al_source.c     (working copy)
@@ -1405,6 +1405,17 @@
                 * What a cheat.
                 */
 
+               /* Fix queueing */
+               src->srcParams.new_readindex = src->bid_queue.read_index+1;
+               src->srcParams.new_soundpos = 0;
+               if(src->bid_queue.read_index >= src->bid_queue.size)
+               {
+                       if(_alSourceIsLooping(src))
+                       {
+                               src->srcParams.new_readindex = 0;
+                       }
+               }
+
                src->srcParams.soundpos = samp->size + nc * resultsamps * 
sizeof **buffers;
        }
 
_______________________________________________
Openal-devel mailing list
Openal-devel@xxxxxxxxxxxxxxxxxxxxxxx
http://opensource.creative.com/mailman/listinfo/openal-devel
Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe