Logo Search packages:      
Sourcecode: blender version File versions  Download package

void AUD_SoftwareDevice::mix ( sample_t *  buffer,
int  length 
) [protected]

Mixes the next samples into the buffer.

Parameters:
buffer The target buffer.
length The length in samples to be filled.

Definition at line 93 of file AUD_SoftwareDevice.cpp.

References AUD_IMixer::add(), AUD_Specs::format, AUD_IReader::getSpecs(), AUD_SoftwareHandle::keep, lock(), m_mixer, m_playingSounds, m_specs, m_volume, pause(), AUD_IReader::read(), AUD_SoftwareHandle::reader, stop(), AUD_IMixer::superpose(), unlock(), and AUD_SoftwareHandle::volume.

Referenced by AUD_JackDevice::jack_mix(), AUD_ReadDevice::read(), and AUD_SDLDevice::SDL_mix().

{
      lock();

      {
            AUD_SoftwareHandle* sound;
            int len;
            sample_t* buf;
            int sample_size = AUD_SAMPLE_SIZE(m_specs);
            std::list<AUD_SoftwareHandle*> stopSounds;

            // for all sounds
            AUD_HandleIterator it = m_playingSounds->begin();
            while(it != m_playingSounds->end())
            {
                  sound = *it;
                  // increment the iterator to make sure it's valid,
                  // in case the sound gets deleted after stopping
                  ++it;

                  // get the buffer from the source
                  len = length;
                  sound->reader->read(len, buf);

                  m_mixer->add(buf, sound->reader->getSpecs(), len, sound->volume);

                  // in case the end of the sound is reached
                  if(len < length)
                  {
                        if(sound->keep)
                              pause(sound);
                        else
                              stopSounds.push_back(sound);
                  }
            }

            // fill with silence
            if(m_specs.format == AUD_FORMAT_U8)
                  memset(buffer, 0x80, length * sample_size);
            else
                  memset(buffer, 0, length * sample_size);

            // superpose
            m_mixer->superpose(buffer, length, m_volume);

            while(!stopSounds.empty())
            {
                  sound = stopSounds.front();
                  stopSounds.pop_front();
                  stop(sound);
            }
      }

      unlock();
}


Generated by  Doxygen 1.6.0   Back to index