# [Solved] OpenAL source playing

## Recommended Posts

DarkShogun    122
I have been trying to use streaming sound in OpenAL and for some reason when I try to load buffers after playing of other files starts, the new sound will not play. Is there a major delay between being able to play a sound and loading data into a buffer? [Edited by - DarkShogun on May 15, 2008 2:53:09 PM]

##### Share on other sites
DarkShogun    122
Alright I was incorrect about diagnosing the problem. Right now I'm trying to play three different sets of buffers to stream audio. Two buffers are being used in a queued fashion, When I try to play these streams, it will only play one at a time. I'm assuming this would be something wrong with my buffer update function.

This is what I have for my update.
m_vStreams is a vector of pointers to structures I made
OggStream is the OggVorbis_File
nSource is the handle to the source given by OpenAL
	ALuint nALbuffer;	int nProcessedBuffers;	int nBytesRead = 0;	int nReadSoFar = 0;	int bitstream;	char buffer[BUFFER_SIZE];	for (unsigned int i = 0; i &lt; m_vStreams.size(); ++i)	{		if (m_vStreams[i] != 0)		{			// Get the number of buffers that have already been processed			alGetSourcei(m_vStreams[i]-&gt;nSource, AL_BUFFERS_PROCESSED, &nProcessedBuffers);			// For each processed buffer, replace with new data and add back to the queue			while (nProcessedBuffers &gt; 0)			{				// Take the first processed buffer off the queue				alSourceUnqueueBuffers(m_vStreams[i]-&gt;nSource, 1, &nALbuffer);				// Read in the data for the buffer				while (nReadSoFar &lt; BUFFER_SIZE)				{					nBytesRead = ov_read(&m_vStreams[i]-&gt;OggStream, buffer + nReadSoFar, BUFFER_SIZE - nReadSoFar, 0, 2, 1, &bitstream);					if (nBytesRead == 0)						break;					nReadSoFar += nBytesRead;				}				alBufferData(nALbuffer, m_vStreams[i]-&gt;nFormat, buffer, nReadSoFar, m_vStreams[i]-&gt;nFrequency);				// Put the buffer with the new data on the back of the queue				alSourceQueueBuffers(m_vStreams[i]-&gt;nSource, 1, &nALbuffer);				--nProcessedBuffers;			}		}	}

Any assistance with this is greatly appreciated.

##### Share on other sites
DarkShogun    122
I figured out the problem... i dumbly forgot to reset nReadSoFar to 0 so it wouldnt just keep the same buffer info in there.

##### Share on other sites
riruilo    218

BTW, I tried to do that few days ago, but I was unsuccesful. When I played some sounds, I could hear a strange sound at the end, sometimes even the beginning of the same sound. I thought it was a problem playing the end of the last buffer, but I couldnt solve it.

Thanks a lot.