Hi Robert,

I'm using the video4windows library. This library only is able to extract the sound buffer of the video. The next step is creating an openalpp::Sample with this buffer. And the question is, how can osg reproduce this audio buffer without using openal?

Robert Osfield escribió:
Hi Marta,

I'm not yet familiar with osgAL so I'll defer to others on how best to
do it.  Also osgAL isn't part of the core OSG so I can't merge
anything that is based on it yet, the wiki is a good place to post
such code though.

The xine-lib and quicktime plugin do there own sound support without
the need for osgAL, does the AVI library you are using not support
this as well?

Robert.

On 7/14/06, Marta Pla i Castells <[EMAIL PROTECTED]> wrote:

Hi all,

I've been playing with the code of Mikkel Gjøl (osgAVI ) and finally
I've been able to play sound in my osgmovie application extracting the
sound buffer to an openalpp sample and the creating a soundState of
osgAL. The only fact is that my code isn't as clean as I wanted. :(
The good new is that it WORKS!!!

I insert my new code here. If Robert, or someone who knows the good way
to modify the code, wants to add it to the osg code I will be very pleased.

Thank you very much to Mikkel and Tao for their help

/*****************************************************/


void AviImageStream::OpenAVI( LPCSTR in_filename ) {
// note: opens an avi-file
// note: allocates data here, before thread is started!
//       (thus in a thread with a gl-context)

        AVIFileInit(); // Opens The AVIFile Library

        // Opens The AVI Stream
        if( AVIStreamOpenFromFile( &m_pavi, in_filename, treamtypeVIDEO,
                                 0, OF_READ, NULL)) {
                std::string err( "Failed to open the AVI-file: " +
                                        std::string(in_filename));
                MessageBox( HWND_DESKTOP, err.c_str(), "Error", MB_OK |
                                MB_ICONEXCLAMATION );
                exit(-1);
        }

        AVIStreamInfo( m_pavi, &m_psi, sizeof(m_psi) );

        if( AVIStreamOpenFromFile( &m_pavi_sound, in_filename,
                                streamtypeAUDIO, 0, OF_READ, NULL)) {
                std::string err( "Failed to open the AVI-file: " +
                                        std::string(in_filename));
                MessageBox( HWND_DESKTOP, err.c_str(), "Error", MB_OK |
                                MB_ICONEXCLAMATION );
                exit(-1);
        }

        AVIStreamInfo( m_pavi_sound, &m_psi_sound, sizeof(m_psi_sound));

        long lSize;
        AVIStreamRead(m_pavi_sound, 0, AVISTREAMREAD_CONVENIENT, NULL,
                        0, &lSize, NULL);

        LPBYTE pChunk = new BYTE[lSize];

        AVIStreamReadFormat(m_pavi_sound, 0, pChunk, &lSize);

        LPWAVEFORMATEX pWaveFormat = (LPWAVEFORMATEX)pChunk;
        long m_length = AVIStreamLength(m_pavi_sound); //Member int

        if(pWaveFormat->wFormatTag!=1)
                puts("Esta comprimido");

        LPBYTE m_lpAudioBuffer = new BYTE[m_length*4];

        // Get the full stream
        for(int i=0; i<m_length; i++)
                AVIStreamRead(m_pavi_sound, i, AVISTREAMREAD_CONVENIENT,
                         &m_lpAudioBuffer[i*4], lSize, NULL, NULL);


        openalpp::ref_ptr<openalpp::Sample> sample = new
                        openalpp::Sample(AL_FORMAT_STEREO16,
                        m_lpAudioBuffer, m_length*4,
                        pWaveFormat->nSamplesPerSec);

        sound_state = new osgAL::SoundState("video");
        sound_state->setSample(sample);
        sound_state->setGain(1.0f);
        sound_state->setPitch(1);

        sound_state->setPlay(false);
        sound_state->setLooping(true);

        sound_state->allocateSource(10, false);

     osgAL::SoundManager::instance()->addSoundState(sound_state.get());

        sound_state->apply();

m_width = m_psi.rcFrame.right - m_psi.rcFrame.left; // Width Is
Right Side Of Frame Minus Left
m_height = m_psi.rcFrame.bottom - m_psi.rcFrame.top; // Height Is
Bottom Of Frame Minus Top

m_lastframe = AVIStreamLength( m_pavi ); // The Last Frame Of The
Stream
m_mpf = AVIStreamSampleToTime( m_pavi, m_lastframe ) / m_lastframe;

        m_pgf = AVIStreamGetFrameOpen(m_pavi, NULL);
        if( !m_pgf) {
                MessageBox( HWND_DESKTOP, "Failed To Open The AVI
                Frame", "Error", MB_OK | MB_ICONEXCLAMATION );
                exit(-1);
        }

        osg::ImageStream::setImage( m_width, m_height, 1,
internal_format, pixelformat, type,
                                0,osg::Image::NO_DELETE,
                                packing );

        return;
}


/*****************************************************/


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/



_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

begin:vcard
fn:Marta Pla i Castells
n:Pla i Castells;Marta
org;quoted-printable:Universidad de Valencia;Instituto de Rob=C3=B3tica
email;internet:[EMAIL PROTECTED]
title;quoted-printable:T=C3=A9cnico Superior de Investigaci=C3=B3n
url:http://www.uv.es/mplac
version:2.1
end:vcard

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to