SoundManager - A very simple sound manager using OpenAL - DLL Version


This is a dll version of the generic OpenAL SoundManager
Aug 05 - First version of the code by Van Stokes, Jr. (http://www.EvilMasterMindsInc.com).

Sep 05 - Second version by Steven.
Jan 06 - Implementation of the ogg format by Crashy, using the excellent tutorial made by Anthony Yuen GameDev tutorial.

Goals

  • Simple sound manager using OpenAL (http://www.OpenAL.org).
  • Nearly no Ogre code was used to be as universal as possible (only exception OgreVector3.h and OgreQuaternion.h)


Careful :
-This code is written for the version '1.1' of OpenAL. Verify that your library is not 1.0. Check the OpenAL site for the new SDK installer.
However, several people couldn't integrate the 1.1 version with Ogre. Ogre simply segfault but until now nobody could find the reason... If it happens you should revert to the 1.0 version and make three small modifications to the source.

If you want a more advanced manager, see OpenAL++ (http://alpp.sourceforge.net/)

Please, use this forum thread to discuss problems, suggestions, etc.

TODO

  • Make the au format readable
  • make functions that call the EAX functions !

Compiling

  • Download and install the OpenAL library and DLL.
  • Download and compile the OGG-Vorbis SDK take the most recent libvorbis archive
  • You 'need' to compile or have the ogg dll (vorbisfile.dll, ogg.dll,vorbisenc.dll, vorbis.dll), setting the Code Generation to "Multithread DLL" with visual Studio.
  • Include the "OpenAl_library\include" containing the directories AL and ALUT.
  • Link to : ALut.lib and OpenAL32.lib. The order is important.
  • Link to : vorbis.lib ogg.lib vorbisenc.lib vorbisfile.lib
  • Adjust for your need the #define and #include of libOpenAl.h
  • You should replace all "printf" by your own version log message.
  • With CodeBlocks there is one warning with the last OpenALSDK 1

Documentation

  • Create the object from the class with createManager() or the createManager(int max_sources, int max_buffers ) if you want to specify those Values. Be careful with this second method! Default values are 64 and 16
  • Call the init() function
  • Call the loadDefaultSounds() function to PRE-LOAD audio into the buffers. This is optional. Review the function to make changes that you need.
  • Set the listener location by calling setListenerPosition() function continually call this as your Listener (camera) position changes!
  • For each object that emits sound, call the loadSound() function. CAREFUL : The filename must be unique.
  • Optional : For each object you can set the all the parameters of the sound with setSound() or only the position, velocity and direction with setSoundPosition().
  • Call the playAudioSource() to play the sound at some event. This function will play the sound and then stop. It will NOT repeat playing. Use stopAudioSource() to stop a sound from playing if its still playing.
  • Call pauseAudio() or pauseAllAudio() to pause one or all sound(s).
  • Call resumeAudio() or resumeAllAudio() to resume one or all paused sound.
  • When your object is done emitting sounds (when out of range for example) call releaseAudioSource(). It is important to release your source when you are no longer going to need it because you are limited in the number of sources you can have.
  • If your objects moves (other than the listener/camera) then continually update the objects position by calling setSourcePosition().

Main.cpp

#include <iostream>
 #include "libOpenAl.h"
 
 int main()
 {
   std::cout << "Simple Sound Manager test application !" << std::endl;
   
   SoundManager* soundMgr = SoundManager::createManager();
   
   std::cout << soundMgr->listAvailableDevices();
   
   soundMgr->init();
   
   // careful : should not be used it doesn't use the resource limitation
   //soundMgr->testSound( "test.wav" );
   
   soundMgr->setAudioPath( (char*) ".\\" );
   
   unsigned int audioId;
 
   // We loop to be able to test the pause function
   soundMgr->loadAudio( "test.wav", &audioId, true);
 
 /*   
    // Set our LISTENER Location (i.e. the ears)
    // The listener is what hears the sounds emitted by audio sources.
    // Note: you only have ONE set of ears - i.e. there is only ONE listener.
    soundMgr->setListenerPosition( mPlayerSceneNode->getWorldPosition(),
        Ogre::Vector3::ZERO, mPlayerSceneNode->getOrientation() );
 
    // Set the Audio SOURCE location/position AND by default PLAY the audio.
    // Note how we reference the correct audio source by using 'mAudioSource'.
 
    soundMgr->setSound( audioId, mSomeObjectSceneNode->getWorldPosition(),
        Ogre::Vector3::ZERO, Ogre::Vector3::ZERO, 1000.0f, true, true, 1.0f );
 */
 
    // Play an Audio source - force a restart from the begining of the buffer.
    // That means, re-play the media file from the begining.
    soundMgr->playAudio( audioId, true );
 
    printf("Audio playing.  Type Enter.\n");
    getchar(); // To hear the sound until the end.
 
    soundMgr->pauseAudio( audioId );
 
    printf("Audio paused.  Type Enter.\n");
    getchar();
 
 //   soundMgr->resumeAudio( audioId );
    soundMgr->resumeAllAudio( );
 
    printf("Audio playing. Type Enter\n");
    getchar();
 
    // Force an audio source to stop playing.
    soundMgr->stopAudio( audioId );
    
   // Release an audio source when we are done with it.
   // This isn't required if you destruct the AudioEngine - as it cleans itself up.
   // But, you *SHOULD* do this when, for example, your SceneObject is no longer
   // in the scene for some reason. In other words, if you don't need this source
   // anymore then free up the resource. Remember, you are limited in audio sources.
   soundMgr->releaseAudio( audioId );
   
   delete soundMgr;
   
   return 0;
 }

libOpenAl.h

/**
 *  libOpenAl.h
 *
 *  Original Code : Van Stokes, Jr. (http://www.EvilMasterMindsInc.com) - Aug 05
 *  Modified Code : Steven Gay - mec3@bluewin.ch - Septembre 2005 - Jan 06
 *  Dll version   : Griffo Jean-Baptiste , crashy@antharia.org - Jan 06
 *
 *                    Partial Documentation
 *                    =====================
 *
 *  Very simple SoundManager using OpenAl. 
 *
 *  For a more complete one, you should see :
 *  OpenAL++ http://alpp.sourceforge.net/
 *
 ****************************************************************************
 *  COMPILE
 *
 *  - Don't forget to link to : ALut.lib and OpenAL32.lib.
 *    The order is important.
 *
 *  - With CodeBlocks there is one warning I didn't resolve :
 *     "Warning: .drectve `/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" ' unrecognized"
 *
 ****************************************************************************
 *  USAGE
 *
 * 1. Create the object from the class with createManager()
 * 
 * 2. Call the init() function
 *
 * 3. Call the loadDefaultSounds() function to PRE-LOAD audio into the buffers.
 *    This is optional. Review the function to make changes that you need.
 *
 * 4. Set the Listener Location by calling setListenerPosition() function
 *    continually call this as your Listener (camera) position changes!
 *
 * 5. For each object that emits sound, call the loadSound() function.
 *    CAREFUL : The filename must be unique.
 *
 * 6. Optional : For each object you can set the all the parameters of the
 *    sound with setSound() or only the position, velocity and direction with
 *    setSoundPosition().
 *
 * 7. Call the playAudioSource() to play the sound at some event.
 *    This function will play the sound and then stop. It will NOT repeat playing.
 *    Use stopAudioSource() to stop a sound from playing if its still playing 
 *
 * 8. Call pauseAudio() or pauseAllAudio() to pause one or all sound(s).
 *    Call resumeAudio() or resumeAllAudio() to resume one or all paused sound(s).
 *
 * 9. When your object is done emitting sounds (when out of range for example)
 *    call releaseAudioSource().
 *    It is important to release your source when you are no longer going to
 *    need it because you are limited in the number of sources you can have.
 *
 * 10. If your objects moves (other than the listener/camera) then
 *    continually update the objects position by calling setSourcePosition().
 *
 ******************************************************************************
 * 
 * Additional informations :
 *
 * Ogg Vorbis - http://www.xiph.org/downloads/
 *            - http://www.illiminable.com/ogg/
 * Flac       - http://flac.sourceforge.net/features.html
 * Theora     - http://www.theora.org/
 *
 *
 ******************************************************************************
 *
 * TODO
 *
 * loadOGG()
 * alSourcePause()
 *
 * Use the EAX functions !
 *
 ******************************************************************************/
 
 
 #ifndef __SOUNDMANAGER_H__
 #define __SOUNDMANAGER_H__
 
 
 
 #if  defined(USE_OPAL_SOUND_MGR)
         #if !defined(__MINGW32__) && !defined(__CYGWIN__)
              #define OPAL_SOUND_MGR __declspec(dllimport)
         #else
               #define OPAL_SOUND_MGR
         #endif
 #elif defined(CMP_OPAL_SOUND_MGR)
         #define OPAL_SOUND_MGR __declspec(dllexport)
 #else
         #define OPAL_SOUND_MGR
 #endif 
 
 #ifdef _WIN32
 #include <io.h>
 #include <fcntl.h>
 #endif
 
 #include <stdio.h>
 #include <string>
 
 // Comment this line if you don't have the EAX 2.0 SDK installed
 //#define _USEEAX
 
 #ifdef _USEEAX
    #include "eax.h"
 #endif
 
 // OpenAl version 1.0
 // #include <al/alctypes.h>
 // #include <al/altypes.h>
 // #include <al/alc.h>
 // #include <al/al.h>
 // #include <alut/alut.h>
 // OpenAl version 1.1
 #include <al.h>
 #include <alc.h>
 #include <alut.h>
 
 #include "codec.h"
 
 #include "vorbisfile.h"
 
 // Modify this as you need. 
 #ifdef OGRE 
   #include "OgreVector3.h" 
   #include "OgreQuaternion.h" 
   using namespace Ogre; 
 #else 
   #include "Vector3.h" 
   using namespace gameengine::utilities; 
 #endif
 
 
 
 // Used to store sound filenames
 #define MAX_FILENAME_LENGTH 40
 
 class OPAL_SOUND_MGR SoundManager
 {
  private:
       // EAX related
       bool isEAXPresent;
 #ifdef _USEEAX
       // EAX 2.0 GUIDs
       const GUID DSPROPSETID_EAX20_ListenerProperties
           = { 0x306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x0, 0x0, 0xe8, 0xd8, 0xc7, 0x22 } };
      
       const GUID DSPROPSETID_EAX20_BufferProperties
           = { 0x306a6a7, 0xb224, 0x11d2, {0x99, 0xe5, 0x0, 0x0, 0xe8, 0xd8, 0xc7, 0x22 } };
      
       EAXSet eaxSet; // EAXSet function, retrieved if EAX Extension is supported
       EAXGet eaxGet; // EAXGet function, retrieved if EAX Extension is supported
 #endif // _USEEAX
      
       bool isInitialised;
       ALCdevice* mSoundDevice;
       ALCcontext* mSoundContext;
      
       std::string mAudioPath;
      
       bool isSoundOn;
 
       ALfloat position[3];
       ALfloat velocity[3];
       ALfloat orientation[6];
      
       // Needed because of hardware limitation
       // Audio sources
       unsigned const short MAX_AUDIO_SOURCES;
       unsigned int mAudioSourcesInUseCount;
       unsigned int* mAudioSources;
       bool         *mAudioSourceInUse;
      
       // Audio buffers
       unsigned const short int MAX_AUDIO_BUFFERS;
       unsigned int mAudioBuffersInUseCount;
       unsigned int* mAudioBuffers;
       bool         *mAudioBufferInUse;
       std::map<int,std::string, std::less<int> > mAudioBufferFileName;
    
       // Function to check if the soundFile is already loaded into a buffer
       int locateAudioBuffer( std::string filename );
       int loadAudioInToSystem( std::string filename );
       bool loadWAV( std::string filename, ALuint pDestAudioBuffer );
       bool loadOGG( std::string filename, ALuint pDestAudioBuffer );
       bool loadOGGFile(std::string fileName, std::vector<char> &buffer, 
 ALenum &format,ALsizei &freq);
       // TODO bool loadAU( std::string filename, ALuint pDestAudioBuffer );
      
       // Ogg Vorbis extension
       bool bOggExtensionPresent;
      
   public:
       static SoundManager* mSoundManager;
      // SoundManager(void);
       SoundManager( int max_buffers, int max_sources );
       virtual ~SoundManager( void );
       void SoundManager::selfDestruct( void );
       static SoundManager* createManager( void );
       static SoundManager* createManager( int,int );
       static SoundManager* getSingletonPtr( void ) { return mSoundManager; };
 
       bool init( void );
       bool getIsSoundOn( void ) { return isSoundOn; };
       void setAudioPath( char* path ) { mAudioPath = std::string( path ); };
      
       bool checkALError( void );
       bool checkALError( std::string pMsg );
      
       /** See http://www.openal.org/windows_enumeration.html for installing other
       *   devices. You should at least have "Generic Hardware".
       */
       std::string listAvailableDevices( void );
      
       // careful : testSound should not be used it doesn't use the resource limitation
       void testSound( const char* wavFile );
      
       // Aquire an Audio Source
       // filename = pass in the sound file to play for this source (ex. "myfile.wav")
       // audioId   = returns the AudioSource identifier you will need for the PlayAudioSource();
       bool loadAudio( std::string filename, unsigned int *audioId, bool loop );
       bool releaseAudio( unsigned int audioID );
      
       // deprecated
       bool aquireAudioSource( char* file, unsigned int *audioId )
           { return loadAudio( std::string(file), audioId, false ); };
      
       // Returns true if the audio is started from the beginning
       // false if error or if already playing
       bool playAudio( unsigned int audioId, bool forceRestart );
       bool stopAudio( unsigned int audioID );
       bool stopAllAudio( void );
 
       bool pauseAudio( unsigned int audioID );
       bool pauseAllAudio( void );
       bool resumeAudio( unsigned int audioID );
       bool resumeAllAudio( void );
      
       bool setSoundPosition( unsigned int audioID, Vector3 position );
      
       bool setSoundPosition( unsigned int audioID, Vector3 position,
           Vector3 velocity, Vector3 direction );
          
       bool setSound( unsigned int audioID, Vector3 position,
           Vector3 velocity, Vector3 direction, float maxDistance,
           bool playNow, bool forceRestart, float minGain );
      
       bool setListenerPosition( Vector3 position, Vector3 velocity,
           Quaternion orientation );
      
       bool isOggExtensionPresent( void );
      
       bool setGain(unsigned int,float gain);
      
       /**
        * Preload audio files into the system.
        * Not obligatory, the files can also be loaded on the fly.
        */
       bool loadDefaultSounds( std::string filename );
       // Function to trim the trailing crap from a string.
       void trimTrailingSpace( char *s );
 
 };
 
 #endif /*__SOUNDMANAGER_H__*/

libOpenAl.cpp

#define CMP_OPAL_SOUND_MGR
 
 #include "libOpenAl.h"
 
 /**
 *  libOpenAl.cpp
 *
 *  Original Code : Van Stokes, Jr. (http://www.EvilMasterMindsInc.com) - Aug 05
 *  Modified Code : Steven Gay - mec3@bluewin.ch - Septembre 2005
 *  Dll version   : Griffo Jean-Baptiste , crashy@antharia.org - Jan 06
 */
 
 SoundManager* SoundManager::mSoundManager = NULL;
 
 /****************************************************************************/
 OPAL_SOUND_MGR SoundManager::SoundManager( int max_buffers=64, int max_sources =16 )
 : MAX_AUDIO_BUFFERS(max_buffers),MAX_AUDIO_SOURCES(max_sources)
 {
 
   mSoundManager = this;
 
   isInitialised = false;
   isSoundOn = false;
   mSoundDevice = 0;
   mSoundContext = 0;
   
   mAudioPath = "";
   
   // EAX related
   isEAXPresent = false;
  
   // Initial position of the listener
   position[0] = 0.0;
   position[1] = 0.0;
   position[2] = 0.0;
  
   // Initial velocity of the listener
   velocity[0] = 0.0;
   velocity[1] = 0.0;
   velocity[2] = 0.0;
  
   // Initial orientation of the listener = direction + direction up
   orientation[0] = 0.0;
   orientation[1] = 0.0;
   orientation[2] = -1.0;
   orientation[3] = 0.0;
   orientation[4] = 1.0;
   orientation[5] = 0.0;
  
   // Needed because of hardware limitation
   mAudioBuffersInUseCount = 0;
   mAudioSourcesInUseCount = 0;
   mAudioSources=new unsigned int[MAX_AUDIO_SOURCES];
   mAudioSourceInUse=new bool[MAX_AUDIO_SOURCES];
 
   for ( int i=0; i < MAX_AUDIO_SOURCES; i++ )
   {
      mAudioSources[i] = 0;
      mAudioSourceInUse[i] = false;
   }
 
    mAudioBuffers=new unsigned int[MAX_AUDIO_BUFFERS];
    mAudioBufferInUse=new bool[MAX_AUDIO_BUFFERS];
   for ( int i=0; i < MAX_AUDIO_BUFFERS; i++ )
   {
      mAudioBuffers[i] = 0;
      
      mAudioBufferInUse[i] = false;
   }
  
  printf("SoudManager Created.\n");
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR SoundManager::~SoundManager( void )
 {
  // Delete the sources and buffers
  alDeleteSources( MAX_AUDIO_SOURCES, mAudioSources );
  alDeleteBuffers( MAX_AUDIO_BUFFERS, mAudioBuffers );
  
   // Destroy the sound context and device
   mSoundContext = alcGetCurrentContext();
   mSoundDevice = alcGetContextsDevice( mSoundContext );
   alcMakeContextCurrent( NULL );
   alcDestroyContext( mSoundContext );
   if ( mSoundDevice)
       alcCloseDevice( mSoundDevice );
  
   alutExit();
  
  printf("SoudManager Destroyed.\n");
  mAudioBufferFileName.clear();
  delete mAudioSources;
  delete mAudioSourceInUse;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR void SoundManager::selfDestruct( void )
 {
  if ( getSingletonPtr() ) delete getSingletonPtr();
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR SoundManager* SoundManager::createManager( void )
 {
  if (mSoundManager == 0)
       mSoundManager = new SoundManager();
   return mSoundManager;
 }
 OPAL_SOUND_MGR SoundManager* SoundManager::createManager( int max_sources, int max_buffers )
 {
  if (mSoundManager == 0)
       mSoundManager = new SoundManager(max_sources,max_buffers);
   return mSoundManager;
 }
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::init( void )
 {
  // It's an error to initialise twice OpenAl
  if ( isInitialised ) return true;
 
  // Open an audio device
  mSoundDevice = alcOpenDevice( NULL ); // TODO ((ALubyte*) "DirectSound3D");
  // mSoundDevice = alcOpenDevice( "DirectSound3D" );
 
  // Check for errors
  if ( !mSoundDevice )
  {
     printf( "SoundManager::init error : No sound device.\n");
     return false;
  }
   
  mSoundContext = alcCreateContext( mSoundDevice, NULL );
 //   if ( checkAlError() || !mSoundContext ) // TODO seems not to work! why ?
  if ( !mSoundContext )
  {
     printf( "SoundManager::init error : No sound context.\n");
     return false;
  }
  
  // Make the context current and active
  alcMakeContextCurrent( mSoundContext );
  if ( checkALError( "Init()" ) )
  {
     printf( "SoundManager::init error : could not make sound context current and active.\n");
     return false;
  }
  
  // Check for EAX 2.0 support and
  // Retrieves function entry addresses to API ARB extensions, in this case,
  // for the EAX extension. See Appendix 1 (Extensions) of
  // http://www.openal.org/openal_webstf/specs/OpenAL1-1Spec_html/al11spec7.html
  //
  // TODO EAX fct not used anywhere in the code ... !!!
  isEAXPresent = alIsExtensionPresent( "EAX2.0" );
  if ( isEAXPresent )
  {
     printf( "EAX 2.0 Extension available\n" );
 
 #ifdef _USEEAX
       eaxSet = (EAXSet) alGetProcAddress( "EAXSet" );
       if ( eaxSet == NULL )
           isEAXPresent = false;
 
       eaxGet = (EAXGet) alGetProcAddress( "EAXGet" );
       if ( eaxGet == NULL )
           isEAXPresent = false;
  
       if ( !isEAXPresent )
           checkALError( "Failed to get the EAX extension functions adresses.\n" );
 #else
       isEAXPresent = false;
       printf( "... but not used.\n" );
 #endif // _USEEAX
 
  }
 
  // Test if Ogg Vorbis extension is present
  isOggExtensionPresent();
  
  // Create the Audio Buffers
  alGenBuffers( MAX_AUDIO_BUFFERS, mAudioBuffers );
  if (checkALError("init::alGenBuffers:") )
       return false;
  
  // Generate Sources
  alGenSources( MAX_AUDIO_SOURCES, mAudioSources );
  if (checkALError( "init::alGenSources :") )
       return false;
 
  
  // Setup the initial listener parameters
  // -> location
  alListenerfv( AL_POSITION, position );
   
  // -> velocity
  alListenerfv( AL_VELOCITY, velocity );
  
  // -> orientation
  alListenerfv( AL_ORIENTATION, orientation );
  
  // Gain
  alListenerf( AL_GAIN, 1.0 );
  
  // Initialise Doppler
  alDopplerFactor( 1.0 ); // 1.2 = exaggerate the pitch shift by 20%
  alDopplerVelocity( 343.0f ); // m/s this may need to be scaled at some point
  
  // Ok
  isInitialised = true;
  isSoundOn = true;
 
  printf( "SoundManager initialised.\n\n");
  
  return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::checkALError( void )
 {
  ALenum errCode;
  if ( ( errCode = alGetError() ) != AL_NO_ERROR )
  {
     std::string err = "ERROR SoundManager:: ";
     err += (char*) alGetString( errCode );
     
     printf( "%s\n", err.c_str());
     return true;
  }
  return false;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR std::string SoundManager::listAvailableDevices( void )
 {
  std::string str = "Sound Devices available : ";
  
  if ( alcIsExtensionPresent( NULL, "ALC_ENUMERATION_EXT" ) == AL_TRUE )
  {
       str = "List of Devices : ";
       str += (char*) alcGetString( NULL, ALC_DEVICE_SPECIFIER );
       str += "\n";
  }
  else
       str += " ... eunmeration error.\n";
  
   return str;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::checkALError( std::string pMsg )
 {
  ALenum error = 0;
  
   if ( (error = alGetError()) == AL_NO_ERROR )
   return false;
 
  char mStr[256];
  switch ( error )
  {
       case AL_INVALID_NAME:
           sprintf(mStr,"ERROR SoundManager::%s Invalid Name", pMsg.c_str());
           break;
       case AL_INVALID_ENUM:
           sprintf(mStr,"ERROR SoundManager::%s Invalid Enum", pMsg.c_str());
           break;
       case AL_INVALID_VALUE:
           sprintf(mStr,"ERROR SoundManager::%s Invalid Value", pMsg.c_str());
           break;
       case AL_INVALID_OPERATION:
           sprintf(mStr,"ERROR SoundManager::%s Invalid Operation", pMsg.c_str());
           break;
       case AL_OUT_OF_MEMORY:
           sprintf(mStr,"ERROR SoundManager::%s Out Of Memory", pMsg.c_str());
           break;
       default:
           sprintf(mStr,"ERROR SoundManager::%s Unknown error (%i) case in testALError()",
  pMsg.c_str(), error);
           break;
  };
  
  printf( "%s\n", mStr );
  
  return true;
 }
 
 /*****************************************************************************/
 OPAL_SOUND_MGR void SoundManager::testSound( const char* wavFile )
 {
  ALuint buffer;
  ALuint source;
  ALenum format;
  ALsizei size;
  ALvoid* data;
  ALsizei freq;
  ALboolean loop;
  alGenBuffers( 1, &buffer );
  if ( checkALError( "testSound()" ) )
      return;
   
  // This is the same for alutLoadWAVMemory
 #ifndef MACINTOSH_AL
  alutLoadWAVFile( (ALbyte*) wavFile, &format, &data, &size, &freq, &loop );
 #else
  alutLoadWAVFile( (ALbyte*) wavFile, &format, &data, &size, &freq );
 #endif
 
  alBufferData( buffer, format, data, size, freq );
  
  alutUnloadWAV( format, data, size, freq );
  alGenSources( 1, &source );
  alSourcei( source, AL_BUFFER, buffer );
  alSourcef( source, AL_PITCH, 1.0f );
  alSourcef( source, AL_GAIN, 1.0f );
 
 #ifndef MACINTOSH_AL
  alSourcei( source, AL_LOOPING, loop );
 #else
  alSourcei( source, AL_LOOPING, false ); // TODO ! But how to get from file?
 #endif
  
  alSourcePlay( source );
  
  //Or else we risk to destroy the manager too quickly to here anything !
  for (int i=0;i<50000; i++) {printf(".");};
 }
 
 // Attempts to aquire an empty audio source and assign it back to the caller
 // via AudioSourceID. This will lock the source
 /*****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::loadAudio( std::string filename, unsigned int *audioId,
   bool loop )
 {
  if ( filename.empty() || filename.length() > MAX_FILENAME_LENGTH )
       return false;
  
  if ( mAudioSourcesInUseCount == MAX_AUDIO_SOURCES )
       return false;   // out of Audio Source slots!
 
  int bufferID = -1;   // Identity of the Sound Buffer to use
  int sourceID = -1;   // Identity of the Source Buffer to use
 
  alGetError();    // Clear Error Code
 
  // Check and see if the pSoundFile is already loaded into a buffer
  bufferID = locateAudioBuffer( filename );
  if ( bufferID < 0 )
  {
     // The sound file isn't loaded in a buffer, lets attempt to load it on the fly
     bufferID = loadAudioInToSystem( filename );
     if ( bufferID < 0 ) return false;   // failed!
  }
 
  // If you are here, the sound the requester wants to reference is in a buffer.
  // Now, we need to find a free Audio Source slot in the sound system
  sourceID = 0;
  
  while ( mAudioSourceInUse[ sourceID ] == true ) sourceID++;
  
  // When you are here, 'mSourceID' now represents a free Audio Source slot
  // The free slot may not be at the end of the array but in the middle of it.
  *audioId = sourceID;  // return the Audio Source ID to the caller
  mAudioSourceInUse[ sourceID ] = true; // mark this Source slot as in use
  mAudioSourcesInUseCount++;    // bump the 'in use' counter
  
  // Now inform OpenAL of the sound assignment and attach the audio buffer
  // to the audio source
  alSourcei( mAudioSources[sourceID], AL_BUFFER, mAudioBuffers[bufferID] );
  
  // Steven : Not in the original code !!!!!
  alSourcei( mAudioSources[sourceID], AL_LOOPING, loop );
  
  if ( checkALError( "loadSource()::alSourcei" ) )
       return false;
  
  return true;
 }
 
 // Function to check and see if the pSoundFile is already loaded into a buffer
 /*****************************************************************************/
 OPAL_SOUND_MGR int SoundManager::locateAudioBuffer( std::string filename )
 {
  for ( unsigned int b = 0; b < MAX_AUDIO_BUFFERS; b++ )
  {
     if (filename == mAudioBufferFileName[b] ) return (int) b; 
     //Surely a way to optimize it with the MAP
  }
  return -1;      // not found
 }
 
 // Function to load a sound file into an AudioBuffer
 /*****************************************************************************/
 OPAL_SOUND_MGR int SoundManager::loadAudioInToSystem( std::string filename )
 {
  if ( filename.empty() )
       return -1;
  
  // Make sure we have audio buffers available
  if ( mAudioBuffersInUseCount == MAX_AUDIO_BUFFERS ) return -1;
  
  // Find a free Audio Buffer slot
  int bufferID = 0;      // Identity of the Sound Buffer to use
  
  while ( mAudioBufferInUse[ bufferID ] == true ) bufferID++;
  
  // load .wav, .ogg or .au
   if ( filename.find( ".wav", 0 ) != std::string::npos )
   {
      printf(" ---> found Wav\n");
     // When you are here, bufferID now represents a free Audio Buffer slot
       // Attempt to load the SoundFile into the buffer
      if ( !loadWAV( filename, mAudioBuffers[ bufferID ] ) ) return -1;
  }
  else if ( filename.find( ".ogg", 0 ) != std::string::npos )
  {
      printf(" ---> found ogg\n");
      std::cout<<filename<<std::endl;
      if ( !loadOGG( filename, mAudioBuffers[bufferID ]) ) return -1;
    
  }
  else if ( filename.find( ".au", 0 ) != std::string::npos )
  {
     printf(" ---> found au\n");
     // TODO if ( !loadAU( filename, mAudioBuffers[mBufferID]) ) return -1;
  }
  
  // Successful load of the file into the Audio Buffer.
  mAudioBufferInUse[ bufferID ] = true;      // Buffer now in use
  mAudioBufferFileName[bufferID]=filename;   // save the file descriptor
 
  
  mAudioBuffersInUseCount++;               // bump the 'in use' counter
  
  return bufferID;
 }
 
 // Function to load a wave file and assigned it to a buffer
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::loadWAV( std::string filename, ALuint pDestAudioBuffer )
 {
  ALenum      format;         //for the buffer format
  ALsizei      size;         //the bit depth
  ALsizei      freq;         //for the frequency of the buffer
  ALboolean   loop;         //looped
  ALvoid*      data;         //data for the buffer
  
  std::string mFullPath = mAudioPath;
 
  alGetError();   // Clear Error Code
 
  // Load in the WAV file from disk
  //mFullPath += "\\";
  mFullPath += filename;
  
 #ifndef MACINTOSH_AL
   alutLoadWAVFile( (ALbyte*)mFullPath.c_str(), &format, &data, &size, &freq, &loop);
 #else
   alutLoadWAVFile( (ALbyte*)mFullPath.c_str(), &format, &data, &size, &freq);
 #endif
  
  if ( checkALError("loadWAV::alutLoadWAVFile: ") )
     return false;
 
  // Copy the new WAV data into the buffer
  alBufferData(pDestAudioBuffer, format, data, size, freq);
  if ( checkALError("loadWAV::alBufferData: ") )
     return false;
 
  // Unload the WAV file
  alutUnloadWAV(format, data, size, freq);
  if ( checkALError("loadWAV::alutUnloadWAV: ") )
     return false;
 
  return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::playAudio( unsigned int audioID, bool forceRestart )
 { 
  // Make sure the audio source ident is valid and usable
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID])
       return false;
  
  int sourceAudioState = 0;
  
  alGetError();
  
  // Are we currently playing the audio source?
  alGetSourcei( mAudioSources[audioID], AL_SOURCE_STATE, &sourceAudioState );
  
  if ( sourceAudioState == AL_PLAYING )
  {
     if ( forceRestart )
          stopAudio( audioID );
       else
           return false; // Not forced, so we don't do anything
  }
  
  alSourcePlay( mAudioSources[ audioID ] );
  if ( checkALError( "playAudio::alSourcePlay: ") )
       return false;
  
   return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::pauseAudio( unsigned int audioID )
 {
  // Make sure the audio source ident is valid and usable
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID] )
       return false;
 
  alGetError();
 
  alSourcePause( mAudioSources[audioID] );
 
  if ( checkALError( "pauseAudio::alSourceStop ") )
       return false;
 
   return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::pauseAllAudio( void )
 {
  if ( mAudioSourcesInUseCount >= MAX_AUDIO_SOURCES )
       return false;
 
  alGetError();
 
  alSourcePausev( mAudioSourcesInUseCount, mAudioSources );
 
  if ( checkALError( "pauseAllAudio::alSourceStop ") )
       return false;
 
   return true;
 }
 
 // We could use playAudio instead !
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::resumeAudio( unsigned int audioID )
 {
  // Make sure the audio source ident is valid and usable
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID] )
       return false;
 
  alGetError();
 
  // If the sound was paused the sound will resume, else it will play from
  // the beginning !
  // TODO No check for forced restart. Verify if it is what you want ?
  alSourcePlay( mAudioSources[ audioID ] );
 
  if ( checkALError( "resumeAudio::alSourceStop ") )
       return false;
 
   return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::resumeAllAudio( void )
 {
  if ( mAudioSourcesInUseCount >= MAX_AUDIO_SOURCES )
       return false;
 
  alGetError();
 
  int sourceAudioState = 0;
 
  for ( int i=0; i<mAudioSourcesInUseCount; i++ )
  {
      // Are we currently playing the audio source?
      alGetSourcei( mAudioSources[i], AL_SOURCE_STATE, &sourceAudioState );
 
      if ( sourceAudioState == AL_PAUSED )
      {
          resumeAudio( i );
      }
  }
 
  if ( checkALError( "resumeAllAudio::alSourceStop ") )
       return false;
 
   return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::stopAudio( unsigned int audioID )
 {
  // Make sure the audio source ident is valid and usable
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID] )
       return false;
  
  alGetError();
  
  alSourceStop( mAudioSources[audioID] );
  
  if ( checkALError( "stopAudio::alSourceStop ") )
       return false;
  
   return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::stopAllAudio( void )
 {
  if ( mAudioSourcesInUseCount >= MAX_AUDIO_SOURCES )
       return false;
 
  alGetError();
 
  for ( int i=0; i<mAudioSourcesInUseCount; i++ )
  {
      stopAudio( i );
  }
 
  if ( checkALError( "stopAllAudio::alSourceStop ") )
       return false;
 
   return true;
 }
  
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::releaseAudio( unsigned int audioID )
 {
  if ( audioID >= MAX_AUDIO_SOURCES )
       return false;
  alSourceStop( mAudioSources[audioID] );
  mAudioSourceInUse[ audioID ] = false;
  mAudioSourcesInUseCount--;
   return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::setSound( unsigned int audioID, Vector3 position,
   Vector3 velocity, Vector3 direction, float maxDistance,
   bool playNow, bool forceRestart, float minGain )
 {
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[ audioID ] )
       return false;
  
  // Set the position
  ALfloat pos[] = { position.x, position.y, position.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_POSITION, pos );
  
  if ( checkALError( "setSound::alSourcefv:AL_POSITION" ) )
      return false;
  
  // Set the veclocity
  ALfloat vel[] = { velocity.x, velocity.y, velocity.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_VELOCITY, vel );
  
  if ( checkALError( "setSound::alSourcefv:AL_VELOCITY" ) )
      return false;
   
  // Set the direction
  ALfloat dir[] = { velocity.x, velocity.y, velocity.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_DIRECTION, dir );
  
  if ( checkALError( "setSound::alSourcefv:AL_DIRECTION" ) )
      return false;
  
  // Set the max audible distance
  alSourcef( mAudioSources[ audioID ], AL_MAX_DISTANCE, maxDistance );
  
  // Set the MIN_GAIN ( IMPORTANT - if not set, nothing audible! )
  alSourcef( mAudioSources[ audioID ], AL_MIN_GAIN, minGain );
  
  // Set the max gain
  alSourcef( mAudioSources[ audioID ], AL_MAX_GAIN, 1.0f ); // TODO as parameter ? global ?
  
  // Set the rollof factor
  alSourcef( mAudioSources[ audioID ], AL_ROLLOFF_FACTOR, 1.0f ); // TODO as parameter ?
  
  // Do we play the sound now ?
  if ( playNow ) return playAudio( audioID, forceRestart ); // TODO bof... not in this fct
  
  return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::setSoundPosition( unsigned int audioID, Vector3 position )
 {
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[ audioID ] )
       return false;
  
  // Set the position
  ALfloat pos[] = { position.x, position.y, position.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_POSITION, pos );
  
  if ( checkALError( "setSound::alSourcefv:AL_POSITION" ) )
      return false;
 
  return true;
 } 
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::setSoundPosition( unsigned int audioID, Vector3 position,
   Vector3 velocity, Vector3 direction )
 {
  if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[ audioID ] )
       return false;
  
  // Set the position
  ALfloat pos[] = { position.x, position.y, position.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_POSITION, pos );
  
  if ( checkALError( "setSound::alSourcefv:AL_POSITION" ) )
      return false;
  
  // Set the veclocity
  ALfloat vel[] = { velocity.x, velocity.y, velocity.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_VELOCITY, vel );
  
  if ( checkALError( "setSound::alSourcefv:AL_VELOCITY" ) )
      return false;
  
  // Set the direction
  ALfloat dir[] = { velocity.x, velocity.y, velocity.z };
  
  alSourcefv( mAudioSources[ audioID ], AL_DIRECTION, dir );
   
  if ( checkALError( "setSound::alSourcefv:AL_DIRECTION" ) )
      return false;
  
  return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::setListenerPosition( Vector3 position, Vector3 velocity,
   Quaternion orientation )
 {
  Vector3 axis;
  
  // Set the position
  ALfloat pos[] = { position.x, position.y, position.z };
  
  alListenerfv( AL_POSITION, pos );
  
  if ( checkALError( "setListenerPosition::alListenerfv:AL_POSITION" ) )
      return false;
  
  // Set the veclocity
  ALfloat vel[] = { velocity.x, velocity.y, velocity.z };
  
  alListenerfv( AL_VELOCITY, vel );
  
  if ( checkALError( "setListenerPosition::alListenerfv:AL_VELOCITY" ) )
      return false;
  
  // Orientation of the listener : look at then look up
  axis = Vector3::ZERO;
  axis.x = orientation.getYaw().valueRadians();
  axis.y = orientation.getPitch().valueRadians();
  axis.z = orientation.getRoll().valueRadians();
  
  // Set the direction
  ALfloat dir[] = { axis.x, axis.y, axis.z };
  
  alListenerfv( AL_ORIENTATION, dir );
  
  if ( checkALError( "setListenerPosition::alListenerfv:AL_DIRECTION" ) )
      return false;
  
  // TODO as parameters ?
  alListenerf( AL_MAX_DISTANCE, 10000.0f );
  alListenerf( AL_MIN_GAIN, 0.0f );
  alListenerf( AL_MAX_GAIN, 1.0f );
  alListenerf( AL_GAIN, 1.0f );
  
  return true;
 }
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::isOggExtensionPresent( void )
 {
  if ( alIsExtensionPresent( "AL_EXT_vorbis" ) != AL_TRUE )
  {
   printf("ERROR: SoundManager::isOggExtensionPresent : Ogg Vorbis extension not   availablee!\n");
     bOggExtensionPresent = false;
     return false;
  }
  return true;
 } 
 
 // Function to load a wave file and assigned it to a buffer
 // This code was taken from the plugin found on this forum :
 // http://www.ogre3d.org/phpBB2/viewtopic.php?t=7234
 //
 // TODO I didn't integrate it fow now .. because I don't need it now :-)
 //
 /****************************************************************************/
 
 OPAL_SOUND_MGR bool SoundManager::loadOGGFile(std::string fileName, std::vector<char> &buffer,
 ALenum &format, ALsizei &freq)
 {
    #define BUFFER_SIZE     32768       // 32 KB buffers
    int endian = 0;                         // 0 for Little-Endian, 1 for Big-Endian
    int bitStream;
    long bytes;
    char array[BUFFER_SIZE];                // Local fixed size array
    FILE *f;
 
    // Open for binary reading
    f = fopen(fileName.c_str(), "rb");
 
    if (f == NULL)
        {
  		std::cout << "Cannot open " << fileName << " for reading..." << std::endl;
        exit(-1);
        }
   
 
    vorbis_info *pInfo;
    OggVorbis_File oggFile;
 
    // Try opening the given file
    if (ov_open(f, &oggFile, NULL, 0) != 0)
        {
        std::cout << "Error opening " << fileName << " for decoding..." << std::endl;
        exit(-1);
        }
  
 
    // Get some information about the OGG file
    pInfo = ov_info(&oggFile, -1);
 
    // Check the number of channels... always use 16-bit samples
    if (pInfo->channels == 1)
        format = AL_FORMAT_MONO16;
    else
        format = AL_FORMAT_STEREO16;
    
 
    // The frequency of the sampling rate
    freq = pInfo->rate;
 
    // Keep reading until all is read
    do
        {
        // Read up to a buffer's worth of decoded sound data
         bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream);
 
        if (bytes < 0)
            {
            ov_clear(&oggFile);
            std::cout << "Error decoding " << fileName << "..." << std::endl;
            exit(-1);
            }
        
 
        // Append to end of buffer
        buffer.insert(buffer.end(), array, array + bytes);
        }
    while (bytes > 0);
 
    // Clean up!
    ov_clear(&oggFile);
    return true;
 }
 OPAL_SOUND_MGR bool SoundManager::loadOGG( std::string filename, ALuint pDestAudioBuffer )
 {
  ALenum       format;         //for the buffer format
  ALsizei      size;         //the bit depth
  ALsizei      freq;         //for the frequency of the buffer
  ALboolean    loop;         //looped
 
  std::vector<char> bufferData;                // The sound buffer data from file
  
  std::string mFullPath = mAudioPath;
 
  alGetError();   // Clear Error Code
 
  mFullPath += filename;
  
 
   loadOGGFile( mFullPath, bufferData,format,freq);
 
 
  alBufferData(pDestAudioBuffer, format, &bufferData[0], static_cast<ALsizei>(bufferData.size())
   , freq);
 
 
 
 
  return true;
 } 
  /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::setGain( unsigned int audioID, float gain) 
  {
	if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[ audioID ] )
       return false;

		alSourcef(mAudioSources[audioID],AL_GAIN,gain);
	return true;
}
 
 
 
 
 
 
 /****************************************************************************/
 OPAL_SOUND_MGR bool SoundManager::loadDefaultSounds( std::string filename )
 {
  FILE *myfile;
  unsigned linecount=0;
  char key[255], buff[512];
 
  if ( (myfile = fopen( filename.c_str() ,"r") )==NULL )
  {
    sprintf(buff, "---> Can't Open File: %s\n", filename.c_str() );
    printf( "SoundManager::loadDefaultSounds : %s\n", buff );
    return false;
  }
  fseek(myfile,0L,SEEK_SET);    // Make sure we are at the begining of the file
  
  while (!feof(myfile))
  {
    fgets(buff,sizeof(buff),myfile);   // Read a line from the file.
    linecount++;
    
    if (strncmp(buff,"#",1) &&        // Is this a comment line?
        strncmp(buff,"",1) &&
        strncmp(buff,"/",1))
    {
      // We have some data, attempt to load it
      strcpy(key,buff);
      trimTrailingSpace(key);
      	
      // First, make sure it isn't already loaded
      if ( locateAudioBuffer( key ) < 0 )
      {
        // Nope, its not already loaded
        if ( loadAudioInToSystem( key ) < 0 )
        {
          sprintf(buff,"Can't load audio file: %s\n",key);
          printf( "SoundManager::loadDefaultSounds() : %s\n", buff );
        }
      }
    }
  }
  
  // Were done
  fclose(myfile);
  return true;
 }
 
 // Function to trim the trailing crap from a string.
 /****************************************************************************/
 OPAL_SOUND_MGR void SoundManager::trimTrailingSpace( char *s )
 {
  char *p;
  p = s;
  if (p == NULL) return;
  for (unsigned i=0;i < (strlen(s)+1);i++)
  {
    if (__iscsym(*p) == 0 && *p != '.' && *p != '-')
    {
      *p='\0';
      break;
    }
    p++;
  }
 }

1

"Warning: .drectve `/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" ' unrecognized"

I found a message on this problem : http://opensource.creative.com/pipermail/openal/2005-July/003087.html

> I think I found the cause.

>

> ALut.c includes

> alMain.h which includes

> alListener.h and alSource.h which both include

> eax.h which includes

> dsound.h which includes

> objbase.h which on line 48 has

> #pragma comment(lib, "uuid.lib")

Bah. Damn pragmas. That was it — thanks everyone for the help...

I checked-in a new ALut.c, so this is now fixed for the public OpenAL

repository. (I suppose I should define "fixed" — the uuid.lib directive is

no longer in alut.lib, but I have _not_ tried a CrystalSpace build, so there

still may be errors lurking.)

The next update of the OpenAL SDK will have the fix in it as well, of course.

Garin

<HR>
Creative Commons Copyright -- Some rights reserved.


THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

  • "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
  • "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  • "Licensor" means the individual or entity that offers the Work under the terms of this License.
  • "Original Author" means the individual or entity who created the Work.
  • "Work" means the copyrightable work of authorship offered under the terms of this License.
  • "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
  • "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.

2. Fair Use Rights

Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

3. License Grant

Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

  • to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
  • to create and reproduce Derivative Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
  • For the avoidance of doubt, where the work is a musical composition:
    • Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    • Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
    • Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).


The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

4. Restrictions

The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

  • You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
  • You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
  • If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability.

EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. Termination

  • This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
  • Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.

8. Miscellaneous

  • Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
  • Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
  • If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  • No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
  • This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.