Thread: [Gcblue-commits] gcb_wx/src/common simmath.cpp,1.20,1.21 tcOggStreamer.cpp,1.13,1.14 tcSound.cpp,1.2
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-02-24 22:19:51
|
Update of /cvsroot/gcblue/gcb_wx/src/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11465/src/common Modified Files: simmath.cpp tcOggStreamer.cpp tcSound.cpp Log Message: More OpenAL++ changes and ai improvements Index: tcOggStreamer.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcOggStreamer.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcOggStreamer.cpp 10 Jan 2005 00:30:46 -0000 1.13 --- tcOggStreamer.cpp 24 Feb 2005 22:19:15 -0000 1.14 *************** *** 1,6 **** ! /* ! ** tcOggStreamer.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tcOggStreamer.cpp ! */ ! /* Copyright (C) 2003-2005 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 38,135 **** void tcOggStreamer::Open(std::string path) { ! int result; ! ! ! // Check if file is already open. Close it if so. ! if (oggFile != NULL) ! { ! Empty(); ! ov_clear(&oggStream); ! oggFile = NULL; ! } ! ! if(!(oggFile = fopen(path.c_str(), "rb"))) { ! fprintf(stderr,"tcOggStreamer--Could not open file: %s\n",path.c_str()); ! cerr << "Could not open Ogg file.\n"; // was: throw string("Could not open Ogg file."); ! return; } ! ! ! //if(!(oggFile = fopen("One_Light_Out_Whole_Lotta.ogg", "rb"))) ! ! ! if((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0) { ! fclose(oggFile); ! oggFile = NULL; ! fprintf(stderr,"tcOggStreamer--Error opening Ogg stream: %s (%s)\n", ! ErrorString(result).c_str(),path.c_str()); ! return; ! //throw string("Could not open Ogg stream. ") + ErrorString(result); } ! fprintf(stdout,"Opened music: %s\n",path.c_str()); ! ! vorbisInfo = ov_info(&oggStream, -1); ! vorbisComment = ov_comment(&oggStream, -1); ! if(vorbisInfo->channels == 1) ! format = AL_FORMAT_MONO16; ! else ! format = AL_FORMAT_STEREO16; ! } - /** - * Called once at startup. - */ - void tcOggStreamer::Init() - { - std::cout << "Generating buffers" << std::endl; - alGenBuffers(NUM_BUFFERS, buffers); - Check(); - std::cout << "Generating source" << std::endl; - alGenSources(1, &source); - Check(); - - std::cout << "Configuring source" << std::endl; - alSource3f(source, AL_POSITION, 0.0, 0.0, 0.0); - alSource3f(source, AL_VELOCITY, 0.0, 0.0, 0.0); - alSource3f(source, AL_DIRECTION, 0.0, 0.0, 0.0); - alSourcef (source, AL_ROLLOFF_FACTOR, 0.0 ); - alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE ); - alSourcef (source, AL_GAIN, volume); - alSourcei(source, AL_LOOPING, AL_FALSE); - } - /** - * Called once before exit. - */ - void tcOggStreamer::Release() - { - alSourceStop(source); - Empty(); - alDeleteSources(1, &source); - Check(); - alDeleteBuffers(1, buffers); - Check(); ! if (oggFile) ov_clear(&oggStream); ! } /** * Seeks to seekTime if song is playing */ void tcOggStreamer::Seek(double seekTime) { - if (!oggFile) - { - fprintf(stderr,"tcOggStreamer::Seek called with no open stream\n"); - return; - } - ov_time_seek(&oggStream, seekTime); - Empty(); - Check(); } --- 38,69 ---- void tcOggStreamer::Open(std::string path) { ! return; ! if (source.valid()) { ! stream.get()->unref(); } ! else { ! source = new openalpp::Source; ! source->setAmbient(); ! source->setGain(volume); } ! stream = new openalpp::FileStream(path); ! source->setSound(stream.get()); ! source->play(); } ! /** * Seeks to seekTime if song is playing + * (not implemented yet in this version using OpenAL++) */ void tcOggStreamer::Seek(double seekTime) { } *************** *** 141,146 **** void tcOggStreamer::SetVolume(float vol) { - alSourcef (source, AL_GAIN, vol); volume = vol; } --- 75,83 ---- void tcOggStreamer::SetVolume(float vol) { volume = vol; + if (source.valid()) + { + source->setGain(volume); + } } *************** *** 150,157 **** void tcOggStreamer::Stop() { ! alSourceStop(source); ! if (oggFile == NULL) return; // already cleared ! ov_clear(&oggStream); ! oggFile = NULL; } --- 87,94 ---- void tcOggStreamer::Stop() { ! if (source.valid()) ! { ! source->stop(); ! } } *************** *** 159,178 **** void tcOggStreamer::Display() { - if (oggFile == NULL) return; - cout - << "version " << vorbisInfo->version << "\n" - << "channels " << vorbisInfo->channels << "\n" - << "rate (hz) " << vorbisInfo->rate << "\n" - << "bitrate upper " << vorbisInfo->bitrate_upper << "\n" - << "bitrate nominal " << vorbisInfo->bitrate_nominal << "\n" - << "bitrate lower " << vorbisInfo->bitrate_lower << "\n" - << "bitrate window " << vorbisInfo->bitrate_window << "\n" - << "\n" - << "vendor " << vorbisComment->vendor << "\n"; - - for(int i = 0; i < vorbisComment->comments; i++) - cout << " " << vorbisComment->user_comments[i] << "\n"; - - cout << endl; } --- 96,99 ---- *************** *** 187,214 **** bool tcOggStreamer::Play() { ! if (oggFile == NULL) return false; paused = false; - if (IsPlaying()) return true; - Update(); // new way of doing this ! #if 0 ! bool dataAvailable = true; ! for (int nBuff = 0;(nBuff < NUM_BUFFERS) && dataAvailable; nBuff++) { ! if(!Stream(buffers[nBuff])) dataAvailable = false; // out of music for stream ! alSourceQueueBuffers(source, 1, &buffers[nBuff]); } - #endif ! alSourcePlay(source); ! ! return true; } void tcOggStreamer::Queue(std::string path) { ! if (oggFile == NULL) { Open(path); --- 108,132 ---- bool tcOggStreamer::Play() { ! if (!source.valid()) return false; paused = false; ! ! if (IsPlaying()) return true; ! ! if (IsStopped()) { ! } ! return IsPlaying(); } + + void tcOggStreamer::Queue(std::string path) { ! if ( (!source.valid()) || (!IsPlaying())) { Open(path); *************** *** 219,232 **** queuedSong = path; } ! //const char *temp = queuedSong.c_str(); } bool tcOggStreamer::IsPaused() { ! ALenum state; ! ! alGetSourcei(source, AL_SOURCE_STATE, &state); ! ! return (state == AL_PAUSED); } --- 137,146 ---- queuedSong = path; } ! } bool tcOggStreamer::IsPaused() { ! return (source->getState() == openalpp::Paused); } *************** *** 234,493 **** bool tcOggStreamer::IsPlaying() { ! ALenum state; ! ! alGetSourcei(source, AL_SOURCE_STATE, &state); ! ! return (state == AL_PLAYING); ! } ! ! bool tcOggStreamer::IsStopped() ! { ! ALenum state; ! ! alGetSourcei(source, AL_SOURCE_STATE, &state); ! ! return (state == AL_STOPPED); ! } ! ! ! ! /* ! bool tcOggStreamer::Update() ! { ! int processed; ! bool active = true; ! ! alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); ! ! while(processed--) ! { ! ALuint buffer; ! ! alSourceUnqueueBuffers(source, 1, &buffer); ! Check(); ! ! active = Stream(buffer); ! ! alSourceQueueBuffers(source, 1, &buffer); ! Check(); ! } ! ! return active; ! } ! */ ! bool tcOggStreamer::Update() ! { ! bool active = true; ! int nProcessed; ! int queued; ! ! if (paused) ! { ! return true; ! } ! ! if (IsStopped()) ! { ! ! //alSourceStop(source); ! alSourcePlay(source); // crashes frequently in OpenAL32.dll thread after here ! ! #ifdef _DEBUG ! fprintf(stderr, "tcOggStreamer::Update - Restarting source\n"); ! #endif ! //return true; ! } ! ! alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); ! ! // Ask OpenAL how many buffers it has managed to play back ! alGetSourcei(source, AL_BUFFERS_PROCESSED, &nProcessed); ! nFreeBuffers += nProcessed; ! ! if (nFreeBuffers > NUM_BUFFERS) ! { ! wxASSERT(false); ! nFreeBuffers = NUM_BUFFERS; ! } ! ! ! /* If stall condition then set nFreeBuffers to NUM_BUFFERS ! ** to restart streaming (not sure if this works yet) ! */ ! int nQueued; ! alGetSourcei(source, AL_BUFFERS_QUEUED, &nQueued); ! if ((nFreeBuffers == 0) && (nQueued == 0)) ! { ! nFreeBuffers = NUM_BUFFERS; ! } ! ! ! while (active && nFreeBuffers) ! { ! if (nProcessed) ! { ! alSourceUnqueueBuffers(source, 1, &buffers[bufferIndex]); ! nProcessed--; ! } ! Check(); ! //fill the buffer ! active = Stream(buffers[bufferIndex]); ! ! if (active) ! { ! alSourceQueueBuffers(source, 1, &buffers[bufferIndex]); ! ! // fprintf(stdout,"Queued buffer: %d\n", bufferIndex); ! ! bufferIndex = (bufferIndex + 1) % NUM_BUFFERS; ! nFreeBuffers--; ! } ! ! Check(); ! } ! ! return active; ! } ! ! bool tcOggStreamer::Stream(ALuint buffer) ! { ! int currentSize = 0; ! int section; ! long result; ! ! currentSize = 0; ! while (currentSize < BUFFER_SIZE) ! { ! result = ov_read(&oggStream, ! streamBuffer + currentSize, BUFFER_SIZE - currentSize, 0, 2, 1, §ion); ! Check(); ! ! if (result > 0) ! { ! currentSize += result; ! } ! else if (result < 0) ! { ! fprintf(stderr, "%s\n", ErrorString(result).c_str()); ! } ! else ! { ! if (queuedSong.size() > 2) ! { ! Open(queuedSong); ! queuedSong = ""; ! return false; ! } ! else ! { ! result = ov_time_seek(&oggStream, 0.0); // loop if no queued song ! } ! break; ! } ! } ! ! if(currentSize == 0) ! return false; ! ! alBufferData(buffer, format, streamBuffer, currentSize, vorbisInfo->rate); ! Check(); ! ! return true; ! } ! ! ! ! ! void tcOggStreamer::Empty() ! { ! int queued; ! ! alSourceStop(source); ! alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); ! ! while(queued--) ! { ! ALuint buffer; ! ! alSourceUnqueueBuffers(source, 1, &buffer); ! Check(); ! } ! bufferIndex = 0; ! nFreeBuffers = NUM_BUFFERS; } ! ! ! ! void tcOggStreamer::Check() { ! int error = alGetError(); ! ! if (error != AL_NO_ERROR) ! { ! fprintf(stderr, "OpenAL error: %s\n", ErrorString(error).c_str()); ! } ! } - string tcOggStreamer::ErrorString(int code) - { - switch(code) - { - case OV_EREAD: - return string("Read from media."); - case OV_ENOTVORBIS: - return string("Not Vorbis data."); - case OV_EVERSION: - return string("Vorbis version mismatch."); - case OV_EBADHEADER: - return string("Invalid Vorbis header."); - case OV_EFAULT: - return string("Internal logic fault (bug or heap/stack corruption."); - case OV_HOLE: - return string("Missing or corrupt data in the bitstream. Recovery is normally automatic. "); - case OV_EIMPL: - return string("Feature not implemented."); - case OV_EINVAL: - return string("Either an invalid argument, or incompletely initialized argument passed to libvorbisfile call"); - case OV_EBADLINK: - return string("The given link exists in the Vorbis data stream, but is not decipherable due to garbacge or corruption."); - case OV_ENOSEEK: - return string("The given stream is not seekable"); - case OV_ENOTAUDIO: - return string("This is not an audio data packet."); - case OV_EBADPACKET: - return string("Bad packet."); - case AL_INVALID_NAME: - return string("Invalid Name paramater passed to AL call."); - case AL_ILLEGAL_ENUM: - return string("Invalid parameter passed to AL call."); - case AL_INVALID_VALUE: - return string("Invalid enum parameter value."); - case AL_ILLEGAL_COMMAND: - return string("Illegal command."); - case AL_OUT_OF_MEMORY: - return string("AL out of memory."); - default: - wxString s = wxString::Format("Unknown Ogg error (%d)", code); - return string(s.c_str()); - } - } - tcOggStreamer::tcOggStreamer() { - oggFile = NULL; - volume = 0.2f; - bufferIndex = 0; - nFreeBuffers = NUM_BUFFERS; - queuedSong == ""; - paused = false; } tcOggStreamer::~tcOggStreamer() { } --- 148,176 ---- bool tcOggStreamer::IsPlaying() { ! if (!source.valid()) return false; ! return (source->getState() == openalpp::Playing); } ! bool tcOggStreamer::IsStopped() { ! return (source->getState() == openalpp::Stopped); } tcOggStreamer::tcOggStreamer() + : volume(0.2f), + queuedSong(""), + paused(false) { } tcOggStreamer::~tcOggStreamer() { + if (source.valid()) + { + source->stop(); + } } Index: tcSound.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcSound.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** tcSound.cpp 21 Feb 2005 18:26:06 -0000 1.23 --- tcSound.cpp 24 Feb 2005 22:19:15 -0000 1.24 *************** *** 108,112 **** - if (oggStreamer) oggStreamer->Init(); SetMusicVolume(0.5f); --- 108,111 ---- *************** *** 261,265 **** if (meMusicState == MS_STOPPED) return; ! if (!oggStreamer->Update()) { oggStreamer->Play(); --- 260,264 ---- if (meMusicState == MS_STOPPED) return; ! if (!oggStreamer->IsPlaying()) { oggStreamer->Play(); *************** *** 443,448 **** effectMap.clear(); - if (oggStreamer) oggStreamer->Release(); - //osgAL::SoundManager::instance()->shutdown(); --- 442,445 ---- *************** *** 473,477 **** std::cout << "Creating OGG streamer" << std::endl; ! oggStreamer = 0;//new tcOggStreamer(); std::cout << "Success - Create OGG streamer" << std::endl; } --- 470,474 ---- std::cout << "Creating OGG streamer" << std::endl; ! oggStreamer = new tcOggStreamer(); std::cout << "Success - Create OGG streamer" << std::endl; } Index: simmath.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/simmath.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** simmath.cpp 5 Dec 2004 02:49:47 -0000 1.20 --- simmath.cpp 24 Feb 2005 22:19:15 -0000 1.21 *************** *** 76,80 **** // assumes lon is within [-pi,pi) and lat [-pi/2,pi/2] ! int GeoWithinRegion(tsGeoPoint p, tcRect *pRegion) { if ((p.mfLat_rad > pRegion->top)||(p.mfLat_rad < pRegion->bottom)) {return 0;} --- 76,80 ---- // assumes lon is within [-pi,pi) and lat [-pi/2,pi/2] ! int GeoWithinRegion(GeoPoint p, tcRect *pRegion) { if ((p.mfLat_rad > pRegion->top)||(p.mfLat_rad < pRegion->bottom)) {return 0;} *************** *** 116,120 **** bool tcGeoRect::ContainsPoint(float x, float y) { ! tsGeoPoint p; p.Set(x, y, 0); return GeoWithinRegion(p, this) != 0; --- 116,120 ---- bool tcGeoRect::ContainsPoint(float x, float y) { ! GeoPoint p; p.Set(x, y, 0); return GeoWithinRegion(p, this) != 0; *************** *** 415,423 **** } ! /********************** tsGeoPoint *************************************/ /** * Load state from stream */ ! tcStream& tsGeoPoint::operator<<(tcStream& stream) { stream >> mfLon_rad; --- 415,423 ---- } ! /********************** GeoPoint *************************************/ /** * Load state from stream */ ! tcStream& GeoPoint::operator<<(tcStream& stream) { stream >> mfLon_rad; *************** *** 431,435 **** * Save state to stream */ ! tcStream& tsGeoPoint::operator>>(tcStream& stream) { stream << mfLon_rad; --- 431,435 ---- * Save state to stream */ ! tcStream& GeoPoint::operator>>(tcStream& stream) { stream << mfLon_rad; *************** *** 536,540 **** } // returns radian heading to (lat,lon) point ! float tcKinematics::HeadingToGeoRad(const tsGeoPoint *apGeoPoint) { return nsNav::GCHeadingApprox_rad((float)mfLat_rad,(float)mfLon_rad, (float)apGeoPoint->mfLat_rad,(float)apGeoPoint->mfLon_rad); --- 536,540 ---- } // returns radian heading to (lat,lon) point ! float tcKinematics::HeadingToGeoRad(const GeoPoint *apGeoPoint) { return nsNav::GCHeadingApprox_rad((float)mfLat_rad,(float)mfLon_rad, (float)apGeoPoint->mfLat_rad,(float)apGeoPoint->mfLon_rad); *************** *** 555,559 **** } ! float tcKinematics::RangeToKm(const tsGeoPoint *apGeoPoint) { return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, --- 555,559 ---- } ! float tcKinematics::RangeToKm(const GeoPoint *apGeoPoint) { return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, *************** *** 737,741 **** // current location of this tcKinematics object // altitude isn't changed, has issues off of equator like everything else :< ! void tcKinematics::SetRelativeGeo(tsGeoPoint& rpGeoPoint, float afBearing_rad, float afRange_km) { nsNav::OffsetApprox((float)mfLat_rad,(float)mfLon_rad, rpGeoPoint.mfLat_rad, rpGeoPoint.mfLon_rad, afBearing_rad,afRange_km*C_KMTORAD); --- 737,741 ---- // current location of this tcKinematics object // altitude isn't changed, has issues off of equator like everything else :< ! void tcKinematics::SetRelativeGeo(GeoPoint& rpGeoPoint, float afBearing_rad, float afRange_km) { nsNav::OffsetApprox((float)mfLat_rad,(float)mfLon_rad, rpGeoPoint.mfLat_rad, rpGeoPoint.mfLon_rad, afBearing_rad,afRange_km*C_KMTORAD); |