[Opentnl-cvs] tnl/zap UIGame.cpp,1.21,1.22 UIGame.h,1.7,1.8 ZAP.vcproj,1.14,1.15 voiceCodec.cpp,1.1,
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-05-09 20:35:28
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv655/zap Modified Files: UIGame.cpp UIGame.h ZAP.vcproj voiceCodec.cpp voiceCodec.h Log Message: Added subfolders to Zap project implemented the wrapper around the HawkVoice GSM codec Index: voiceCodec.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/voiceCodec.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** voiceCodec.h 8 May 2004 22:01:13 -0000 1.1 --- voiceCodec.h 9 May 2004 20:35:17 -0000 1.2 *************** *** 94,97 **** --- 94,124 ---- }; + /// The GSMVoiceEncoder class implements the HawkVoice GSM codec + /// compressor. + class GSMVoiceEncoder : public VoiceEncoder + { + void *encoderState; + U32 getSamplesPerFrame(); + U32 getMaxCompressedFrameSize(); + U32 compressFrame(S16 *samplePtr, U8 *outputPtr); + public: + GSMVoiceEncoder(); + ~GSMVoiceEncoder(); + }; + + /// The GSMVoiceDecoder class implements the HawkVoice GSM codec + /// decompressor. + class GSMVoiceDecoder : public VoiceDecoder + { + void *decoderState; + U32 getSamplesPerFrame(); + U32 getAvgCompressedFrameSize(); + + U32 decompressFrame(S16 *framePtr, U8 *inputPtr); + public: + GSMVoiceDecoder(); + ~GSMVoiceDecoder(); + }; + }; Index: voiceCodec.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/voiceCodec.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** voiceCodec.cpp 8 May 2004 22:01:13 -0000 1.1 --- voiceCodec.cpp 9 May 2004 20:35:17 -0000 1.2 *************** *** 27,30 **** --- 27,31 ---- #include "voiceCodec.h" #include "lpc10.h" + #include "gsm.h" namespace Zap *************** *** 149,151 **** --- 150,204 ---- } + GSMVoiceEncoder::GSMVoiceEncoder() + { + encoderState = gsm_create(); + } + + GSMVoiceEncoder::~GSMVoiceEncoder() + { + gsm_destroy((struct gsm_state *) encoderState); + } + + U32 GSMVoiceEncoder::getSamplesPerFrame() + { + return GSM_SAMPLES_PER_FRAME; + } + + U32 GSMVoiceEncoder::getMaxCompressedFrameSize() + { + return GSM_ENCODED_FRAME_SIZE; + } + + U32 GSMVoiceEncoder::compressFrame(S16 *samplePtr, U8 *outputPtr) + { + return gsm_encode((struct gsm_state *) encoderState, samplePtr, outputPtr); + } + + GSMVoiceDecoder::GSMVoiceDecoder() + { + decoderState = gsm_create(); + } + + GSMVoiceDecoder::~GSMVoiceDecoder() + { + gsm_destroy((struct gsm_state *) decoderState); + } + + U32 GSMVoiceDecoder::getSamplesPerFrame() + { + return GSM_SAMPLES_PER_FRAME; + } + + U32 GSMVoiceDecoder::getAvgCompressedFrameSize() + { + return GSM_ENCODED_FRAME_SIZE; + } + + U32 GSMVoiceDecoder::decompressFrame(S16 *framePtr, U8 *inputPtr) + { + gsm_decode((struct gsm_state *) decoderState, inputPtr, framePtr); + return GSM_ENCODED_FRAME_SIZE; + } + + }; \ No newline at end of file Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ZAP.vcproj 8 May 2004 22:01:13 -0000 1.14 --- ZAP.vcproj 9 May 2004 20:35:17 -0000 1.15 *************** *** 117,132 **** </References> <Files> ! <File ! RelativePath=".\barrier.cpp"> ! </File> ! <File ! RelativePath=".\barrier.h"> ! </File> ! <File ! RelativePath=".\CTFGame.cpp"> ! </File> ! <File ! RelativePath=".\CTFGame.h"> ! </File> <File RelativePath=".\game.cpp"> --- 117,296 ---- </References> <Files> ! <Filter ! Name="Levels" ! Filter=""> ! <File ! RelativePath="..\exe\level1.txt"> ! </File> ! <File ! RelativePath="..\exe\level2.txt"> ! </File> ! <File ! RelativePath="..\exe\level3.txt"> ! </File> ! <File ! RelativePath="..\exe\level4.txt"> ! </File> ! </Filter> ! <Filter ! Name="UI" ! Filter=""> ! <File ! RelativePath=".\quickChat.cpp"> ! </File> ! <File ! RelativePath=".\quickChat.h"> ! </File> ! <File ! RelativePath=".\UI.cpp"> ! </File> ! <File ! RelativePath=".\UI.h"> ! </File> ! <File ! RelativePath=".\UICredits.cpp"> ! </File> ! <File ! RelativePath=".\UICredits.h"> ! </File> ! <File ! RelativePath=".\UIGame.cpp"> ! </File> ! <File ! RelativePath=".\UIGame.h"> ! </File> ! <File ! RelativePath=".\UIMenus.cpp"> ! </File> ! <File ! RelativePath=".\UIMenus.h"> ! </File> ! <File ! RelativePath=".\UINameEntry.cpp"> ! </File> ! <File ! RelativePath=".\UINameEntry.h"> ! </File> ! <File ! RelativePath=".\UIQueryServers.cpp"> ! </File> ! <File ! RelativePath=".\UIQueryServers.h"> ! </File> ! </Filter> ! <Filter ! Name="SoundAndVoice" ! Filter=""> ! <File ! RelativePath=".\gsm.h"> ! </File> ! <File ! RelativePath=".\gsm_decode.c"> ! </File> ! <File ! RelativePath=".\gsm_encode.c"> ! </File> ! <File ! RelativePath=".\gsm_state.c"> ! </File> ! <File ! RelativePath=".\lpc10.h"> ! </File> ! <File ! RelativePath=".\lpc10dec.c"> ! </File> ! <File ! RelativePath=".\lpc10enc.c"> ! </File> ! <File ! RelativePath=".\sfx.cpp"> ! </File> ! <File ! RelativePath=".\sfx.h"> ! </File> ! <File ! RelativePath=".\voiceCodec.cpp"> ! </File> ! <File ! RelativePath=".\voiceCodec.h"> ! </File> ! </Filter> ! <Filter ! Name="GameObjects" ! Filter=""> ! <File ! RelativePath=".\barrier.cpp"> ! </File> ! <File ! RelativePath=".\barrier.h"> ! </File> ! <File ! RelativePath=".\gameItems.cpp"> ! </File> ! <File ! RelativePath=".\gameObject.cpp"> ! </File> ! <File ! RelativePath=".\gameObject.h"> ! </File> ! <File ! RelativePath=".\item.cpp"> ! </File> ! <File ! RelativePath=".\item.h"> ! </File> ! <File ! RelativePath=".\moveObject.cpp"> ! </File> ! <File ! RelativePath=".\moveObject.h"> ! </File> ! <File ! RelativePath=".\projectile.cpp"> ! </File> ! <File ! RelativePath=".\projectile.h"> ! </File> ! <File ! RelativePath=".\ship.cpp"> ! </File> ! <File ! RelativePath=".\ship.h"> ! </File> ! <File ! RelativePath=".\SweptEllipsoid.cpp"> ! </File> ! <File ! RelativePath=".\SweptEllipsoid.h"> ! </File> ! <File ! RelativePath=".\teleporter.cpp"> ! </File> ! <File ! RelativePath=".\teleporter.h"> ! </File> ! </Filter> ! <Filter ! Name="GameTypes" ! Filter=""> ! <File ! RelativePath=".\CTFGame.cpp"> ! </File> ! <File ! RelativePath=".\CTFGame.h"> ! </File> ! <File ! RelativePath=".\gameType.cpp"> ! </File> ! <File ! RelativePath=".\gameType.h"> ! </File> ! <File ! RelativePath=".\soccerGame.cpp"> ! </File> ! <File ! RelativePath=".\soccerGame.h"> ! </File> ! </Filter> <File RelativePath=".\game.cpp"> *************** *** 142,148 **** </File> <File - RelativePath=".\gameItems.cpp"> - </File> - <File RelativePath=".\gameLoader.cpp"> </File> --- 306,309 ---- *************** *** 157,172 **** </File> <File - RelativePath=".\gameObject.cpp"> - </File> - <File - RelativePath=".\gameObject.h"> - </File> - <File - RelativePath=".\gameType.cpp"> - </File> - <File - RelativePath=".\gameType.h"> - </File> - <File RelativePath=".\gridDB.cpp"> </File> --- 318,321 ---- *************** *** 175,205 **** </File> <File - RelativePath=".\item.cpp"> - </File> - <File - RelativePath=".\item.h"> - </File> - <File - RelativePath="..\exe\level1.txt"> - </File> - <File - RelativePath="..\exe\level2.txt"> - </File> - <File - RelativePath="..\exe\level3.txt"> - </File> - <File - RelativePath="..\exe\level4.txt"> - </File> - <File - RelativePath=".\lpc10.h"> - </File> - <File - RelativePath=".\lpc10dec.c"> - </File> - <File - RelativePath=".\lpc10enc.c"> - </File> - <File RelativePath=".\main.cpp"> </File> --- 324,327 ---- *************** *** 214,259 **** </File> <File - RelativePath=".\moveObject.cpp"> - </File> - <File - RelativePath=".\moveObject.h"> - </File> - <File RelativePath=".\point.h"> </File> <File - RelativePath=".\projectile.cpp"> - </File> - <File - RelativePath=".\projectile.h"> - </File> - <File - RelativePath=".\quickChat.cpp"> - </File> - <File - RelativePath=".\quickChat.h"> - </File> - <File RelativePath="..\exe\README.txt"> </File> <File - RelativePath=".\sfx.cpp"> - </File> - <File - RelativePath=".\sfx.h"> - </File> - <File - RelativePath=".\ship.cpp"> - </File> - <File - RelativePath=".\ship.h"> - </File> - <File - RelativePath=".\soccerGame.cpp"> - </File> - <File - RelativePath=".\soccerGame.h"> - </File> - <File RelativePath=".\sparkManager.cpp"> </File> --- 336,345 ---- *************** *** 262,322 **** </File> <File - RelativePath=".\SweptEllipsoid.cpp"> - </File> - <File - RelativePath=".\SweptEllipsoid.h"> - </File> - <File - RelativePath=".\teleporter.cpp"> - </File> - <File - RelativePath=".\teleporter.h"> - </File> - <File RelativePath=".\timer.h"> </File> <File - RelativePath=".\UI.cpp"> - </File> - <File - RelativePath=".\UI.h"> - </File> - <File - RelativePath=".\UICredits.cpp"> - </File> - <File - RelativePath=".\UICredits.h"> - </File> - <File - RelativePath=".\UIGame.cpp"> - </File> - <File - RelativePath=".\UIGame.h"> - </File> - <File - RelativePath=".\UIMenus.cpp"> - </File> - <File - RelativePath=".\UIMenus.h"> - </File> - <File - RelativePath=".\UINameEntry.cpp"> - </File> - <File - RelativePath=".\UINameEntry.h"> - </File> - <File - RelativePath=".\UIQueryServers.cpp"> - </File> - <File - RelativePath=".\UIQueryServers.h"> - </File> - <File - RelativePath=".\voiceCodec.cpp"> - </File> - <File - RelativePath=".\voiceCodec.h"> - </File> - <File RelativePath=".\winJoystick.cpp"> </File> --- 348,354 ---- Index: UIGame.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** UIGame.h 8 May 2004 22:01:13 -0000 1.7 --- UIGame.h 9 May 2004 20:35:17 -0000 1.8 *************** *** 69,74 **** enum { ChatBlinkTime = 100, - FirstVoiceAudioSampleTime = 250, - VoiceAudioSampleTime = 100, }; Mode mCurrentMode; --- 69,72 ---- *************** *** 80,99 **** U32 mChatLastBlinkTime; bool mInScoreboardMode; - bool mRecordingAudio; - S16 mMaxAudioSample; VChatHelper *mVChat; - Timer mVoiceAudioTimer; - RefPtr<SFXObject> mVoiceSfx; - RefPtr<VoiceEncoder> mVoiceEncoder; ! ByteBufferPtr mUnusedAudio; public: GameUserInterface(); void displayMessage(Color messageColor, const char *format, ...); - void processRecordingAudio(); - void startRecordingAudio(); - void stopRecordingAudio(); void render(); --- 78,114 ---- U32 mChatLastBlinkTime; bool mInScoreboardMode; VChatHelper *mVChat; ! struct VoiceRecorder ! { ! enum { ! FirstVoiceAudioSampleTime = 250, ! VoiceAudioSampleTime = 100, ! MaxDetectionThreshold = 2048, ! }; ! ! Timer mVoiceAudioTimer; ! RefPtr<SFXObject> mVoiceSfx; ! RefPtr<VoiceEncoder> mVoiceEncoder; ! bool mRecordingAudio; ! S32 mMaxAudioSample; ! S32 mMaxForGain; ! ByteBufferPtr mUnusedAudio; ! ! VoiceRecorder(); ! ! void idle(U32 timeDelta); ! void process(); ! void start(); ! void stop(); ! void render(); ! ! } mVoiceRecorder; ! public: GameUserInterface(); void displayMessage(Color messageColor, const char *format, ...); void render(); Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** UIGame.cpp 8 May 2004 22:01:13 -0000 1.21 --- UIGame.cpp 9 May 2004 20:35:17 -0000 1.22 *************** *** 59,65 **** mVChat = new VChatHelper(); - mRecordingAudio = false; - mMaxAudioSample = 0; - mVoiceEncoder = new LPC10VoiceEncoder; } --- 59,62 ---- *************** *** 103,114 **** } } ! if(mRecordingAudio) ! { ! if(mVoiceAudioTimer.update(timeDelta)) ! { ! mVoiceAudioTimer.reset(VoiceAudioSampleTime); ! processRecordingAudio(); ! } ! } } --- 100,104 ---- } } ! mVoiceRecorder.idle(timeDelta); } *************** *** 242,266 **** } ! if(mRecordingAudio) ! { ! F32 amt = mMaxAudioSample / F32(0x7FFF); ! U32 totalLineCount = 50; ! ! glColor3f(1, 1 ,1); ! glBegin(GL_LINES); ! glVertex2f(10, 130); ! glVertex2f(10, 145); ! glVertex2f(10 + totalLineCount * 2, 130); ! glVertex2f(10 + totalLineCount * 2, 145); ! glColor3f(0.8, 0.8, 0.8); ! ! for(U32 i = 1; i < amt * totalLineCount; i++) ! { ! glVertex2f(10 + i * 2, 130); ! glVertex2f(10 + i * 2, 145); ! } ! glEnd(); ! } ! #if 0 // some code for outputting the position of the ship for finding good spawns --- 232,236 ---- } ! mVoiceRecorder.render(); #if 0 // some code for outputting the position of the ship for finding good spawns *************** *** 326,330 **** { case 0: ! startRecordingAudio(); break; --- 296,300 ---- { case 0: ! mVoiceRecorder.start(); break; *************** *** 356,360 **** { case 0: ! stopRecordingAudio(); break; case 3: --- 326,330 ---- { case 0: ! mVoiceRecorder.stop(); break; case 3: *************** *** 439,443 **** break; case 'R': ! startRecordingAudio(); break; } --- 409,413 ---- break; case 'R': ! mVoiceRecorder.start(); break; } *************** *** 515,519 **** break; case 'R': ! stopRecordingAudio(); break; } --- 485,489 ---- break; case 'R': ! mVoiceRecorder.stop(); break; } *************** *** 526,580 **** } - void GameUserInterface::startRecordingAudio() - { - if(!mRecordingAudio) - { - mUnusedAudio = new ByteBuffer(0); - mRecordingAudio = true; - mMaxAudioSample = 0; - mVoiceAudioTimer.reset(FirstVoiceAudioSampleTime); - SFXObject::startRecording(); - - // trim the start of the capture buffer: - SFXObject::captureSamples(mUnusedAudio); - mUnusedAudio->resize(0); - } - } - - void GameUserInterface::stopRecordingAudio() - { - if(mRecordingAudio) - { - processRecordingAudio(); - SFXObject::stopRecording(); - - mRecordingAudio = false; - SFXObject::stopRecording(); - mVoiceSfx = NULL; - mUnusedAudio = NULL; - } - } - - void GameUserInterface::processRecordingAudio() - { - SFXObject::captureSamples(mUnusedAudio); - ByteBufferPtr sendBuffer = mVoiceEncoder->compressBuffer(mUnusedAudio); - - U32 sampleCount = mUnusedAudio->getBufferSize() / 2; - S16 *samplePtr = (S16 *) mUnusedAudio->getBuffer(); - mMaxAudioSample = 0; - - for(U32 i = 0; i < sampleCount; i++) - if(samplePtr[i] > mMaxAudioSample) - mMaxAudioSample = samplePtr[i]; - - if(sendBuffer.isValid()) - { - GameType *gt = gClientGame->getGameType(); - if(gt) - gt->c2sVoiceChat(OptionsMenuUserInterface::echoVoice, *(sendBuffer.getPointer())); - } - } - Move *GameUserInterface::getCurrentMove() { --- 496,499 ---- *************** *** 644,646 **** --- 563,686 ---- } + GameUserInterface::VoiceRecorder::VoiceRecorder() + { + mRecordingAudio = false; + mMaxAudioSample = 0; + mMaxForGain = 0; + mVoiceEncoder = new LPC10VoiceEncoder; + } + + void GameUserInterface::VoiceRecorder::idle(U32 timeDelta) + { + if(mRecordingAudio) + { + if(mVoiceAudioTimer.update(timeDelta)) + { + mVoiceAudioTimer.reset(VoiceAudioSampleTime); + process(); + } + } + } + + void GameUserInterface::VoiceRecorder::render() + { + if(mRecordingAudio) + { + F32 amt = mMaxAudioSample / F32(0x7FFF); + U32 totalLineCount = 50; + + glColor3f(1, 1 ,1); + glBegin(GL_LINES); + glVertex2f(10, 130); + glVertex2f(10, 145); + glVertex2f(10 + totalLineCount * 2, 130); + glVertex2f(10 + totalLineCount * 2, 145); + glColor3f(0.8, 0.8, 0.8); + + for(U32 i = 1; i < amt * totalLineCount; i++) + { + glVertex2f(10 + i * 2, 130); + glVertex2f(10 + i * 2, 145); + } + glEnd(); + } + } + + void GameUserInterface::VoiceRecorder::start() + { + if(!mRecordingAudio) + { + mUnusedAudio = new ByteBuffer(0); + mRecordingAudio = true; + mMaxAudioSample = 0; + mVoiceAudioTimer.reset(FirstVoiceAudioSampleTime); + SFXObject::startRecording(); + + // trim the start of the capture buffer: + SFXObject::captureSamples(mUnusedAudio); + mUnusedAudio->resize(0); + } + } + + void GameUserInterface::VoiceRecorder::stop() + { + if(mRecordingAudio) + { + process(); + SFXObject::stopRecording(); + + mRecordingAudio = false; + SFXObject::stopRecording(); + mVoiceSfx = NULL; + mUnusedAudio = NULL; + } + } + + void GameUserInterface::VoiceRecorder::process() + { + U32 preSampleCount = mUnusedAudio->getBufferSize() / 2; + SFXObject::captureSamples(mUnusedAudio); + + U32 sampleCount = mUnusedAudio->getBufferSize() / 2; + S16 *samplePtr = (S16 *) mUnusedAudio->getBuffer(); + mMaxAudioSample = 0; + + for(U32 i = preSampleCount; i < sampleCount; i++) + { + if(samplePtr[i] > mMaxAudioSample) + mMaxAudioSample = samplePtr[i]; + else if(-samplePtr[i] > mMaxAudioSample) + mMaxAudioSample = -samplePtr[i]; + } + mMaxForGain *= 0.95; + S32 boostedMax = mMaxAudioSample + 2048; + if(boostedMax > mMaxForGain) + mMaxForGain = boostedMax; + if(mMaxForGain > MaxDetectionThreshold) + { + // apply some gain to the buffer: + F32 gain = 0x7FFF / F32(mMaxForGain); + for(U32 i = preSampleCount; i < sampleCount; i++) + { + F32 sample = gain * samplePtr[i]; + if(sample > 0x7FFF) + samplePtr[i] = 0x7FFF; + else if(sample < -0x7FFF) + samplePtr[i] = -0x7FFF; + else + samplePtr[i] = S16(sample); + } + mMaxAudioSample *= gain; + } + + ByteBufferPtr sendBuffer = mVoiceEncoder->compressBuffer(mUnusedAudio); + + if(sendBuffer.isValid()) + { + GameType *gt = gClientGame->getGameType(); + if(gt) + gt->c2sVoiceChat(OptionsMenuUserInterface::echoVoice, *(sendBuffer.getPointer())); + } + } + }; |