| 82 | } |
| 83 | |
| 84 | void SFXALBuffer::write( SFXInternal::SFXStreamPacket* const* packets, U32 num ) |
| 85 | { |
| 86 | using namespace SFXInternal; |
| 87 | |
| 88 | if( !num ) |
| 89 | return; |
| 90 | |
| 91 | // If this is not a streaming buffer, just load the data into our single |
| 92 | // static buffer. |
| 93 | |
| 94 | if( !isStreaming() ) |
| 95 | { |
| 96 | SFXStreamPacket* packet = packets[ num - 1 ]; |
| 97 | |
| 98 | ALenum alFormat = _sfxFormatToALFormat( getFormat() ); |
| 99 | AssertFatal( alFormat != 0, "SFXALBuffer::write() - format unsupported" ); |
| 100 | |
| 101 | mOpenAL.alBufferData( mALBuffer, alFormat, |
| 102 | packet->data, packet->mSizeActual, getFormat().getSamplesPerSecond() ); |
| 103 | |
| 104 | destructSingle( packet ); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | MutexHandle mutex; |
| 109 | mutex.lock( &_getUniqueVoice()->mMutex, true ); |
| 110 | |
| 111 | // Unqueue processed packets. |
| 112 | |
| 113 | ALuint source = _getUniqueVoice()->mSourceName; |
| 114 | ALint numProcessed; |
| 115 | mOpenAL.alGetSourcei( source, AL_BUFFERS_PROCESSED, &numProcessed ); |
| 116 | |
| 117 | for( U32 i = 0; i < numProcessed; ++ i ) |
| 118 | { |
| 119 | // Unqueue the buffer. |
| 120 | |
| 121 | ALuint buffer; |
| 122 | mOpenAL.alSourceUnqueueBuffers( source, 1, &buffer ); |
| 123 | |
| 124 | // Update the sample offset on the voice. |
| 125 | |
| 126 | ALint size; |
| 127 | mOpenAL.alGetBufferi( buffer, AL_SIZE, &size ); |
| 128 | _getUniqueVoice()->mSampleOffset += size / getFormat().getBytesPerSample(); |
| 129 | |
| 130 | // Push the buffer onto the freelist. |
| 131 | |
| 132 | mFreeBuffers.push_back( buffer ); |
| 133 | } |
| 134 | |
| 135 | // Queue buffers. |
| 136 | |
| 137 | for( U32 i = 0; i < num; ++ i ) |
| 138 | { |
| 139 | SFXStreamPacket* packet = packets[ i ]; |
| 140 | |
| 141 | // Allocate a buffer. |
no test coverage detected