Example #1
0
 Sound *Sound::Create(const std::string &inFilename,bool inForceMusic)
 {
    //Always check if openal is intitialized
    if (!OpenALInit())
       return 0;
    
    //Return a reference
    OpenALSound *sound;
    
    #ifdef ANDROID
    if (!inForceMusic)
    {
       ByteArray bytes = AndroidGetAssetBytes(inFilename.c_str());
       sound = new OpenALSound((float*)bytes.Bytes(), bytes.Size());
    }
    else
    {
       sound = new OpenALSound(inFilename, inForceMusic);
    }
    #else
    sound = new OpenALSound(inFilename, inForceMusic);
    #endif
    
    if (sound->ok ())
       return sound;
    else
       return 0;
 }
Example #2
0
 SoundChannel *SoundChannel::Create(const ByteArray &inBytes,const SoundTransform &inTransform)
 {
    if (!OpenALInit())
       return 0;
    
    return new OpenALChannel(inBytes, inTransform);
 }
Example #3
0
SoundSource::SoundSource(string soundFileName, OpenGLApplicationBase * OpenGLApp )
	:VisualObject( OpenGLApp ), soundFileName(soundFileName)
{
	if ( SoundSource::soundInitialized == false ) {

		OpenALInit();
		SoundSource::soundInitialized = true;
	}

}
Example #4
0
   Sound *Sound::Create(float *inData, int len, bool inForceMusic)
   {
      //Always check if openal is intitialized
      if (!OpenALInit())
         return 0;

      //Return a reference
      OpenALSound *sound = new OpenALSound(inData, len);
      
      if (sound->ok ())
         return sound;
      else
         return 0;
   }
Example #5
0
SoundSource::SoundSource(string soundFileName )
	:VisualObject( ), soundFileName(soundFileName)
{
	// Initialize OpenAL if it has not been initialized yet
	if ( SoundSource::soundInitialized == false ) {

		OpenALInit();
		SoundSource::soundInitialized = true;
	}

	// Load the sound 
	ALuint      uiBuffer;

	// Generate an AL Buffer
	alGenBuffers( 1, &uiBuffer );

	// Load Wave file into OpenAL Buffer
	if (!ALFWLoadWaveToBuffer(soundFileName.c_str(), uiBuffer)) {

		ALFWprintf("Failed to load %s.\n", soundFileName.c_str());
	}
	else {

		ALFWprintf("Loaded %s sound file.\n", soundFileName.c_str());
	
		// Generate a Source to playback the Buffer
		alGenSources( 1, &uiSource );

		// Attach Source to Buffer
		alSourcei( uiSource, AL_BUFFER, uiBuffer );
		
		// Set source properties
		alSourcef(uiSource, AL_PITCH, 1.0f); // pitch multiplier 
		alSourcef(uiSource, AL_GAIN, 1.0f); // source gain value 
	
		// determines if the positions are relative to the listener
		alSourcei(uiSource, AL_SOURCE_RELATIVE, AL_FALSE);

		// Position for sound sources
		alSource3f( uiSource, AL_POSITION, 0.0, 0.0, 0.0);

		// Velocity for sound sources
		alSource3f(uiSource, AL_VELOCITY, 0.0, 0.0, 0.0);

	}

} // end SoundSource constructor
Example #6
0
 void Sound::Suspend()
 {
    //Always check if openal is initialized
    if (!OpenALInit())
       return;
    
    OpenALChannel* channel = 0;
    for (int i = 0; i < sgOpenChannels.size(); i++)
    {
       channel = (OpenALChannel*)(sgOpenChannels[i]);
       if (channel)
       {
          channel->suspend();
       }
    }
    
    alcMakeContextCurrent(0);
    alcSuspendContext(sgContext);
    
    #ifdef ANDROID
    alcSuspend();
    #endif
 }
Example #7
0
 void Sound::Resume()
 {
    //Always check if openal is initialized
    if (!OpenALInit())
       return;
    
    #ifdef ANDROID
    alcResume();
    #endif
    
    alcMakeContextCurrent(sgContext);
    
    OpenALChannel* channel = 0;
    for (int i = 0; i < sgOpenChannels.size(); i++)
    {
       channel = (OpenALChannel*)(sgOpenChannels[i]);
       if (channel)
       {
          channel->resume();
       }
    }
    
    alcProcessContext(sgContext);
 }