• Advertisement
Sign in to follow this  

Play AVI's sound with OpenAL...

This topic is 4173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I write an AVI player for my free game, and I choosed the OpenAL library for the sound. I heard, the windows' avi handle API's are great and easy enought, and it works fine in the video part, with OpenGL. Then I load the audio stream (AVIStreamOpenFromFile) and looks it's OK, every information what OpenAL require are correct (frequency, channel num, ...), but unfortunately when I try to play with alSourcePlay I hear nothing... Here's the playing part of the source, I hope someone can help me 'cause this problem make me mad... ALuint tmp_buffer, tmp_source; alGenBuffers(1, &tmp_buffer); alGenSources(1, &tmp_source); LONG buffer_size; AVIStreamRead(my_audio_stream, AVIStreamStart(my_audio_stream), AVISTREAMREAD_CONVENIENT, NULL, 0, &buffer_size, NULL); PBYTE tmp_format = new BYTE[buffer_size]; AVIStreamReadFormat(my_audio_stream, AVIStreamStart(my_audio_stream), tmp_format, &buffer_size); LPWAVEFORMATEX wave_format = (LPWAVEFORMATEX)tmp_format; LONG samples_num = AVIStreamLength(my_audio_stream); //Member int cout << "/// Samples num: " << samples_num << endl; // Definie Databuffers (size of one sample is 4) PBYTE m_lpAudioBuffer = new BYTE[samples_num * 4]; if(!m_lpAudioBuffer) ERRORMSG("FUCK!", "Error"); // Get the full stream for(int i=0; i < samples_num; i++) { // Auslesen der Audiodaten in den Datenpuffer if(AVIStreamRead(my_audio_stream, AVIStreamStart(my_audio_stream), AVISTREAMREAD_CONVENIENT, &m_lpAudioBuffer, buffer_size, NULL, NULL)) ERRORMSG("FUCK! during read", "Error"); } //tmp_buffer = alutCreateBufferHelloWorld (); alBufferData(tmp_buffer, AL_FORMAT_STEREO16, my_audio_stream, buffer_size*4, wave_format->nSamplesPerSec); //tmp_buffer = alutCreateBufferFromFileImage(my_audio_stream, buffer_size); alSourcei(tmp_source, AL_BUFFER, tmp_buffer); alSourcePlay(tmp_source); End everything ok, if I use the alutCreateBufferHelloWorld function, so the problem is not with the OpenAL part. And I can get the correct informations about the audio stream, so I think, it's correct as well...

Share this post


Link to post
Share on other sites
Advertisement

So, have you studied that there is actually some data read from the AVI file, ie. that the buffer you read contains something ?

Share this post


Link to post
Share on other sites
No I haven't. But could it be ok? (this code, what I quoted).

I read a lot (msdn), but the main problem ->
AVIStreamRead(...); "returns" what kind of buffer (data)? So it can be the full decoded data (if the size is correct), or it's only one chunk? And what type of data is this?

I saw in a code, and I copied for my ogg player the "trick", I use a std::vector<char> array for the data contain, and it makes easy get the buffer's size:
alBufferData(in_r_sound_data.my_buffer, format, &bufferData[0], static_cast<ALsizei> (bufferData.size()), freq);
So the best would be, if I could make this with AVI's sound as well...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement