opentnl-cvs Mailing List for Torque Network Library (Page 21)
Brought to you by:
mark_frohnmayer,
s_alanet
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(141) |
May
(232) |
Jun
(103) |
Jul
(36) |
Aug
(35) |
Sep
(19) |
Oct
(20) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
|
Feb
(26) |
Mar
(2) |
Apr
(84) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Mark F. <mar...@us...> - 2004-05-10 22:34:50
|
Update of /cvsroot/opentnl/tnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22383/tnl Modified Files: tnl.vcproj tnlTypes.h Added Files: journal.cpp tnlJournal.h Log Message: Added initial pass-through journaling code to TNL cleaned up SFX a bit. --- NEW FILE: tnlJournal.h --- //----------------------------------------------------------------------------------- // // Torque Network Library // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #ifndef _TNL_JOURNAL_H_ #define _TNL_JOURNAL_H_ #include "tnlMethodDispatch.h" #include <stdio.h> #define TNL_ENABLE_JOURNALING namespace TNL { /// The Journal class represents the recordable entry point(s) into program execution. /// When journaling is enabled by the TNL_ENABLE_JOURNALING macro, any calls into specially /// marked Journal methods will be intercepted and potentially recorded for later playback. /// If TNL_ENABLE_JOURNALING is not defined, all of the interception code will be disabled. class Journal : public Object { FILE *journalFile; BitStream readStream; BitStream writeStream; public: void record(const char *fileName); void load(const char *fileName); void callEntry(const char *funcName, MarshalledCall *theCall); void processNextJournalEntry(); }; struct JournalEntryRecord { const char *mFunctionName; JournalEntryRecord *mNext; static JournalEntryRecord *mList; JournalEntryRecord(const char *functionName) { mFunctionName = functionName; mNext = mList; mList = this; } virtual void getFuncPtr(MethodPointer &m) = 0; }; #ifdef TNL_ENABLE_JOURNALING #define TNL_DECLARE_JOURNAL_ENTRYPOINT(func, args) \ virtual void FN_CDECL func args; \ virtual void FN_CDECL func##_body args #define TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(className, func, args) \ TNL::MethodArgList Journal_##className##_##func(#className, #args); \ struct Journal_##className##_##func##_er : public JournalEntryRecord { \ void getFuncPtr(MethodPointer &m) { \ void (FN_CDECL className::*fptr) args; \ fptr = &className::func##_body; \ m.v1 = *((U32 *) &fptr); \ if(sizeof(fptr) > sizeof(U32)) m.v2 = *(((U32 *) &fptr) + 1); \ }; \ Journal_##className##_##func##_er(const char *name) : JournalEntryRecord(name) {} \ } gJournal_##className##_##func##_er(#func); \ void FN_CDECL className::func args { \ SAVE_PARAMS \ MarshalledCall call(&Journal_##className##_##func); \ call.marshall(); \ callEntry(#func, &call); \ } \ void FN_CDECL className::func##_body args #else #define TNL_DECLARE_JOURNAL_ENTRYPOINT(func, args) \ void func args #define TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(className, func, args) \ void className::func args #endif }; #endif Index: tnl.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnl.vcproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tnl.vcproj 6 May 2004 00:33:38 -0000 1.2 --- tnl.vcproj 10 May 2004 22:34:23 -0000 1.3 *************** *** 184,187 **** --- 184,190 ---- </File> <File + RelativePath=".\journal.cpp"> + </File> + <File RelativePath=".\log.cpp"> </File> *************** *** 319,322 **** --- 322,328 ---- </File> <File + RelativePath=".\tnlJournal.h"> + </File> + <File RelativePath=".\tnlLog.h"> </File> --- NEW FILE: journal.cpp --- //----------------------------------------------------------------------------------- // // Torque Network Library // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #include "tnlJournal.h" namespace TNL { JournalEntryRecord *JournalEntryRecord::mList = NULL; void Journal::callEntry(const char *funcName, MarshalledCall *theCall) { BitStream unmarshallData(theCall->marshalledData.getBuffer(), theCall->marshalledData.getBytePosition()); theCall->unmarshall(&unmarshallData); for(JournalEntryRecord *walk = JournalEntryRecord::mList; walk; walk = walk->mNext) { if(!strcmp(walk->mFunctionName, funcName)) { MethodPointer p; walk->getFuncPtr(p); theCall->dispatch((void *) this, &p); return; } } } }; Index: tnlTypes.h =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnlTypes.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tnlTypes.h 6 May 2004 00:33:38 -0000 1.4 --- tnlTypes.h 10 May 2004 22:34:23 -0000 1.5 *************** *** 241,245 **** --- 241,250 ---- # define TNL_OS_STRING "Win32" # define TNL_OS_WIN32 + + #ifdef TNL_COMPILER_MINGW + # define FN_CDECL + #else # define FN_CDECL __cdecl + #endif #elif defined(linux) |
From: Mark F. <mar...@us...> - 2004-05-10 22:34:50
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22383/zap Modified Files: main.cpp sfx.cpp Log Message: Added initial pass-through journaling code to TNL cleaned up SFX a bit. Index: main.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** main.cpp 7 May 2004 22:59:11 -0000 1.24 --- main.cpp 10 May 2004 22:34:24 -0000 1.25 *************** *** 29,32 **** --- 29,33 ---- #include "../tnl/tnlGhostConnection.h" #include "../tnl/tnlNetInterface.h" + #include "../tnl/tnlJournal.h" #include "glutInclude.h" *************** *** 58,69 **** const char *gLevelList = "level4.txt level2.txt level1.txt level2.txt level3.txt level2.txt"; void reshape(int nw, int nh) { ! UserInterface::windowWidth = nw; ! UserInterface::windowHeight = nh; } void motion(int x, int y) { if(UserInterface::current) UserInterface::current->onMouseDragged(x, y); --- 59,97 ---- const char *gLevelList = "level4.txt level2.txt level1.txt level2.txt level3.txt level2.txt"; + class ZapJournal : public Journal + { + public: + TNL_DECLARE_JOURNAL_ENTRYPOINT(reshape, (S32 newWidth, S32 newHeight)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(motion, (S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(passivemotion, (S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(key, (U8 key, S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(keyup, (U8 key, S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(mouse, (S32 button, S32 state, S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(specialkey, (S32 key, S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(specialkeyup, (S32 key, S32 x, S32 y)); + TNL_DECLARE_JOURNAL_ENTRYPOINT(idle, ()); + TNL_DECLARE_JOURNAL_ENTRYPOINT(display, ()); + }; + + ZapJournal gZapJournal; + void reshape(int nw, int nh) { ! gZapJournal.reshape(nw, nh); ! } ! ! TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, reshape, (S32 newWidth, S32 newHeight)) ! { ! UserInterface::windowWidth = newWidth; ! UserInterface::windowHeight = newHeight; } void motion(int x, int y) { + gZapJournal.motion(x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, motion, (S32 x, S32 y)) + { if(UserInterface::current) UserInterface::current->onMouseDragged(x, y); *************** *** 72,75 **** --- 100,108 ---- void passivemotion(int x, int y) { + gZapJournal.passivemotion(x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, passivemotion, (S32 x, S32 y)) + { if(UserInterface::current) UserInterface::current->onMouseMoved(x, y); *************** *** 78,81 **** --- 111,119 ---- void key(unsigned char key, int x, int y) { + gZapJournal.key(key, x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, key, (U8 key, S32 x, S32 y)) + { if(UserInterface::current) UserInterface::current->onKeyDown(key); *************** *** 84,87 **** --- 122,130 ---- void keyup(unsigned char key, int x, int y) { + gZapJournal.keyup(key, x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, keyup, (U8 key, S32 x, S32 y)) + { if(UserInterface::current) UserInterface::current->onKeyUp(key); *************** *** 90,93 **** --- 133,141 ---- void mouse(int button, int state, int x, int y) { + gZapJournal.mouse(button, state, x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, mouse, (S32 button, S32 state, S32 x, S32 y)) + { static int mouseState[2] = { 0, }; if(!UserInterface::current) *************** *** 124,127 **** --- 172,180 ---- void specialkey(int key, int x, int y) { + gZapJournal.specialkey(key, x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, specialkey, (S32 key, S32 x, S32 y)) + { if(UserInterface::current) UserInterface::current->onSpecialKeyDown(key); *************** *** 130,133 **** --- 183,191 ---- void specialkeyup(int key, int x, int y) { + gZapJournal.specialkeyup(key, x, y); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, specialkeyup, (S32 key, S32 x, S32 y)) + { if(UserInterface::current) UserInterface::current->onSpecialKeyUp(key); *************** *** 136,139 **** --- 194,202 ---- void idle() { + gZapJournal.idle(); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, idle, ()) + { static S64 lastTimer = Platform::getHighPrecisionTimerValue(); static F64 unusedFraction = 0; *************** *** 172,175 **** --- 235,243 ---- void display(void) { + gZapJournal.display(); + } + + TNL_IMPLEMENT_JOURNAL_ENTRYPOINT(ZapJournal, display, ()) + { if(UserInterface::current) UserInterface::current->render(); Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** sfx.cpp 8 May 2004 22:59:58 -0000 1.18 --- sfx.cpp 10 May 2004 22:34:24 -0000 1.19 *************** *** 210,215 **** static ALuint gSources[NumSources]; - static bool gSourceActive[NumSources]; - static bool gQueuedBuffers[NumSources] = { false, }; Point SFXObject::mListenerPosition; Point SFXObject::mListenerVelocity; --- 210,213 ---- *************** *** 338,341 **** --- 336,342 ---- void SFXObject::queueBuffer(ByteBufferPtr p) { + if(!gSFXValid) + return; + mInitialBuffer = p; if(mSourceIndex != -1) *************** *** 389,399 **** mInitialBuffer->getBufferSize(), 8000); alSourceQueueBuffers(source, 1, &buffer); - gQueuedBuffers[mSourceIndex] = true; } else - { alSourcei(source, AL_BUFFER, gBuffers[mSFXIndex]); - gQueuedBuffers[mSourceIndex] = false; - } alSourcei(source, AL_LOOPING, mProfile->isLooping); --- 390,396 ---- *************** *** 409,412 **** --- 406,412 ---- void SFXObject::setGain(F32 gain) { + if(!gSFXValid) + return; + mGain = gain; if(mSourceIndex != -1) *************** *** 416,419 **** --- 416,422 ---- void SFXObject::setMovementParams(Point position, Point velocity) { + if(!gSFXValid) + return; + mPosition = position; mVelocity = velocity; *************** *** 424,427 **** --- 427,433 ---- void SFXObject::play() { + if(!gSFXValid) + return; + if(mSourceIndex != -1) return; *************** *** 438,441 **** --- 444,450 ---- void SFXObject::stop() { + if(!gSFXValid) + return; + // remove from the play list, if this sound is playing: if(mSourceIndex != -1) *************** *** 541,544 **** --- 550,554 ---- // ones need to be retired: + bool sourceActive[NumSources]; for(S32 i = 0; i < NumSources; i++) { *************** *** 546,550 **** unqueueBuffers(i); alGetSourcei(gSources[i], AL_SOURCE_STATE, &state); ! gSourceActive[i] = state != AL_STOPPED && state != AL_INITIAL; } for(S32 i = 0; i < gPlayList.size(); ) --- 556,560 ---- unqueueBuffers(i); alGetSourcei(gSources[i], AL_SOURCE_STATE, &state); ! sourceActive[i] = state != AL_STOPPED && state != AL_INITIAL; } for(S32 i = 0; i < gPlayList.size(); ) *************** *** 552,556 **** SFXHandle &s = gPlayList[i]; ! if(s->mSourceIndex != -1 && !gSourceActive[s->mSourceIndex]) { // this sound was playing; now it is stopped, --- 562,566 ---- SFXHandle &s = gPlayList[i]; ! if(s->mSourceIndex != -1 && !sourceActive[s->mSourceIndex]) { // this sound was playing; now it is stopped, *************** *** 593,597 **** if(s->mSourceIndex != -1) { ! gSourceActive[s->mSourceIndex] = false; s->mSourceIndex = -1; } --- 603,607 ---- if(s->mSourceIndex != -1) { ! sourceActive[s->mSourceIndex] = false; s->mSourceIndex = -1; } *************** *** 612,619 **** if(s->mSourceIndex == -1) { ! while(gSourceActive[firstFree]) firstFree++; s->mSourceIndex = firstFree; ! gSourceActive[firstFree] = true; s->playOnSource(); } --- 622,629 ---- if(s->mSourceIndex == -1) { ! while(sourceActive[firstFree]) firstFree++; s->mSourceIndex = firstFree; ! sourceActive[firstFree] = true; s->playOnSource(); } |
From: Ben G. <s_a...@us...> - 2004-05-09 22:17:54
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21206/zap Modified Files: winJoystick.cpp Log Message: Fixed issue with out-of-control window movement in relation to the mouse lock functionality. Index: winJoystick.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/winJoystick.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** winJoystick.cpp 7 May 2004 22:59:11 -0000 1.7 --- winJoystick.cpp 9 May 2004 22:17:28 -0000 1.8 *************** *** 56,59 **** --- 56,67 ---- GetCursorPos(&cp); + // Check our position in the window; if we're close to the top (within 32px) then ignore + // same if we're within 5px of the edges. That way we can avoid going crazy when + // people try to resize/drag the window. + if(cp.x - r.top < 32) return; + if(cp.y - r.left < 5) return; + if(r.right - cp.y < 5) return; + if(r.bottom - cp.x < 5) return; + S32 centerX = (r.right + r.left) >> 1; S32 centerY = (r.bottom + r.top) >> 1; |
From: Mark F. <mar...@us...> - 2004-05-09 20:44:17
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2905/zap Added Files: gsm.h gsm_decode.c gsm_encode.c gsm_state.c private.h Log Message: Added GSM codec files from HawkVoice --- NEW FILE: gsm_encode.c --- /* GSM voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2003 Phil Frisbie, Jr. (ph...@ha...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. [...1074 lines suppressed...] *c++ = (unsigned char)(((xmaxc[3] & 0x1) << 7) | ((xmc[39] & 0x7) << 4) | ((xmc[40] & 0x7) << 1) | ((xmc[41] >> 2) & 0x1)); *c++ = (unsigned char)(((xmc[41] & 0x3) << 6) /* 30 */ | ((xmc[42] & 0x7) << 3) | (xmc[43] & 0x7)); *c++ = (unsigned char)(((xmc[44] & 0x7) << 5) | ((xmc[45] & 0x7) << 2) | ((xmc[46] >> 1) & 0x3)); *c++ = (unsigned char)(((xmc[46] & 0x1) << 7) | ((xmc[47] & 0x7) << 4) | ((xmc[48] & 0x7) << 1) | ((xmc[49] >> 2) & 0x1)); *c++ = (unsigned char)(((xmc[49] & 0x3) << 6) | ((xmc[50] & 0x7) << 3) | (xmc[51] & 0x7)); return GSM_ENCODED_FRAME_SIZE; } --- NEW FILE: gsm.h --- /* GSM voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2003 Phil Frisbie, Jr. (ph...@ha...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ /* * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Universitaet Berlin. See the accompanying file "COPYRIGHT" for * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ #ifndef GSM_H #define GSM_H #ifdef __cplusplus extern "C" { #endif #define GSM_SAMPLES_PER_FRAME 160 #define GSM_ENCODED_FRAME_SIZE 33 /* The GSM_OPT_LTP_CUT option speeds up encoding by using an alternate */ /* faster algorithm to calculate the long term predictor */ #define GSM_OPT_LTP_CUT 3 struct gsm_state * gsm_create(void); void gsm_destroy(struct gsm_state *st); int gsm_option(struct gsm_state *st, int opt, int *val); int gsm_encode(struct gsm_state *st, short *in, unsigned char *out); int gsm_decode(struct gsm_state *st, unsigned char *in, short *out); #ifdef __cplusplus } /* extern "C" */ #endif #endif /* GSM_H */ --- NEW FILE: gsm_decode.c --- /* GSM voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2003 Phil Frisbie, Jr. (ph...@ha...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ /* * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Universitaet Berlin. See the accompanying file "COPYRIGHT" for * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ #include "private.h" static gsmword gsm_FACd[8] = {18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767}; static gsmword gsm_QLB[4] = {3277, 11469, 21299, 32767}; INLINE void Postprocessing(struct gsm_state *S, short *s) { int k; gsmword msr = S->msr; longword ltmp; for(k = 160; k--; s++) { msr = *s + (gsmword)GSM_MULT_R( msr, 28672 ); /* Deemphasis */ *s = (short)(GSM_ADD(msr, msr) & 0xFFF8); /* Truncation & Upscaling */ } S->msr = msr; } static void APCM_quantization_xmaxc_to_exp_mant(gsmword xmaxc, gsmword *exp_out, gsmword *mant_out) { gsmword exp, mant; exp = 0; if(xmaxc > 15) exp = (gsmword)(SASR(xmaxc, 3) - 1); mant = (gsmword)(xmaxc - SASL( exp, 3 )); if(mant == 0) { exp = -4; mant = 7; } else { while(mant <= 7) { mant = (gsmword)(SASL(mant, 1) | 1); exp--; } mant -= 8; } *exp_out = exp; *mant_out = mant; } static void APCM_inverse_quantization(gsmword *xMc, gsmword mant, gsmword exp, gsmword *xMp) { int i; gsmword temp, temp1, temp2, temp3; longword ltmp; temp1 = gsm_FACd[ mant ]; /* see 4.2-15 for mant */ temp2 = (gsmword)GSM_SUB( 6, exp ); /* see 4.2-15 for exp */ temp3 = (gsmword)SASL( 1, GSM_SUB( temp2, 1 )); for(i = 13; i--;) { temp = (gsmword)(SASL(*xMc++, 1) - 7); /* restore sign */ temp = (gsmword)SASL(temp, 12); /* 16 bit signed */ temp = (gsmword)GSM_MULT_R( temp1, temp ); temp = (gsmword)GSM_ADD( temp, temp3 ); *xMp++ = (gsmword)SASR( temp, temp2 ); } } static void RPE_grid_positioning(gsmword Mc, gsmword *xMp, gsmword *ep) { int i = 13; switch (Mc) { case 3: *ep++ = 0; case 2: do { *ep++ = 0; case 1: *ep++ = 0; case 0: *ep++ = *xMp++; } while (--i != 0); } while(++Mc < 4) *ep++ = 0; } static void Gsm_RPE_Decoding(gsmword xmaxcr, gsmword Mcr, gsmword *xMcr, gsmword *erp) { gsmword exp, mant; gsmword xMp[ 13 ]; APCM_quantization_xmaxc_to_exp_mant(xmaxcr, &exp, &mant); APCM_inverse_quantization(xMcr, mant, exp, xMp); RPE_grid_positioning(Mcr, xMp, erp); } static void Decoding_of_the_coded_Log_Area_Ratios(gsmword *LARc, gsmword *LARpp) { gsmword temp1; long ltmp; #undef STEP #define STEP( B, MIC, INVA ) \ temp1 = (gsmword)(SASL( *LARc++ + MIC , 10)); \ temp1 -= SASL( B, 1 ); \ temp1 = (gsmword)GSM_MULT_R( INVA, temp1 ); \ *LARpp++ = (gsmword)GSM_ADD( temp1, temp1 ); STEP( 0, -32, 13107 ); STEP( 0, -32, 13107 ); STEP( 2048, -16, 13107 ); STEP( -2560, -16, 13107 ); STEP( 94, -8, 19223 ); STEP( -1792, -8, 17476 ); STEP( -341, -4, 31454 ); STEP( -1144, -4, 29708 ); } INLINE void Coefficients_0_12(gsmword * LARpp_j_1, gsmword * LARpp_j, gsmword * LARp) { int i; for(i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) { *LARp = (gsmword)(SASR( *LARpp_j_1, 2 ) + SASR( *LARpp_j, 2 )); *LARp += (gsmword)SASR( *LARpp_j_1, 1); } } INLINE void Coefficients_13_26(gsmword * LARpp_j_1, gsmword * LARpp_j, gsmword * LARp) { int i; for(i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) *LARp = SASR( *LARpp_j_1, 1) + SASR( *LARpp_j, 1 ); } INLINE void Coefficients_27_39(gsmword * LARpp_j_1, gsmword * LARpp_j, gsmword * LARp) { int i; for(i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { *LARp = (gsmword)(SASR( *LARpp_j_1, 2 ) + SASR( *LARpp_j, 2 )); *LARp += (gsmword)SASR( *LARpp_j, 1 ); } } INLINE void Coefficients_40_159(gsmword * LARpp_j, gsmword * LARp) { int i; for(i = 1; i <= 8; i++, LARp++, LARpp_j++) *LARp = *LARpp_j; } static void LARp_to_rp(gsmword * LARp) { int i; gsmword temp; for (i = 1; i <= 8; i++, LARp++) { if (*LARp < 0) { temp = (gsmword)GSM_ABS( *LARp ); *LARp = (gsmword)(- ((temp < 11059) ? SASL( temp, 1 ) : ((temp < 20070) ? temp + 11059 : ( SASR( temp, 2 ) + 26112 )))); } else { temp = *LARp; *LARp = (gsmword)((temp < 11059) ? SASL( temp, 1 ) : ((temp < 20070) ? temp + 11059 : ( SASR( temp, 2 ) + 26112 ))); } } } static void Short_term_synthesis_filtering(struct gsm_state *S, gsmword *rrp, int k, gsmword *wt, short *sr) { gsmword * v = S->v; gsmword sri; longword ltmp; gsmword v0=v[0], v1=v[1], v2=v[2], v3=v[3], v4=v[4], v5=v[5], v6=v[6], v7=v[7]; gsmword rrp0, rrp1, rrp2, rrp3, rrp4, rrp5, rrp6, rrp7; rrp0 = rrp[0]; rrp1 = rrp[1]; rrp2 = rrp[2]; rrp3 = rrp[3]; rrp4 = rrp[4]; rrp5 = rrp[5]; rrp6 = rrp[6]; rrp7 = rrp[7]; while(k-- != 0) { sri = *wt++; sri -= (gsmword)GSM_MULT_R(rrp7, v7); sri -= (gsmword)GSM_MULT_R(rrp6, v6); v7 = v6 + (gsmword)GSM_MULT_R(rrp6, sri); sri -= (gsmword)GSM_MULT_R(rrp5, v5); v6 = v5 + (gsmword)GSM_MULT_R(rrp5, sri); sri -= (gsmword)GSM_MULT_R(rrp4, v4); v5 = v4 + (gsmword)GSM_MULT_R(rrp4, sri); sri -= (gsmword)GSM_MULT_R(rrp3, v3); v4 = v3 + (gsmword)GSM_MULT_R(rrp3, sri); sri -= (gsmword)GSM_MULT_R(rrp2, v2); v3 = v2 + (gsmword)GSM_MULT_R(rrp2, sri); sri -= (gsmword)GSM_MULT_R(rrp1, v1); v2 = v1 + (gsmword)GSM_MULT_R(rrp1, sri); sri = (gsmword)GSM_SUB( sri, (gsmword)GSM_MULT_R(rrp0, v0) ); v1 = v0 + (gsmword)GSM_MULT_R(rrp0, sri); v0 = sri; *sr++ = (short)sri; } v[0]=GSM_ADD(v0, 0); v[1]=GSM_ADD(v1, 0); v[2]=GSM_ADD(v2, 0); v[3]=GSM_ADD(v3, 0); v[4]=GSM_ADD(v4, 0); v[5]=GSM_ADD(v5, 0); v[6]=GSM_ADD(v6, 0); v[7]=GSM_ADD(v7, 0); } static void Gsm_Short_Term_Synthesis_Filter(struct gsm_state * S, gsmword *LARcr, gsmword *wt, short *s) { gsmword * LARpp_j = S->LARpp[ S->j ]; gsmword * LARpp_j_1 = S->LARpp[ S->j ^=1 ]; gsmword LARp[8]; Decoding_of_the_coded_Log_Area_Ratios(LARcr, LARpp_j); Coefficients_0_12(LARpp_j_1, LARpp_j, LARp); LARp_to_rp(LARp); Short_term_synthesis_filtering(S, LARp, 13, wt, s); Coefficients_13_26(LARpp_j_1, LARpp_j, LARp); LARp_to_rp(LARp); Short_term_synthesis_filtering(S, LARp, 14, wt + 13, s + 13); Coefficients_27_39(LARpp_j_1, LARpp_j, LARp); LARp_to_rp(LARp); Short_term_synthesis_filtering(S, LARp, 13, wt + 27, s + 27); Coefficients_40_159(LARpp_j, LARp); LARp_to_rp(LARp); Short_term_synthesis_filtering(S, LARp, 120, wt + 40, s + 40); } static void Gsm_Long_Term_Synthesis_Filtering(struct gsm_state *S, gsmword Ncr, gsmword bcr, gsmword *erp, gsmword *drp) { int k; gsmword brp, Nr; gsmword * pdrp; Nr = (gsmword)(Ncr < 40 || Ncr > 120 ? S->nrp : Ncr); S->nrp = Nr; brp = gsm_QLB[ bcr ]; pdrp = drp; for(k = 40; k--; pdrp++) { *pdrp = (gsmword)(*erp++ + GSM_MULT_R( brp, pdrp[ -(Nr) ] )); } memcpy(&drp[-120], &drp[-80], (sizeof(drp[0]) * 120)); } static void Gsm_Decoder(struct gsm_state *S, gsmword *LARcr, gsmword *Ncr, gsmword *bcr, gsmword *Mcr, gsmword *xmaxcr, gsmword *xMcr, short *s) { int j; gsmword erp[40], wt[160]; gsmword * drp = S->dp0 + 120; for(j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) { Gsm_RPE_Decoding( *xmaxcr, *Mcr, xMcr, erp ); Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp ); memcpy(&wt[ j * 40 ], drp, sizeof(drp[0]) * 40); } Gsm_Short_Term_Synthesis_Filter(S, LARcr, wt, s); Postprocessing(S, s); } int gsm_decode ( struct gsm_state *s, unsigned char *c, short *target) { gsmword LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; { if(((*c >> 4) & 0x0F) != GSM_MAGIC) return 0; LARc[0] = (gsmword)((*c++ & 0xF) << 2); /* 1 */ LARc[0] |= (gsmword)((*c >> 6) & 0x3); LARc[1] = (gsmword)(*c++ & 0x3F); LARc[2] = (gsmword)((*c >> 3) & 0x1F); LARc[3] = (gsmword)((*c++ & 0x7) << 2); LARc[3] |= (gsmword)((*c >> 6) & 0x3); LARc[4] = (gsmword)((*c >> 2) & 0xF); LARc[5] = (gsmword)((*c++ & 0x3) << 2); LARc[5] |= (gsmword)((*c >> 6) & 0x3); LARc[6] = (gsmword)((*c >> 3) & 0x7); LARc[7] = (gsmword)(*c++ & 0x7); Nc[0] = (gsmword)((*c >> 1) & 0x7F); bc[0] = (gsmword)((*c++ & 0x1) << 1); bc[0] |= (gsmword)((*c >> 7) & 0x1); Mc[0] = (gsmword)((*c >> 5) & 0x3); xmaxc[0] = (gsmword)((*c++ & 0x1F) << 1); xmaxc[0] |= (gsmword)((*c >> 7) & 0x1); xmc[0] = (gsmword)((*c >> 4) & 0x7); xmc[1] = (gsmword)((*c >> 1) & 0x7); xmc[2] = (gsmword)((*c++ & 0x1) << 2); xmc[2] |= (gsmword)((*c >> 6) & 0x3); xmc[3] = (gsmword)((*c >> 3) & 0x7); xmc[4] = (gsmword)(*c++ & 0x7); xmc[5] = (gsmword)((*c >> 5) & 0x7); xmc[6] = (gsmword)((*c >> 2) & 0x7); xmc[7] = (gsmword)((*c++ & 0x3) << 1); /* 10 */ xmc[7] |= (gsmword)((*c >> 7) & 0x1); xmc[8] = (gsmword)((*c >> 4) & 0x7); xmc[9] = (gsmword)((*c >> 1) & 0x7); xmc[10] = (gsmword)((*c++ & 0x1) << 2); xmc[10] |= (gsmword)((*c >> 6) & 0x3); xmc[11] = (gsmword)((*c >> 3) & 0x7); xmc[12] = (gsmword)(*c++ & 0x7); Nc[1] = (gsmword)((*c >> 1) & 0x7F); bc[1] = (gsmword)((*c++ & 0x1) << 1); bc[1] |= (gsmword)((*c >> 7) & 0x1); Mc[1] = (gsmword)((*c >> 5) & 0x3); xmaxc[1] = (gsmword)((*c++ & 0x1F) << 1); xmaxc[1] |= (gsmword)((*c >> 7) & 0x1); xmc[13] = (gsmword)((*c >> 4) & 0x7); xmc[14] = (gsmword)((*c >> 1) & 0x7); xmc[15] = (gsmword)((*c++ & 0x1) << 2); xmc[15] |= (gsmword)((*c >> 6) & 0x3); xmc[16] = (gsmword)((*c >> 3) & 0x7); xmc[17] = (gsmword)(*c++ & 0x7); xmc[18] = (gsmword)((*c >> 5) & 0x7); xmc[19] = (gsmword)((*c >> 2) & 0x7); xmc[20] = (gsmword)((*c++ & 0x3) << 1); xmc[20] |= (gsmword)((*c >> 7) & 0x1); xmc[21] = (gsmword)((*c >> 4) & 0x7); xmc[22] = (gsmword)((*c >> 1) & 0x7); xmc[23] = (gsmword)((*c++ & 0x1) << 2); xmc[23] |= (gsmword)((*c >> 6) & 0x3); xmc[24] = (gsmword)((*c >> 3) & 0x7); xmc[25] = (gsmword)(*c++ & 0x7); Nc[2] = (gsmword)((*c >> 1) & 0x7F); bc[2] = (gsmword)((*c++ & 0x1) << 1); /* 20 */ bc[2] |= (gsmword)((*c >> 7) & 0x1); Mc[2] = (gsmword)((*c >> 5) & 0x3); xmaxc[2] = (gsmword)((*c++ & 0x1F) << 1); xmaxc[2] |= (gsmword)((*c >> 7) & 0x1); xmc[26] = (gsmword)((*c >> 4) & 0x7); xmc[27] = (gsmword)((*c >> 1) & 0x7); xmc[28] = (gsmword)((*c++ & 0x1) << 2); xmc[28] |= (gsmword)((*c >> 6) & 0x3); xmc[29] = (gsmword)((*c >> 3) & 0x7); xmc[30] = (gsmword)(*c++ & 0x7); xmc[31] = (gsmword)((*c >> 5) & 0x7); xmc[32] = (gsmword)((*c >> 2) & 0x7); xmc[33] = (gsmword)((*c++ & 0x3) << 1); xmc[33] |= (gsmword)((*c >> 7) & 0x1); xmc[34] = (gsmword)((*c >> 4) & 0x7); xmc[35] = (gsmword)((*c >> 1) & 0x7); xmc[36] = (gsmword)((*c++ & 0x1) << 2); xmc[36] |= (gsmword)((*c >> 6) & 0x3); xmc[37] = (gsmword)((*c >> 3) & 0x7); xmc[38] = (gsmword)(*c++ & 0x7); Nc[3] = (gsmword)((*c >> 1) & 0x7F); bc[3] = (gsmword)((*c++ & 0x1) << 1); bc[3] |= (gsmword)((*c >> 7) & 0x1); Mc[3] = (gsmword)((*c >> 5) & 0x3); xmaxc[3] = (gsmword)((*c++ & 0x1F) << 1); xmaxc[3] |= (gsmword)((*c >> 7) & 0x1); xmc[39] = (gsmword)((*c >> 4) & 0x7); xmc[40] = (gsmword)((*c >> 1) & 0x7); xmc[41] = (gsmword)((*c++ & 0x1) << 2); xmc[41] |= (gsmword)((*c >> 6) & 0x3); xmc[42] = (gsmword)((*c >> 3) & 0x7); xmc[43] = (gsmword)(*c++ & 0x7); /* 30 */ xmc[44] = (gsmword)((*c >> 5) & 0x7); xmc[45] = (gsmword)((*c >> 2) & 0x7); xmc[46] = (gsmword)((*c++ & 0x3) << 1); xmc[46] |= (gsmword)((*c >> 7) & 0x1); xmc[47] = (gsmword)((*c >> 4) & 0x7); xmc[48] = (gsmword)((*c >> 1) & 0x7); xmc[49] = (gsmword)((*c++ & 0x1) << 2); xmc[49] |= (gsmword)((*c >> 6) & 0x3); xmc[50] = (gsmword)((*c >> 3) & 0x7); xmc[51] = (gsmword)(*c & 0x7); /* 33 */ } Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target); return GSM_SAMPLES_PER_FRAME; } --- NEW FILE: private.h --- /* GSM voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2003 Phil Frisbie, Jr. (ph...@ha...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ /* * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Universitaet Berlin. See the accompanying file "COPYRIGHT" for * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ #ifndef PRIVATE_H #define PRIVATE_H #ifdef __GNUC__ #define INLINE extern __inline__ #else #ifdef _MSC_VER #define INLINE __inline #pragma warning (disable:4514) #pragma warning (disable:4711) #else #define INLINE #endif #endif #include <memory.h> #include "gsm.h" #define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */ typedef long gsmword; /* 16 or 32 bit signed int */ typedef long longword; /* 32 bit signed int */ struct gsm_state { gsmword dp0[ 280 ]; gsmword z1; /* preprocessing.c, Offset_com. */ longword L_z2; /* Offset_com. */ int mp; /* Preemphasis */ gsmword u[8]; /* short_term_aly_filter.c */ gsmword LARpp[2][8];/* */ gsmword j; /* */ gsmword ltp_cut; /* long_term.c, LTP crosscorr. */ gsmword nrp; /* 40 */ /* long_term.c, synthesis */ gsmword v[9]; /* short_term.c, synthesis */ gsmword msr; /* decoder.c, Postprocessing */ char fast; /* only used if FAST */ }; #define MIN_WORD (-32767 - 1) #define MAX_WORD 32767 #define SASR(x, by) ((x) >> (by)) #define SASL(x, by) ((x) << (by)) # define GSM_MULT_R(a, b) (SASR( ((longword)(a) * (longword)(b)), 15 )) # define GSM_MULT(a, b) (SASR( ((longword)(a) * (longword)(b)), 15 )) # define GSM_ADD(a, b) (gsmword)((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) # define GSM_SUB(a, b) (gsmword)((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) # define GSM_ABS(a) (gsmword)((a) < 0 ? -(a) : (a)) INLINE gsmword gsm_div (gsmword num, gsmword denum) { longword L_num = SASL( num, 15 ); longword L_denum = denum; if (L_num == 0) return 0; return (gsmword)(L_num/L_denum); } #endif /* PRIVATE_H */ --- NEW FILE: gsm_state.c --- /* GSM voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2003 Phil Frisbie, Jr. (ph...@ha...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ /* * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Universitaet Berlin. See the accompanying file "COPYRIGHT" for * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. */ #ifndef MACOSX #include <malloc.h> #endif #include <stdlib.h> #include "private.h" struct gsm_state *gsm_create(void) { struct gsm_state * r; r = (struct gsm_state *)malloc(sizeof(struct gsm_state)); if (!r) return r; memset((char *)r, 0, sizeof(*r)); r->nrp = 40; return r; } void gsm_destroy(struct gsm_state *S) { if(S != NULL) free(S); } int gsm_option( struct gsm_state *r, int opt, int *val) { int result = -1; switch (opt) { case GSM_OPT_LTP_CUT: result = r->ltp_cut; if(val != NULL) r->ltp_cut = (gsmword)*val; break; default: break; } return result; } |
From: Mark F. <mar...@us...> - 2004-05-09 20:41:15
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1923/zap Modified Files: UIGame.cpp Log Message: Added color coded mic level Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** UIGame.cpp 9 May 2004 20:35:17 -0000 1.22 --- UIGame.cpp 9 May 2004 20:41:05 -0000 1.23 *************** *** 596,603 **** 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); --- 596,609 ---- glVertex2f(10 + totalLineCount * 2, 130); glVertex2f(10 + totalLineCount * 2, 145); ! F32 halfway = totalLineCount * 0.5; ! F32 full = amt * totalLineCount; ! for(U32 i = 1; i < full; i++) { + if(i < halfway) + glColor3f(i / halfway, 1, 0); + else + glColor3f(1, 1 - (i - halfway) / halfway, 0); + glVertex2f(10 + i * 2, 130); glVertex2f(10 + i * 2, 145); |
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())); + } + } + }; |
From: Mark F. <mar...@us...> - 2004-05-08 23:00:07
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3925/zap Modified Files: game.h sfx.cpp Log Message: bumped RC label for game string changed SFX code to better manage leaking buffers Index: game.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** game.h 8 May 2004 00:03:51 -0000 1.15 --- game.h 8 May 2004 22:59:58 -0000 1.16 *************** *** 213,217 **** extern void endGame(); ! #define ZAP_GAME_STRING "ZAP 1.2.0 rc 1" }; --- 213,217 ---- extern void endGame(); ! #define ZAP_GAME_STRING "ZAP 1.2.0 rc 2" }; Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** sfx.cpp 8 May 2004 00:26:32 -0000 1.17 --- sfx.cpp 8 May 2004 22:59:58 -0000 1.18 *************** *** 185,189 **** { "ship_explode.wav", false, 1.0, false, 300, 1000 }, { "ship_heal.wav", false, 1.0, false, 300, 1000 }, ! { "ship_turbo.wav", false, 0.15, true, 150, 500 }, { "flag_capture.wav", true, 0.45f, false, 0, 0 }, { "flag_drop.wav", true, 0.45f, false, 0, 0 }, --- 185,189 ---- { "ship_explode.wav", false, 1.0, false, 300, 1000 }, { "ship_heal.wav", false, 1.0, false, 300, 1000 }, ! { "ship_turbo.wav", false, 0.15f, true, 150, 500 }, { "flag_capture.wav", true, 0.45f, false, 0, 0 }, { "flag_drop.wav", true, 0.45f, false, 0, 0 }, *************** *** 341,344 **** --- 341,347 ---- if(mSourceIndex != -1) { + if(!gVoiceFreeBuffers.size()) + return; + ALuint source = gSources[mSourceIndex]; ALuint buffer = gVoiceFreeBuffers.first(); *************** *** 359,362 **** --- 362,370 ---- mInitialBuffer->getBufferSize(), 8000); alSourceQueueBuffers(source, 1, &buffer); + + ALint state; + alGetSourcei(mSourceIndex, AL_SOURCE_STATE, &state); + if(state == AL_STOPPED) + alSourcePlay(mSourceIndex); } else *************** *** 372,375 **** --- 380,386 ---- if(mInitialBuffer.isValid()) { + if(!gVoiceFreeBuffers.size()) + return; + ALuint buffer = gVoiceFreeBuffers.first(); gVoiceFreeBuffers.pop_front(); *************** *** 533,536 **** --- 544,548 ---- { ALint state; + unqueueBuffers(i); alGetSourcei(gSources[i], AL_SOURCE_STATE, &state); gSourceActive[i] = state != AL_STOPPED && state != AL_INITIAL; *************** *** 539,543 **** { SFXHandle &s = gPlayList[i]; - unqueueBuffers(s->mSourceIndex); if(s->mSourceIndex != -1 && !gSourceActive[s->mSourceIndex]) --- 551,554 ---- |
From: Mark F. <mar...@us...> - 2004-05-08 22:01:25
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25789/zap Modified Files: UIGame.cpp UIGame.h ZAP.vcproj gameType.cpp gameType.h Added Files: voiceCodec.cpp voiceCodec.h Log Message: Added new voice codec abstraction classes --- NEW FILE: voiceCodec.h --- //----------------------------------------------------------------------------------- // // Torque Network Library - ZAP example multiplayer vector graphics space game // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #ifndef _VOICECODEC_H_ #define _VOICECODEC_H_ #ifndef _TNL_BYTEBUFFER_H_ #include "tnlByteBuffer.h" #endif using namespace TNL; namespace Zap { /// The VoiceEncoder class is an abstract base class for the various /// voice compression algorithms supported by Zap - initially just the /// HawkVoice variable bitrate LPC10 codec. It takes an arbitrary buffer /// of 16 bit samples at 8KHz and returns a compressed buffer. The /// original buffer is modified to contain any samples that were not used /// due to unfilled frame sizing. class VoiceEncoder : public Object { virtual U32 getSamplesPerFrame() = 0; virtual U32 getMaxCompressedFrameSize() = 0; virtual U32 compressFrame(S16 *samplePtr, U8 *outputPtr) = 0; public: ByteBufferPtr compressBuffer(ByteBufferPtr sampleBuffer); }; /// The VoiceDecoder class is an abstract base class for the various /// voice decompression algorithms supported by Zap - initially just the /// HawkVoice variable bitrate LPC10 codec. It takes a buffer compressed /// with the appropriate VoiceEncoder analogue and returns the decompressed /// 16 bit sample buffer. class VoiceDecoder : public Object { virtual U32 getSamplesPerFrame() = 0; virtual U32 getAvgCompressedFrameSize() = 0; virtual U32 decompressFrame(S16 *framePtr, U8 *inputPtr) = 0; public: ByteBufferPtr decompressBuffer(ByteBufferRef compressedBuffer); }; /// The LPC10VoiceEncoder class implements the HawkVoice LPC10 codec /// compressor. class LPC10VoiceEncoder : public VoiceEncoder { void *encoderState; U32 getSamplesPerFrame(); U32 getMaxCompressedFrameSize(); U32 compressFrame(S16 *samplePtr, U8 *outputPtr); public: LPC10VoiceEncoder(); ~LPC10VoiceEncoder(); }; /// The LPC10VoiceDecoder class implements the HawkVoice LPC10 codec /// decompressor. class LPC10VoiceDecoder : public VoiceDecoder { void *decoderState; U32 getSamplesPerFrame(); U32 getAvgCompressedFrameSize(); U32 decompressFrame(S16 *framePtr, U8 *inputPtr); public: LPC10VoiceDecoder(); ~LPC10VoiceDecoder(); }; }; #endif --- NEW FILE: voiceCodec.cpp --- //----------------------------------------------------------------------------------- // // Torque Network Library - ZAP example multiplayer vector graphics space game // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #include "voiceCodec.h" #include "lpc10.h" namespace Zap { ByteBufferPtr VoiceEncoder::compressBuffer(ByteBufferPtr sampleBuffer) { U32 sampleCount = sampleBuffer->getBufferSize() >> 1; U32 spf = getSamplesPerFrame(); U32 framesUsed = U32(sampleCount / spf); if(framesUsed) { U32 samplesUsed = framesUsed * spf; U32 maxSize = getMaxCompressedFrameSize() * framesUsed; ByteBufferPtr ret = new ByteBuffer(maxSize); U8 *compressedPtr = ret->getBuffer(); S16 *samplePtr = (S16 *) sampleBuffer->getBuffer(); U32 len = 0; for(U32 i = 0; i < samplesUsed; i += spf) len += compressFrame(samplePtr + i, compressedPtr + len); ret->resize(len); U32 newSize = (sampleCount - samplesUsed) * sizeof(U16); memcpy(samplePtr, samplePtr + samplesUsed, newSize); sampleBuffer->resize(newSize); return ret; } return NULL; } ByteBufferPtr VoiceDecoder::decompressBuffer(ByteBufferRef compressedBuffer) { U32 spf = getSamplesPerFrame(); U32 avgCompressedSize = getAvgCompressedFrameSize(); U32 compressedSize = compressedBuffer.getBufferSize(); // guess the total number of frames: U32 guessFrameCount = (compressedSize / avgCompressedSize) + 1; ByteBufferPtr ret = new ByteBuffer(spf * sizeof(S16) * guessFrameCount); U32 p = 0; U8 *inputPtr = (U8 *) compressedBuffer.getBuffer(); U32 frameCount = 0; S16 *samplePtr = (S16 *) ret->getBuffer(); for(U32 i = 0; i < compressedSize; i += p) { if(frameCount == guessFrameCount) { guessFrameCount = frameCount + ( (compressedSize - i) / avgCompressedSize ) + 1; ret->resize(spf * sizeof(S16) * guessFrameCount); samplePtr = (S16 *) ret->getBuffer(); } p = decompressFrame(samplePtr + frameCount * spf, inputPtr + i); frameCount++; } ret->resize(frameCount * spf * sizeof(S16)); return ret; } LPC10VoiceEncoder::LPC10VoiceEncoder() { encoderState = create_lpc10_encoder_state(); init_lpc10_encoder_state((lpc10_encoder_state *) encoderState); } LPC10VoiceEncoder::~LPC10VoiceEncoder() { destroy_lpc10_encoder_state((lpc10_encoder_state *) encoderState); } U32 LPC10VoiceEncoder::getSamplesPerFrame() { return LPC10_SAMPLES_PER_FRAME; } U32 LPC10VoiceEncoder::getMaxCompressedFrameSize() { return LPC10_ENCODED_FRAME_SIZE; } U32 LPC10VoiceEncoder::compressFrame(S16 *samplePtr, U8 *outputPtr) { return vbr_lpc10_encode(samplePtr, outputPtr, (lpc10_encoder_state *) encoderState); } LPC10VoiceDecoder::LPC10VoiceDecoder() { decoderState = create_lpc10_decoder_state(); init_lpc10_decoder_state((lpc10_decoder_state *) decoderState); } LPC10VoiceDecoder::~LPC10VoiceDecoder() { destroy_lpc10_decoder_state((lpc10_decoder_state *) decoderState); } U32 LPC10VoiceDecoder::getSamplesPerFrame() { return LPC10_SAMPLES_PER_FRAME; } U32 LPC10VoiceDecoder::getAvgCompressedFrameSize() { return (LPC10_ENCODED_FRAME_SIZE + 1) >> 1; } U32 LPC10VoiceDecoder::decompressFrame(S16 *framePtr, U8 *inputPtr) { int p; vbr_lpc10_decode(inputPtr, framePtr, (lpc10_decoder_state *) decoderState, &p); return (U32) p; } }; Index: gameType.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** gameType.cpp 8 May 2004 00:03:51 -0000 1.21 --- gameType.cpp 8 May 2004 22:01:13 -0000 1.22 *************** *** 433,438 **** cref.wantsScoreboardUpdates = false; cref.ping = 0; ! cref.decoderState = create_lpc10_decoder_state(); ! init_lpc10_decoder_state(cref.decoderState); cref.voiceSFX = new SFXObject(SFXVoice, NULL, 1, Point(), Point()); --- 433,438 ---- cref.wantsScoreboardUpdates = false; cref.ping = 0; ! cref.decoder = new LPC10VoiceDecoder(); ! cref.voiceSFX = new SFXObject(SFXVoice, NULL, 1, Point(), Point()); *************** *** 462,466 **** { S32 clientIndex = findClientIndexByName(name); - destroy_lpc10_decoder_state(mClientList[clientIndex].decoderState); gGameUserInterface.displayMessage(Color(0.6f, 0.6f, 0.8f), "%s left the game.", name.getString()); --- 462,465 ---- *************** *** 626,641 **** if(clientIndex != -1) { ! S16 frame[LPC10_SAMPLES_PER_FRAME]; ! int p = 0, decodeLen = 0; ! ByteBufferPtr playBuffer = new ByteBuffer(0); ! ! for(U32 i = 0; i < voiceBuffer.getBufferSize(); i += p) ! { ! int frameLen = vbr_lpc10_decode((unsigned char *) voiceBuffer.getBuffer() + i, frame, mClientList[clientIndex].decoderState, &p); ! playBuffer->resize((decodeLen + frameLen) * 2); ! ! memcpy(playBuffer->getBuffer() + decodeLen * 2, frame, frameLen * 2); ! decodeLen += frameLen; ! } //logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); --- 625,629 ---- if(clientIndex != -1) { ! ByteBufferPtr playBuffer = mClientList[clientIndex].decoder->decompressBuffer(voiceBuffer); //logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); Index: gameType.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** gameType.h 8 May 2004 00:03:51 -0000 1.11 --- gameType.h 8 May 2004 22:01:13 -0000 1.12 *************** *** 31,35 **** #include "timer.h" #include "sfx.h" ! #include "lpc10.h" namespace Zap --- 31,35 ---- #include "timer.h" #include "sfx.h" ! #include "voiceCodec.h" namespace Zap *************** *** 54,58 **** SafePtr<GameConnection> clientConnection; RefPtr<SFXObject> voiceSFX; ! lpc10_decoder_state *decoderState; U32 ping; ClientRef() { ping = 0; score = 0; } --- 54,59 ---- SafePtr<GameConnection> clientConnection; RefPtr<SFXObject> voiceSFX; ! RefPtr<VoiceDecoder> decoder; ! U32 ping; ClientRef() { ping = 0; score = 0; } Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ZAP.vcproj 7 May 2004 02:21:46 -0000 1.13 --- ZAP.vcproj 8 May 2004 22:01:13 -0000 1.14 *************** *** 313,316 **** --- 313,322 ---- </File> <File + RelativePath=".\voiceCodec.cpp"> + </File> + <File + RelativePath=".\voiceCodec.h"> + </File> + <File RelativePath=".\winJoystick.cpp"> </File> Index: UIGame.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** UIGame.h 7 May 2004 02:21:46 -0000 1.6 --- UIGame.h 8 May 2004 22:01:13 -0000 1.7 *************** *** 34,37 **** --- 34,38 ---- #include "timer.h" #include "sfx.h" + #include "voiceCodec.h" namespace Zap *************** *** 85,88 **** --- 86,91 ---- Timer mVoiceAudioTimer; RefPtr<SFXObject> mVoiceSfx; + RefPtr<VoiceEncoder> mVoiceEncoder; + ByteBufferPtr mUnusedAudio; public: Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** UIGame.cpp 8 May 2004 00:03:51 -0000 1.20 --- UIGame.cpp 8 May 2004 22:01:13 -0000 1.21 *************** *** 61,64 **** --- 61,65 ---- mRecordingAudio = false; mMaxAudioSample = 0; + mVoiceEncoder = new LPC10VoiceEncoder; } *************** *** 525,537 **** } - static lpc10_encoder_state *encoderState = NULL; - void GameUserInterface::startRecordingAudio() { if(!mRecordingAudio) { - encoderState = create_lpc10_encoder_state(); - init_lpc10_encoder_state(encoderState); - mUnusedAudio = new ByteBuffer(0); mRecordingAudio = true; --- 526,533 ---- *************** *** 539,542 **** --- 535,542 ---- mVoiceAudioTimer.reset(FirstVoiceAudioSampleTime); SFXObject::startRecording(); + + // trim the start of the capture buffer: + SFXObject::captureSamples(mUnusedAudio); + mUnusedAudio->resize(0); } } *************** *** 547,555 **** { processRecordingAudio(); ! destroy_lpc10_encoder_state(encoderState); mRecordingAudio = false; SFXObject::stopRecording(); mVoiceSfx = NULL; } } --- 547,556 ---- { processRecordingAudio(); ! SFXObject::stopRecording(); mRecordingAudio = false; SFXObject::stopRecording(); mVoiceSfx = NULL; + mUnusedAudio = NULL; } } *************** *** 558,563 **** { SFXObject::captureSamples(mUnusedAudio); ! U32 sampleCount = mUnusedAudio->getBufferSize() / 2; S16 *samplePtr = (S16 *) mUnusedAudio->getBuffer(); mMaxAudioSample = 0; --- 559,565 ---- { SFXObject::captureSamples(mUnusedAudio); ! ByteBufferPtr sendBuffer = mVoiceEncoder->compressBuffer(mUnusedAudio); + U32 sampleCount = mUnusedAudio->getBufferSize() / 2; S16 *samplePtr = (S16 *) mUnusedAudio->getBuffer(); mMaxAudioSample = 0; *************** *** 567,592 **** mMaxAudioSample = samplePtr[i]; ! U32 useCount = U32(sampleCount / LPC10_SAMPLES_PER_FRAME) * LPC10_SAMPLES_PER_FRAME; ! //U32 useCount = sampleCount - (sampleCount % LPC10_SAMPLES_PER_FRAME); ! ! if(useCount) ! { ! U32 unusedCount = sampleCount - useCount; ! ! U8 codingBuffer[2048]; ! U32 len = 0; ! ! for(U32 i = 0; i < useCount; i += LPC10_SAMPLES_PER_FRAME) ! len += vbr_lpc10_encode(samplePtr + i, codingBuffer + len, encoderState); ! ! memcpy(mUnusedAudio->getBuffer(), mUnusedAudio->getBuffer() + useCount * 2, unusedCount * 2); ! mUnusedAudio->resize(unusedCount * 2); ! ! ByteBuffer sendBuffer(codingBuffer, len); ! //logprintf("Encoded %d samples in %d bytes", useCount, len); ! GameType *gt = gClientGame->getGameType(); if(gt) ! gt->c2sVoiceChat(OptionsMenuUserInterface::echoVoice, sendBuffer); } } --- 569,577 ---- mMaxAudioSample = samplePtr[i]; ! if(sendBuffer.isValid()) ! { GameType *gt = gClientGame->getGameType(); if(gt) ! gt->c2sVoiceChat(OptionsMenuUserInterface::echoVoice, *(sendBuffer.getPointer())); } } |
From: Mark F. <mar...@us...> - 2004-05-08 00:50:36
|
Update of /cvsroot/opentnl/tnl/exe In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10726/exe Modified Files: README.txt Log Message: Updated readme to plug HawkVoice Index: README.txt =================================================================== RCS file: /cvsroot/opentnl/tnl/exe/README.txt,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** README.txt 8 May 2004 00:03:48 -0000 1.8 --- README.txt 8 May 2004 00:50:22 -0000 1.9 *************** *** 13,16 **** --- 13,18 ---- - Added a new CTF level - Added voice recording and playback (recording on Win32 only for now) + - Added voice compression using the variable LPC10 codec from the + excellent HawkVoice library. - Added more sounds |
From: Mark F. <mar...@us...> - 2004-05-08 00:26:43
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5971/zap Modified Files: Makefile sfx.cpp Log Message: Moved function in sfx so not undefined Updated makefiles for linux Index: Makefile =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/Makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile 3 May 2004 23:03:38 -0000 1.5 --- Makefile 8 May 2004 00:26:31 -0000 1.6 *************** *** 36,39 **** --- 36,41 ---- teleporter.o\ barrier.o\ + lpc10dec.o\ + lpc10enc.o\ main.o *************** *** 41,44 **** --- 43,49 ---- CFLAGS= + .c.o: + $(CC) -c $(CFLAGS) $< + .cpp.o : $(CC) -c $(CFLAGS) $< Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** sfx.cpp 8 May 2004 00:18:07 -0000 1.16 --- sfx.cpp 8 May 2004 00:26:32 -0000 1.17 *************** *** 47,55 **** static U32 lastReadOffset = 0; - void SFXObject::setCaptureGain(S32 amt) - { - mCaptureGain = amt; - } - bool SFXObject::startRecording() { --- 47,50 ---- *************** *** 227,230 **** --- 222,230 ---- static Vector<SFXHandle> gPlayList; + void SFXObject::setCaptureGain(S32 amt) + { + mCaptureGain = amt; + } + SFXObject::SFXObject(U32 profileIndex, ByteBufferPtr ib, F32 gain, Point position, Point velocity) { |
From: Mark F. <mar...@us...> - 2004-05-08 00:26:41
|
Update of /cvsroot/opentnl/tnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5971/tnl Modified Files: Makefile Log Message: Moved function in sfx so not undefined Updated makefiles for linux Index: Makefile =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/Makefile,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile 25 Apr 2004 19:07:23 -0000 1.3 --- Makefile 8 May 2004 00:26:31 -0000 1.4 *************** *** 32,35 **** --- 32,36 ---- rpc.o\ symmetricCipher.o\ + tnlMessageDispatch.o\ udp.o\ vector.o\ |
From: Mark F. <mar...@us...> - 2004-05-08 00:19:20
|
Update of /cvsroot/opentnl/tnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4523/tnl Modified Files: tnlMethodDispatch.cpp Log Message: Fixed compile for OS X Index: tnlMethodDispatch.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnlMethodDispatch.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tnlMethodDispatch.cpp 6 May 2004 00:33:38 -0000 1.1 --- tnlMethodDispatch.cpp 8 May 2004 00:19:08 -0000 1.2 *************** *** 515,519 **** U32 delta; ! U8 *data = theEvent->unmarshalledData.getBuffer(); delta = data - rpcReadData; --- 515,520 ---- U32 delta; ! U8 *data; ! data = theEvent->unmarshalledData.getBuffer(); delta = data - rpcReadData; |
From: Mark F. <mar...@us...> - 2004-05-08 00:19:20
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4523/zap Modified Files: lpc10dec.c lpc10enc.c Log Message: Fixed compile for OS X Index: lpc10dec.c =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/lpc10dec.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** lpc10dec.c 7 May 2004 02:21:46 -0000 1.1 --- lpc10dec.c 8 May 2004 00:19:08 -0000 1.2 *************** *** 25,29 **** */ ! #ifndef MACOSX #include <malloc.h> #endif --- 25,29 ---- */ ! #if !defined( MACOSX ) && !defined (__APPLE__) #include <malloc.h> #endif Index: lpc10enc.c =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/lpc10enc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** lpc10enc.c 7 May 2004 02:21:46 -0000 1.1 --- lpc10enc.c 8 May 2004 00:19:09 -0000 1.2 *************** *** 25,29 **** */ ! #ifndef MACOSX #include <malloc.h> #endif --- 25,29 ---- */ ! #if !defined( MACOSX ) && !defined (__APPLE__) #include <malloc.h> #endif |
From: Mark F. <mar...@us...> - 2004-05-08 00:19:20
|
Update of /cvsroot/opentnl/tnl/osx/tnl.xcode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4523/osx/tnl.xcode Modified Files: project.pbxproj Log Message: Fixed compile for OS X Index: project.pbxproj =================================================================== RCS file: /cvsroot/opentnl/tnl/osx/tnl.xcode/project.pbxproj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** project.pbxproj 4 May 2004 00:37:07 -0000 1.5 --- project.pbxproj 8 May 2004 00:19:07 -0000 1.6 *************** *** 93,96 **** --- 93,181 ---- //193 //194 + //1D0 + //1D1 + //1D2 + //1D3 + //1D4 + 1DC82046064C5C9000F61B0E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.cpp.cpp; + name = tnlMethodDispatch.cpp; + path = ../tnl/tnlMethodDispatch.cpp; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 1DC82047064C5C9000F61B0E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = tnlMethodDispatch.h; + path = ../tnl/tnlMethodDispatch.h; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 1DC82048064C5C9000F61B0E = { + fileRef = 1DC82046064C5C9000F61B0E; + isa = PBXBuildFile; + settings = { + }; + }; + 1DC82049064C5C9000F61B0E = { + fileRef = 1DC82047064C5C9000F61B0E; + isa = PBXBuildFile; + settings = { + }; + }; + 1DC8204A064C5CBC00F61B0E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = lpc10.h; + path = ../zap/lpc10.h; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 1DC8204B064C5CBC00F61B0E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.c; + name = lpc10dec.c; + path = ../zap/lpc10dec.c; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 1DC8204C064C5CBC00F61B0E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.c; + name = lpc10enc.c; + path = ../zap/lpc10enc.c; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 1DC8204D064C5CBC00F61B0E = { + fileRef = 1DC8204A064C5CBC00F61B0E; + isa = PBXBuildFile; + settings = { + }; + }; + 1DC8204E064C5CBC00F61B0E = { + fileRef = 1DC8204B064C5CBC00F61B0E; + isa = PBXBuildFile; + settings = { + }; + }; + 1DC8204F064C5CBC00F61B0E = { + fileRef = 1DC8204C064C5CBC00F61B0E; + isa = PBXBuildFile; + settings = { + }; + }; + //1D0 + //1D1 + //1D2 + //1D3 + //1D4 //290 //291 *************** *** 459,462 **** --- 544,549 ---- 6649E0EE05FD022100B3DD8B = { children = ( + 1DC82046064C5C9000F61B0E, + 1DC82047064C5C9000F61B0E, DB9525E3063610C200B8795E, 66BA0CE005FD17F600D882FA, *************** *** 1754,1757 **** --- 1841,1845 ---- DBAFF49C06471A4200683BA4, DBAFF4AA06471AAE00683BA4, + 1DC8204D064C5CBC00F61B0E, ); isa = PBXHeadersBuildPhase; *************** *** 1790,1793 **** --- 1878,1883 ---- DBAFF49B06471A4200683BA4, DBAFF4A906471AAE00683BA4, + 1DC8204E064C5CBC00F61B0E, + 1DC8204F064C5CBC00F61B0E, ); isa = PBXSourcesBuildPhase; *************** *** 2224,2227 **** --- 2314,2320 ---- 6692C0E606247C3B00D5ADFE = { children = ( + 1DC8204A064C5CBC00F61B0E, + 1DC8204B064C5CBC00F61B0E, + 1DC8204C064C5CBC00F61B0E, DBAFF4A706471AAE00683BA4, DBAFF4A806471AAE00683BA4, *************** *** 3425,3428 **** --- 3518,3522 ---- 66BA0C8005FD107700D882FA, 66BA0C8105FD107700D882FA, + 1DC82049064C5C9000F61B0E, ); isa = PBXHeadersBuildPhase; *************** *** 3455,3458 **** --- 3549,3553 ---- 66BA0CE705FD17F600D882FA, DB9525E4063610C200B8795E, + 1DC82048064C5C9000F61B0E, ); isa = PBXSourcesBuildPhase; |
From: Ben G. <s_a...@us...> - 2004-05-08 00:18:21
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4486/zap Modified Files: sfx.cpp Log Message: Better turbo gain! Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** sfx.cpp 8 May 2004 00:03:51 -0000 1.15 --- sfx.cpp 8 May 2004 00:18:07 -0000 1.16 *************** *** 190,194 **** { "ship_explode.wav", false, 1.0, false, 300, 1000 }, { "ship_heal.wav", false, 1.0, false, 300, 1000 }, ! { "ship_turbo.wav", false, 1.0, true, 150, 500 }, { "flag_capture.wav", true, 0.45f, false, 0, 0 }, { "flag_drop.wav", true, 0.45f, false, 0, 0 }, --- 190,194 ---- { "ship_explode.wav", false, 1.0, false, 300, 1000 }, { "ship_heal.wav", false, 1.0, false, 300, 1000 }, ! { "ship_turbo.wav", false, 0.15, true, 150, 500 }, { "flag_capture.wav", true, 0.45f, false, 0, 0 }, { "flag_drop.wav", true, 0.45f, false, 0, 0 }, |
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2429/zap Modified Files: CTFGame.cpp UIGame.cpp UIMenus.cpp UIMenus.h game.h gameType.cpp gameType.h sfx.cpp sfx.h soccerGame.cpp Log Message: Added rendering of currently talking players' names Updated version # to 1.2 rc 1 Added an enable voice echo option to the options menu Index: gameType.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** gameType.cpp 7 May 2004 22:59:11 -0000 1.20 --- gameType.cpp 8 May 2004 00:03:51 -0000 1.21 *************** *** 168,171 **** --- 168,177 ---- } } + renderTimeLeft(); + renderTalkingClients(); + } + + void GameType::renderTimeLeft() + { glColor3f(1,1,1); U32 timeLeft = mGameTimer.getCurrent(); *************** *** 176,179 **** --- 182,200 ---- } + void GameType::renderTalkingClients() + { + S32 y = 150; + for(S32 i = 0; i < mClientList.size(); i++) + { + if(mClientList[i].voiceSFX->isPlaying()) + { + Color teamColor = mTeams[mClientList[i].teamId].color; + glColor3f(teamColor.r, teamColor.g, teamColor.b); + UserInterface::drawString(10, y, 20, mClientList[i].name.getString()); + y += 25; + } + } + } + void GameType::gameOverManGameOver() { *************** *** 580,584 **** } ! TNL_IMPLEMENT_NETOBJECT_RPC(GameType, c2sVoiceChat, (ByteBufferRef voiceBuffer), NetClassGroupGameMask, RPCUnguaranteed, RPCToGhostParent, 0) { --- 601,605 ---- } ! TNL_IMPLEMENT_NETOBJECT_RPC(GameType, c2sVoiceChat, (bool echo, ByteBufferRef voiceBuffer), NetClassGroupGameMask, RPCUnguaranteed, RPCToGhostParent, 0) { *************** *** 589,593 **** S32 clientIndex = findClientIndexByConnection(source); if(clientIndex != -1) ! s2cVoiceChat(mClientList[clientIndex].name, voiceBuffer); } --- 610,621 ---- S32 clientIndex = findClientIndexByConnection(source); if(clientIndex != -1) ! { ! RefPtr<NetEvent> event = TNL_RPC_CONSTRUCT_NETEVENT(this, s2cVoiceChat, (mClientList[clientIndex].name, voiceBuffer)); ! for(S32 i = 0; i < mClientList.size(); i++) ! { ! if((i != clientIndex || echo) && mClientList[i].clientConnection) ! mClientList[i].clientConnection->postNetEvent(event); ! } ! } } *************** *** 611,615 **** } ! logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); mClientList[clientIndex].voiceSFX->queueBuffer(playBuffer); } --- 639,643 ---- } ! //logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); mClientList[clientIndex].voiceSFX->queueBuffer(playBuffer); } Index: soccerGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/soccerGame.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** soccerGame.cpp 6 May 2004 00:33:39 -0000 1.4 --- soccerGame.cpp 8 May 2004 00:03:51 -0000 1.5 *************** *** 125,134 **** } } ! glColor3f(1,1,1); ! U32 timeLeft = mGameTimer.getCurrent(); ! ! U32 minsRemaining = timeLeft / (60000); ! U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000; ! UserInterface::drawStringf(720, 577, 20, "%02d:%02d", minsRemaining, secsRemaining); } --- 125,130 ---- } } ! renderTimeLeft(); ! renderTalkingClients(); } Index: UIMenus.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIMenus.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** UIMenus.h 27 Apr 2004 21:43:04 -0000 1.6 --- UIMenus.h 8 May 2004 00:03:51 -0000 1.7 *************** *** 81,84 **** --- 81,85 ---- static bool fullscreen; static bool joystickEnabled; + static bool echoVoice; OptionsMenuUserInterface(); Index: gameType.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** gameType.h 7 May 2004 22:21:13 -0000 1.10 --- gameType.h 8 May 2004 00:03:51 -0000 1.11 *************** *** 124,127 **** --- 124,129 ---- virtual void renderInterfaceOverlay(bool scoreboardVisible); + void renderTimeLeft(); + void renderTalkingClients(); virtual void updateClientScoreboard(S32 clientIndex); *************** *** 146,150 **** TNL_DECLARE_RPC(c2sRequestScoreboardUpdates, (bool updates)); ! TNL_DECLARE_RPC(c2sVoiceChat, (ByteBufferRef compressedVoice)); TNL_DECLARE_RPC(s2cVoiceChat, (StringTableEntryRef client, ByteBufferRef compressedVoice)); --- 148,152 ---- TNL_DECLARE_RPC(c2sRequestScoreboardUpdates, (bool updates)); ! TNL_DECLARE_RPC(c2sVoiceChat, (bool echo, ByteBufferRef compressedVoice)); TNL_DECLARE_RPC(s2cVoiceChat, (StringTableEntryRef client, ByteBufferRef compressedVoice)); Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** sfx.cpp 7 May 2004 22:21:13 -0000 1.14 --- sfx.cpp 8 May 2004 00:03:51 -0000 1.15 *************** *** 111,115 **** DWORD count2; ! printf("Capturing samples... %d ... %d\n", lastReadOffset, readPosition); if(!byteCount) --- 111,115 ---- DWORD count2; ! //printf("Capturing samples... %d ... %d\n", lastReadOffset, readPosition); if(!byteCount) *************** *** 319,323 **** ALuint buffer; alSourceUnqueueBuffers(gSources[sourceIndex], 1, &buffer); ! logprintf("unqueued buffer %d\n", buffer); processed--; --- 319,323 ---- ALuint buffer; alSourceUnqueueBuffers(gSources[sourceIndex], 1, &buffer); ! //logprintf("unqueued buffer %d\n", buffer); processed--; *************** *** 355,359 **** } ! logprintf("queued buffer %d - %d max %d len\n", buffer, max, mInitialBuffer->getBufferSize()); alBufferData(buffer, AL_FORMAT_MONO16, mInitialBuffer->getBuffer(), mInitialBuffer->getBufferSize(), 8000); --- 355,359 ---- } ! //logprintf("queued buffer %d - %d max %d len\n", buffer, max, mInitialBuffer->getBufferSize()); alBufferData(buffer, AL_FORMAT_MONO16, mInitialBuffer->getBuffer(), mInitialBuffer->getBufferSize(), 8000); Index: UIMenus.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIMenus.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** UIMenus.cpp 30 Apr 2004 06:57:39 -0000 1.9 --- UIMenus.cpp 8 May 2004 00:03:51 -0000 1.10 *************** *** 175,178 **** --- 175,179 ---- bool OptionsMenuUserInterface::fullscreen = false; bool OptionsMenuUserInterface::joystickEnabled = false; + bool OptionsMenuUserInterface::echoVoice = false; OptionsMenuUserInterface::OptionsMenuUserInterface() *************** *** 206,209 **** --- 207,215 ---- menuItems.push_back("ENABLE JOYSTICK/CONTROLLER"); + if(echoVoice) + menuItems.push_back("DISABLE VOICE ECHO"); + else + menuItems.push_back("ENABLE VOICE ECHO"); + if(gClientGame->getConnectionToServer()) menuItems.push_back("RETURN TO GAME"); *************** *** 253,256 **** --- 259,265 ---- break; case 3: + echoVoice = !echoVoice; + break; + case 4: if(gClientGame->getConnectionToServer()) gGameUserInterface.activate(); Index: game.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** game.h 4 May 2004 18:24:51 -0000 1.14 --- game.h 8 May 2004 00:03:51 -0000 1.15 *************** *** 213,217 **** extern void endGame(); ! #define ZAP_GAME_STRING "ZAP 1.1.4" }; --- 213,217 ---- extern void endGame(); ! #define ZAP_GAME_STRING "ZAP 1.2.0 rc 1" }; Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** UIGame.cpp 7 May 2004 22:21:13 -0000 1.19 --- UIGame.cpp 8 May 2004 00:03:51 -0000 1.20 *************** *** 243,253 **** if(mRecordingAudio) { glColor3f(1, 1 ,1); ! glBegin(GL_POLYGON); ! glVertex2f(10, 600); ! glVertex2f(30, 600); ! F32 y = 600 - F32(mMaxAudioSample) * 600 / F32(0x7FFF); ! glVertex2f(30, y); ! glVertex2f(10, y); glEnd(); } --- 243,262 ---- 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(); } *************** *** 575,583 **** ByteBuffer sendBuffer(codingBuffer, len); ! logprintf("Encoded %d samples in %d bytes", useCount, len); GameType *gt = gClientGame->getGameType(); if(gt) ! gt->c2sVoiceChat(sendBuffer); } } --- 584,592 ---- ByteBuffer sendBuffer(codingBuffer, len); ! //logprintf("Encoded %d samples in %d bytes", useCount, len); GameType *gt = gClientGame->getGameType(); if(gt) ! gt->c2sVoiceChat(OptionsMenuUserInterface::echoVoice, sendBuffer); } } Index: sfx.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** sfx.h 7 May 2004 22:21:13 -0000 1.9 --- sfx.h 8 May 2004 00:03:51 -0000 1.10 *************** *** 97,100 **** --- 97,101 ---- void setMovementParams(Point position, Point velocity); void queueBuffer(ByteBufferPtr b); + bool isPlaying() { return mSourceIndex != -1; } static bool startRecording(); Index: CTFGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** CTFGame.cpp 6 May 2004 00:33:39 -0000 1.21 --- CTFGame.cpp 8 May 2004 00:03:50 -0000 1.22 *************** *** 147,156 **** } } ! glColor3f(1,1,1); ! U32 timeLeft = mGameTimer.getCurrent(); ! ! U32 minsRemaining = timeLeft / (60000); ! U32 secsRemaining = (timeLeft - (minsRemaining * 60000)) / 1000; ! UserInterface::drawStringf(720, 577, 20, "%02d:%02d", minsRemaining, secsRemaining); } --- 147,152 ---- } } ! renderTimeLeft(); ! renderTalkingClients(); } |
From: Mark F. <mar...@us...> - 2004-05-08 00:04:00
|
Update of /cvsroot/opentnl/tnl/exe In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2429/exe Modified Files: README.txt Log Message: Added rendering of currently talking players' names Updated version # to 1.2 rc 1 Added an enable voice echo option to the options menu Index: README.txt =================================================================== RCS file: /cvsroot/opentnl/tnl/exe/README.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** README.txt 7 May 2004 22:59:11 -0000 1.7 --- README.txt 8 May 2004 00:03:48 -0000 1.8 *************** *** 1,3 **** ! ZAP 1.1.4 Welcome to ZAP, the retro multiplayer team action game! --- 1,3 ---- ! ZAP 1.2.0 Welcome to ZAP, the retro multiplayer team action game! *************** *** 12,15 **** --- 12,17 ---- - Added credits on exit - Added a new CTF level + - Added voice recording and playback (recording on Win32 only for now) + - Added more sounds Controls: *************** *** 23,26 **** --- 25,29 ---- G - chat global V - open quick chat menu + R - record voice chat C - toggle commander map *************** *** 41,44 **** --- 44,49 ---- left trigger - shield right trigger - boost + + button 1 - record voice chat button 3 - toggle commander map button 4 - show scores |
From: Mark F. <mar...@us...> - 2004-05-07 22:59:20
|
Update of /cvsroot/opentnl/tnl/exe In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22758/exe Modified Files: README.txt Log Message: Fixed crash on exit with VOIP Added param to -joystick command line argument Updated readme with -joystick command line argument Index: README.txt =================================================================== RCS file: /cvsroot/opentnl/tnl/exe/README.txt,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** README.txt 4 May 2004 19:46:33 -0000 1.6 --- README.txt 7 May 2004 22:59:11 -0000 1.7 *************** *** 71,74 **** --- 71,77 ---- -maxplayers [number] sets the maximum number of players allowed on the server + -joystick [joystickType] enables dual analog control pad. The + joystickType argument can be either 0 or 1. If the right + stick doesn't aim shots properly with 0, try 1. Credits: |
From: Mark F. <mar...@us...> - 2004-05-07 22:59:20
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22758/zap Modified Files: gameType.cpp main.cpp winJoystick.cpp Log Message: Fixed crash on exit with VOIP Added param to -joystick command line argument Updated readme with -joystick command line argument Index: main.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** main.cpp 7 May 2004 04:58:00 -0000 1.23 --- main.cpp 7 May 2004 22:59:11 -0000 1.24 *************** *** 52,55 **** --- 52,56 ---- const char *gWindowTitle = "ZAP II - The Return"; U32 gMaxPlayers = 128; + U32 gJoystickType = 0; const char *gMasterAddressString = "IP:master.opentnl.org:29005"; *************** *** 320,326 **** else if(!stricmp(argv[i], "-joystick")) { if(hasAdditionalArg) ! OptionsMenuUserInterface::joystickEnabled = true; ! } else if(!stricmp(argv[i], "-gain")) --- 321,327 ---- else if(!stricmp(argv[i], "-joystick")) { + OptionsMenuUserInterface::joystickEnabled = true; if(hasAdditionalArg) ! gJoystickType = atoi(argv[i+1]); } else if(!stricmp(argv[i], "-gain")) Index: gameType.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** gameType.cpp 7 May 2004 22:21:13 -0000 1.19 --- gameType.cpp 7 May 2004 22:59:11 -0000 1.20 *************** *** 426,430 **** { S32 clientIndex = findClientIndexByConnection(theClient); - destroy_lpc10_decoder_state(mClientList[clientIndex].decoderState); mClientList.erase(clientIndex); --- 426,429 ---- *************** *** 442,445 **** --- 441,446 ---- { S32 clientIndex = findClientIndexByName(name); + destroy_lpc10_decoder_state(mClientList[clientIndex].decoderState); + gGameUserInterface.displayMessage(Color(0.6f, 0.6f, 0.8f), "%s left the game.", name.getString()); mClientList.erase(clientIndex); Index: winJoystick.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/winJoystick.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** winJoystick.cpp 3 May 2004 02:41:01 -0000 1.6 --- winJoystick.cpp 7 May 2004 22:59:11 -0000 1.7 *************** *** 38,41 **** --- 38,42 ---- extern const char *gWindowTitle; + extern U32 gJoystickType; void checkMousePos(S32 maxdx, S32 maxdy) *************** *** 135,140 **** controls[0] = F32( js.lX ) - 32768.0f; controls[1] = F32( js.lY ) - 32768.0f; ! controls[2] = F32( js.lRz ) - 32768.0f; ! controls[3] = F32( js.rglSlider[0] ) - 32768.0f; for(U32 i = 0; i < 4; i++) --- 136,150 ---- controls[0] = F32( js.lX ) - 32768.0f; controls[1] = F32( js.lY ) - 32768.0f; ! ! if(gJoystickType == 0) ! { ! controls[2] = F32( js.lRz ) - 32768.0f; ! controls[3] = F32( js.rglSlider[0] ) - 32768.0f; ! } ! else if(gJoystickType == 1) ! { ! controls[3] = F32( js.lZ ) - 32768.0f; ! controls[2] = F32( js.lRz ) - 32768.0f; ! } for(U32 i = 0; i < 4; i++) |
From: Mark F. <mar...@us...> - 2004-05-07 22:21:30
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14954/zap Modified Files: UIGame.cpp gameType.cpp gameType.h sfx.cpp sfx.h Log Message: V O I P - whee! Index: gameType.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** gameType.cpp 6 May 2004 00:33:39 -0000 1.18 --- gameType.cpp 7 May 2004 22:21:13 -0000 1.19 *************** *** 412,415 **** --- 412,419 ---- cref.wantsScoreboardUpdates = false; cref.ping = 0; + cref.decoderState = create_lpc10_decoder_state(); + init_lpc10_decoder_state(cref.decoderState); + cref.voiceSFX = new SFXObject(SFXVoice, NULL, 1, Point(), Point()); + mClientList.push_back(cref); *************** *** 422,425 **** --- 426,431 ---- { S32 clientIndex = findClientIndexByConnection(theClient); + destroy_lpc10_decoder_state(mClientList[clientIndex].decoderState); + mClientList.erase(clientIndex); *************** *** 573,575 **** --- 579,617 ---- } + TNL_IMPLEMENT_NETOBJECT_RPC(GameType, c2sVoiceChat, (ByteBufferRef voiceBuffer), + NetClassGroupGameMask, RPCUnguaranteed, RPCToGhostParent, 0) + { + // in the naive implementation, we just broadcast this to everyone, + // including the sender... + + GameConnection *source = (GameConnection *) getRPCSourceConnection(); + S32 clientIndex = findClientIndexByConnection(source); + if(clientIndex != -1) + s2cVoiceChat(mClientList[clientIndex].name, voiceBuffer); + } + + TNL_IMPLEMENT_NETOBJECT_RPC(GameType, s2cVoiceChat, (StringTableEntryRef clientName, ByteBufferRef voiceBuffer), + NetClassGroupGameMask, RPCUnguaranteed, RPCToGhost, 0) + { + S32 clientIndex = findClientIndexByName(clientName); + if(clientIndex != -1) + { + S16 frame[LPC10_SAMPLES_PER_FRAME]; + int p = 0, decodeLen = 0; + ByteBufferPtr playBuffer = new ByteBuffer(0); + + for(U32 i = 0; i < voiceBuffer.getBufferSize(); i += p) + { + int frameLen = vbr_lpc10_decode((unsigned char *) voiceBuffer.getBuffer() + i, frame, mClientList[clientIndex].decoderState, &p); + playBuffer->resize((decodeLen + frameLen) * 2); + + memcpy(playBuffer->getBuffer() + decodeLen * 2, frame, frameLen * 2); + decodeLen += frameLen; + } + + logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); + mClientList[clientIndex].voiceSFX->queueBuffer(playBuffer); + } + } + }; \ No newline at end of file Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** UIGame.cpp 7 May 2004 02:21:46 -0000 1.18 --- UIGame.cpp 7 May 2004 22:21:13 -0000 1.19 *************** *** 516,521 **** } ! lpc10_encoder_state *encoderState = NULL; ! lpc10_decoder_state *decoderState = NULL; void GameUserInterface::startRecordingAudio() --- 516,520 ---- } ! static lpc10_encoder_state *encoderState = NULL; void GameUserInterface::startRecordingAudio() *************** *** 526,532 **** init_lpc10_encoder_state(encoderState); - decoderState = create_lpc10_decoder_state(); - init_lpc10_decoder_state(decoderState); - mUnusedAudio = new ByteBuffer(0); mRecordingAudio = true; --- 525,528 ---- *************** *** 543,547 **** processRecordingAudio(); destroy_lpc10_encoder_state(encoderState); - destroy_lpc10_decoder_state(decoderState); mRecordingAudio = false; --- 539,542 ---- *************** *** 579,604 **** mUnusedAudio->resize(unusedCount * 2); logprintf("Encoded %d samples in %d bytes", useCount, len); ! S16 frame[LPC10_SAMPLES_PER_FRAME]; ! int p = 0, decodeLen = 0; ! ByteBufferPtr playBuffer = new ByteBuffer(0); ! ! for(U32 i = 0; i < len; i += p) ! { ! int frameLen = vbr_lpc10_decode(codingBuffer + i, frame, decoderState, &p); ! playBuffer->resize((decodeLen + frameLen) * 2); ! ! memcpy(playBuffer->getBuffer() + decodeLen * 2, frame, frameLen * 2); ! decodeLen += frameLen; ! } ! ! logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); ! ! if(mVoiceSfx.isValid()) ! mVoiceSfx->queueBuffer(playBuffer); ! else ! mVoiceSfx = SFXObject::playRecordedBuffer(playBuffer); ! } } --- 574,583 ---- mUnusedAudio->resize(unusedCount * 2); + ByteBuffer sendBuffer(codingBuffer, len); logprintf("Encoded %d samples in %d bytes", useCount, len); ! GameType *gt = gClientGame->getGameType(); ! if(gt) ! gt->c2sVoiceChat(sendBuffer); } } Index: gameType.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameType.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** gameType.h 6 May 2004 00:33:39 -0000 1.9 --- gameType.h 7 May 2004 22:21:13 -0000 1.10 *************** *** 30,33 **** --- 30,35 ---- #include "gameObject.h" #include "timer.h" + #include "sfx.h" + #include "lpc10.h" namespace Zap *************** *** 51,54 **** --- 53,58 ---- bool wantsScoreboardUpdates; SafePtr<GameConnection> clientConnection; + RefPtr<SFXObject> voiceSFX; + lpc10_decoder_state *decoderState; U32 ping; ClientRef() { ping = 0; score = 0; } *************** *** 142,145 **** --- 146,152 ---- TNL_DECLARE_RPC(c2sRequestScoreboardUpdates, (bool updates)); + TNL_DECLARE_RPC(c2sVoiceChat, (ByteBufferRef compressedVoice)); + TNL_DECLARE_RPC(s2cVoiceChat, (StringTableEntryRef client, ByteBufferRef compressedVoice)); + TNL_DECLARE_CLASS(GameType); }; Index: sfx.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** sfx.h 7 May 2004 04:58:00 -0000 1.8 --- sfx.h 7 May 2004 22:21:13 -0000 1.9 *************** *** 88,93 **** void updateGain(); void updateMovementParams(); - SFXObject(U32 profileIndex, ByteBufferPtr samples, F32 gain, Point position, Point velocity); public: ~SFXObject(); --- 88,93 ---- void updateGain(); void updateMovementParams(); public: + SFXObject(U32 profileIndex, ByteBufferPtr samples, F32 gain, Point position, Point velocity); ~SFXObject(); Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** sfx.cpp 7 May 2004 04:58:00 -0000 1.13 --- sfx.cpp 7 May 2004 22:21:13 -0000 1.14 *************** *** 360,363 **** --- 360,365 ---- alSourceQueueBuffers(source, 1, &buffer); } + else + play(); } *************** *** 416,421 **** { // see if it's on the play list: ! S32 i; ! for(i = 0; i < gPlayList.size(); i++) if(this == gPlayList[i].getPointer()) return; --- 418,422 ---- { // see if it's on the play list: ! for(S32 i = 0; i < gPlayList.size(); i++) if(this == gPlayList[i].getPointer()) return; |
From: Ben G. <s_a...@us...> - 2004-05-07 05:21:30
|
Update of /cvsroot/opentnl/tnl/exe In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8503/exe Modified Files: ship_turbo.wav Log Message: Better turbo sound, courtesy of Nate. Index: ship_turbo.wav =================================================================== RCS file: /cvsroot/opentnl/tnl/exe/ship_turbo.wav,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 Binary files /tmp/cvs9llSYJ and /tmp/cvslrac8N differ |
From: Ben G. <s_a...@us...> - 2004-05-07 04:58:20
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5288/zap Modified Files: main.cpp sfx.cpp sfx.h Log Message: - Added -joystick command line for automatically enabling joystick device. - Added -gain # command line option to deal with gain on microphones. (Necessary for my mike to be audible.) Index: main.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** main.cpp 6 May 2004 01:55:21 -0000 1.22 --- main.cpp 7 May 2004 04:58:00 -0000 1.23 *************** *** 318,321 **** --- 318,332 ---- gMasterAddressString = argv[i+1]; } + else if(!stricmp(argv[i], "-joystick")) + { + if(hasAdditionalArg) + OptionsMenuUserInterface::joystickEnabled = true; + + } + else if(!stricmp(argv[i], "-gain")) + { + if(hasAdditionalArg) + SFXObject::setCaptureGain(atoi(argv[i+1])); + } else if(!stricmp(argv[i], "-dedicated")) { Index: sfx.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** sfx.h 7 May 2004 02:21:46 -0000 1.7 --- sfx.h 7 May 2004 04:58:00 -0000 1.8 *************** *** 75,78 **** --- 75,79 ---- static Point mListenerVelocity; static F32 mMaxDistance; + static S32 mCaptureGain; U32 mSFXIndex; *************** *** 99,102 **** --- 100,104 ---- static bool startRecording(); static void captureSamples(ByteBufferPtr sampleBuffer); + static void setCaptureGain(S32 amt); static void stopRecording(); Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** sfx.cpp 7 May 2004 02:21:46 -0000 1.12 --- sfx.cpp 7 May 2004 04:58:00 -0000 1.13 *************** *** 47,50 **** --- 47,55 ---- static U32 lastReadOffset = 0; + void SFXObject::setCaptureGain(S32 amt) + { + mCaptureGain = amt; + } + bool SFXObject::startRecording() { *************** *** 124,127 **** --- 129,137 ---- captureBuffer->Unlock(buf1, count1, buf2, count2); + // Endeavour futilely to do a gain pass + S16 *data = (S16*)buffer->getBuffer(); + for(U32 i=start/2; i<(start+sizeAdd)/2; i++) + data[i] <<= mCaptureGain; + lastReadOffset += count1 + count2; lastReadOffset %= BufferBytes; *************** *** 210,213 **** --- 220,224 ---- Point SFXObject::mListenerVelocity; F32 SFXObject::mMaxDistance = 500; + S32 SFXObject::mCaptureGain = 0; static ALuint gBuffers[NumSFXBuffers]; |
From: Mark F. <mar...@us...> - 2004-05-07 02:21:56
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16254/zap Modified Files: UIGame.cpp UIGame.h ZAP.vcproj sfx.cpp sfx.h Added Files: ftol.h lpc10.h lpc10dec.c lpc10enc.c Log Message: Added Win32 recording code to Zap SFX layer Added HawkVoice's lpc10 codec Added key bindings to voice record/encode/decode/playback Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ZAP.vcproj 4 May 2004 19:46:34 -0000 1.12 --- ZAP.vcproj 7 May 2004 02:21:46 -0000 1.13 *************** *** 34,38 **** <Tool Name="VCLinkerTool" ! AdditionalDependencies="dxguid.lib dinput8.lib dinput.lib ../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAPd.exe" LinkIncremental="2" --- 34,38 ---- <Tool Name="VCLinkerTool" ! AdditionalDependencies="dsound.lib dxguid.lib dinput8.lib dinput.lib ../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAPd.exe" LinkIncremental="2" *************** *** 84,88 **** <Tool Name="VCLinkerTool" ! AdditionalDependencies="dxguid.lib dinput8.lib dinput.lib ../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAP.exe" LinkIncremental="1" --- 84,88 ---- <Tool Name="VCLinkerTool" ! AdditionalDependencies="dsound.lib dxguid.lib dinput8.lib dinput.lib ../openal/OpenAL32.lib ../openal/alut.lib wsock32.lib ../glut/glut32.lib" OutputFile="../exe/ZAP.exe" LinkIncremental="1" *************** *** 193,196 **** --- 193,205 ---- </File> <File + RelativePath=".\lpc10.h"> + </File> + <File + RelativePath=".\lpc10dec.c"> + </File> + <File + RelativePath=".\lpc10enc.c"> + </File> + <File RelativePath=".\main.cpp"> </File> --- NEW FILE: ftol.h --- #ifdef _MSC_VER __inline int lrintf(float flt) { int intgr; _asm { fld flt fistp intgr }; return intgr ; } #else #ifdef __GNUC__ /* must define _GNU_SOURCE here or in the makefile */ #include <math.h> #else #define FP_BITS(fp) (*(int *)&(fp)) #define FIST_FLOAT_MAGIC_S (float)(7.0f * 2097152.0f) static int lrintf(float inval) { float tmp = FIST_FLOAT_MAGIC_S + inval; int res = ((FP_BITS(tmp)<<10)-0x80000000); return res>>10; } #endif #endif Index: UIGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** UIGame.cpp 4 May 2004 19:46:34 -0000 1.17 --- UIGame.cpp 7 May 2004 02:21:46 -0000 1.18 *************** *** 31,38 **** --- 31,41 ---- #include "UIMenus.h" #include "gameType.h" + #include "lpc10.h" + #include "tnlEndian.h" #include <stdarg.h> #include "glutInclude.h" #include <ctype.h> + #include <stdio.h> namespace Zap *************** *** 56,59 **** --- 59,64 ---- mVChat = new VChatHelper(); + mRecordingAudio = false; + mMaxAudioSample = 0; } *************** *** 97,100 **** --- 102,113 ---- } } + if(mRecordingAudio) + { + if(mVoiceAudioTimer.update(timeDelta)) + { + mVoiceAudioTimer.reset(VoiceAudioSampleTime); + processRecordingAudio(); + } + } } *************** *** 228,231 **** --- 241,256 ---- } + if(mRecordingAudio) + { + glColor3f(1, 1 ,1); + glBegin(GL_POLYGON); + glVertex2f(10, 600); + glVertex2f(30, 600); + F32 y = 600 - F32(mMaxAudioSample) * 600 / F32(0x7FFF); + glVertex2f(30, y); + glVertex2f(10, y); + glEnd(); + } + #if 0 // some code for outputting the position of the ship for finding good spawns *************** *** 290,293 **** --- 315,322 ---- switch(buttonIndex) { + case 0: + startRecordingAudio(); + break; + case 3: { *************** *** 316,319 **** --- 345,351 ---- switch(buttonIndex) { + case 0: + stopRecordingAudio(); + break; case 3: { *************** *** 396,399 **** --- 428,434 ---- gClientGame->zoomCommanderMap(); break; + case 'R': + startRecordingAudio(); + break; } } *************** *** 469,472 **** --- 504,510 ---- mCurrentMove.shield = !mCurrentMove.shield; break; + case 'R': + stopRecordingAudio(); + break; } } *************** *** 478,481 **** --- 516,607 ---- } + lpc10_encoder_state *encoderState = NULL; + lpc10_decoder_state *decoderState = NULL; + + void GameUserInterface::startRecordingAudio() + { + if(!mRecordingAudio) + { + encoderState = create_lpc10_encoder_state(); + init_lpc10_encoder_state(encoderState); + + decoderState = create_lpc10_decoder_state(); + init_lpc10_decoder_state(decoderState); + + mUnusedAudio = new ByteBuffer(0); + mRecordingAudio = true; + mMaxAudioSample = 0; + mVoiceAudioTimer.reset(FirstVoiceAudioSampleTime); + SFXObject::startRecording(); + } + } + + void GameUserInterface::stopRecordingAudio() + { + if(mRecordingAudio) + { + processRecordingAudio(); + destroy_lpc10_encoder_state(encoderState); + destroy_lpc10_decoder_state(decoderState); + + mRecordingAudio = false; + SFXObject::stopRecording(); + mVoiceSfx = NULL; + } + } + + void GameUserInterface::processRecordingAudio() + { + SFXObject::captureSamples(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]; + + U32 useCount = U32(sampleCount / LPC10_SAMPLES_PER_FRAME) * LPC10_SAMPLES_PER_FRAME; + //U32 useCount = sampleCount - (sampleCount % LPC10_SAMPLES_PER_FRAME); + + if(useCount) + { + U32 unusedCount = sampleCount - useCount; + + U8 codingBuffer[2048]; + U32 len = 0; + + for(U32 i = 0; i < useCount; i += LPC10_SAMPLES_PER_FRAME) + len += vbr_lpc10_encode(samplePtr + i, codingBuffer + len, encoderState); + + memcpy(mUnusedAudio->getBuffer(), mUnusedAudio->getBuffer() + useCount * 2, unusedCount * 2); + mUnusedAudio->resize(unusedCount * 2); + + logprintf("Encoded %d samples in %d bytes", useCount, len); + + S16 frame[LPC10_SAMPLES_PER_FRAME]; + int p = 0, decodeLen = 0; + ByteBufferPtr playBuffer = new ByteBuffer(0); + + for(U32 i = 0; i < len; i += p) + { + int frameLen = vbr_lpc10_decode(codingBuffer + i, frame, decoderState, &p); + playBuffer->resize((decodeLen + frameLen) * 2); + + memcpy(playBuffer->getBuffer() + decodeLen * 2, frame, frameLen * 2); + decodeLen += frameLen; + } + + logprintf("Decoded buffer size %d", playBuffer->getBufferSize()); + + if(mVoiceSfx.isValid()) + mVoiceSfx->queueBuffer(playBuffer); + else + mVoiceSfx = SFXObject::playRecordedBuffer(playBuffer); + + } + } + Move *GameUserInterface::getCurrentMove() { Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** sfx.cpp 7 May 2004 00:50:59 -0000 1.11 --- sfx.cpp 7 May 2004 02:21:46 -0000 1.12 *************** *** 29,32 **** --- 29,168 ---- #include "tnlLog.h" + #ifdef TNL_OS_WIN32 + + #include <dsound.h> + #include <stdio.h> + + namespace Zap + { + + static LPDIRECTSOUNDCAPTURE8 capture = NULL; + static LPDIRECTSOUNDCAPTUREBUFFER captureBuffer = NULL; + static bool recording = false; + + enum { + BufferBytes = 16000, + }; + + static U32 lastReadOffset = 0; + + bool SFXObject::startRecording() + { + if(recording) + return true; + + if(!capture) + { + DirectSoundCaptureCreate8(NULL, &capture, NULL); + if(!capture) + return false; + } + + if(!captureBuffer) + { + HRESULT hr; + DSCBUFFERDESC dscbd; + + // wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec, + // nBlockAlign, wBitsPerSample, cbSize + WAVEFORMATEX wfx = { WAVE_FORMAT_PCM, 1, 8000, 16000, 2, 16, 0}; + + dscbd.dwSize = sizeof(DSCBUFFERDESC); + dscbd.dwFlags = 0; + dscbd.dwBufferBytes = BufferBytes; + dscbd.dwReserved = 0; + dscbd.lpwfxFormat = &wfx; + dscbd.dwFXCount = 0; + dscbd.lpDSCFXDesc = NULL; + + if (FAILED(hr = capture->CreateCaptureBuffer(&dscbd, &captureBuffer, NULL))) + return false; + } + recording = true; + lastReadOffset = 0; + captureBuffer->Start(DSCBSTART_LOOPING); + return true; + } + + void SFXObject::captureSamples(ByteBufferPtr buffer) + { + if(!recording) + { + return; + } + else + { + DWORD capturePosition; + DWORD readPosition; + + captureBuffer->GetCurrentPosition(&capturePosition, &readPosition); + S32 byteCount = readPosition - lastReadOffset; + if(byteCount < 0) + byteCount += BufferBytes; + + void *buf1; + void *buf2; + DWORD count1; + DWORD count2; + + printf("Capturing samples... %d ... %d\n", lastReadOffset, readPosition); + + if(!byteCount) + return; + + captureBuffer->Lock(lastReadOffset, byteCount, &buf1, &count1, &buf2, &count2, 0); + + U32 sizeAdd = count1 + count2; + U32 start = buffer->getBufferSize(); + + buffer->resize(start + sizeAdd); + + memcpy(buffer->getBuffer() + start, buf1, count1); + if(count2) + memcpy(buffer->getBuffer() + start + count1, buf2, count2); + + captureBuffer->Unlock(buf1, count1, buf2, count2); + + lastReadOffset += count1 + count2; + lastReadOffset %= BufferBytes; + } + } + + void SFXObject::stopRecording() + { + if(recording) + { + recording = false; + captureBuffer->Stop(); + if(captureBuffer) + captureBuffer->Release(); + captureBuffer = NULL; + } + } + + }; + + #else + + namespace Zap + { + + bool SFXObject::startRecording() + { + return false; + } + + void SFXObject::captureSamples(ByteBufferPtr buffer) + { + } + + void SFXObject::stopRecording() + { + } + + }; + + #endif + #if defined (TNL_OS_WIN32) || defined (TNL_OS_LINUX) || defined (TNL_OS_MAC_OSX) *************** *** 39,42 **** --- 175,179 ---- static SFXProfile gSFXProfiles[] = { + { "phaser.wav", true, 1.0f, false, 0, 0 }, { "phaser.wav", false, 0.45f, false, 150, 600 }, { "phaser_impact.wav", false, 0.7f, false, 150, 600 }, *************** *** 69,72 **** --- 206,210 ---- static ALuint gSources[NumSources]; static bool gSourceActive[NumSources]; + static bool gQueuedBuffers[NumSources] = { false, }; Point SFXObject::mListenerPosition; Point SFXObject::mListenerVelocity; *************** *** 74,80 **** static ALuint gBuffers[NumSFXBuffers]; static Vector<SFXHandle> gPlayList; ! SFXObject::SFXObject(U32 profileIndex, F32 gain, Point position, Point velocity) { mSFXIndex = profileIndex; --- 212,220 ---- static ALuint gBuffers[NumSFXBuffers]; + static Vector<ALuint> gVoiceFreeBuffers; + static Vector<SFXHandle> gPlayList; ! SFXObject::SFXObject(U32 profileIndex, ByteBufferPtr ib, F32 gain, Point position, Point velocity) { mSFXIndex = profileIndex; *************** *** 85,93 **** mSourceIndex = -1; mPriority = 0; } RefPtr<SFXObject> SFXObject::play(U32 profileIndex, F32 gain) { ! RefPtr<SFXObject> ret = new SFXObject(profileIndex, gain, Point(), Point()); ret->play(); return ret; --- 225,234 ---- mSourceIndex = -1; mPriority = 0; + mInitialBuffer = ib; } RefPtr<SFXObject> SFXObject::play(U32 profileIndex, F32 gain) { ! RefPtr<SFXObject> ret = new SFXObject(profileIndex, NULL, gain, Point(), Point()); ret->play(); return ret; *************** *** 96,100 **** RefPtr<SFXObject> SFXObject::play(U32 profileIndex, Point position, Point velocity, F32 gain) { ! RefPtr<SFXObject> ret = new SFXObject(profileIndex, gain, position, velocity); ret->play(); return ret; --- 237,248 ---- RefPtr<SFXObject> SFXObject::play(U32 profileIndex, Point position, Point velocity, F32 gain) { ! RefPtr<SFXObject> ret = new SFXObject(profileIndex, NULL, gain, position, velocity); ! ret->play(); ! return ret; ! } ! ! RefPtr<SFXObject> SFXObject::playRecordedBuffer(ByteBufferPtr p, F32 gain) ! { ! RefPtr<SFXObject> ret = new SFXObject(0, p, gain, Point(), Point()); ret->play(); return ret; *************** *** 148,156 **** } void SFXObject::playOnSource() { ALuint source = gSources[mSourceIndex]; alSourceStop(source); ! alSourcei(source, AL_BUFFER, gBuffers[mSFXIndex]); alSourcei(source, AL_LOOPING, mProfile->isLooping); alSourcef(source, AL_REFERENCE_DISTANCE,9000); --- 296,376 ---- } + + static void unqueueBuffers(S32 sourceIndex) + { + // free up any played buffers from this source. + if(sourceIndex != -1) + { + ALint processed; + alGetSourcei(gSources[sourceIndex], AL_BUFFERS_PROCESSED, &processed); + while(processed) + { + ALuint buffer; + alSourceUnqueueBuffers(gSources[sourceIndex], 1, &buffer); + logprintf("unqueued buffer %d\n", buffer); + processed--; + + // ok, this is a lame solution - but the way OpenAL should work is... + // you should only be able to unqueue buffers that you queued - duh! + // otherwise it's a bitch to manage sources that can either be streamed + // or already loaded. + U32 i; + for(i = 0 ; i < NumSFXBuffers; i++) + if(buffer == gBuffers[i]) + break; + if(i == NumSFXBuffers) + gVoiceFreeBuffers.push_back(buffer); + } + } + } + + void SFXObject::queueBuffer(ByteBufferPtr p) + { + mInitialBuffer = p; + if(mSourceIndex != -1) + { + ALuint source = gSources[mSourceIndex]; + ALuint buffer = gVoiceFreeBuffers.first(); + gVoiceFreeBuffers.pop_front(); + + S16 max = 0; + S16 *ptr = (S16 *) p->getBuffer(); + U32 count = p->getBufferSize() / 2; + while(count--) + { + if(max < *ptr) + max = *ptr; + ptr++; + } + + logprintf("queued buffer %d - %d max %d len\n", buffer, max, mInitialBuffer->getBufferSize()); + alBufferData(buffer, AL_FORMAT_MONO16, mInitialBuffer->getBuffer(), + mInitialBuffer->getBufferSize(), 8000); + alSourceQueueBuffers(source, 1, &buffer); + } + } + void SFXObject::playOnSource() { ALuint source = gSources[mSourceIndex]; alSourceStop(source); ! unqueueBuffers(mSourceIndex); ! ! if(mInitialBuffer.isValid()) ! { ! ALuint buffer = gVoiceFreeBuffers.first(); ! gVoiceFreeBuffers.pop_front(); ! ! alBufferData(buffer, AL_FORMAT_MONO16, mInitialBuffer->getBuffer(), ! mInitialBuffer->getBufferSize(), 8000); ! alSourceQueueBuffers(source, 1, &buffer); ! gQueuedBuffers[mSourceIndex] = true; ! } ! else ! { ! alSourcei(source, AL_BUFFER, gBuffers[mSFXIndex]); ! gQueuedBuffers[mSourceIndex] = false; ! } ! alSourcei(source, AL_LOOPING, mProfile->isLooping); alSourcef(source, AL_REFERENCE_DISTANCE,9000); *************** *** 233,236 **** --- 453,459 ---- alGenBuffers(NumSFXBuffers, gBuffers); + gVoiceFreeBuffers.setSize(32); + alGenBuffers(32, gVoiceFreeBuffers.address()); + error = alGetError(); *************** *** 304,307 **** --- 527,532 ---- { SFXHandle &s = gPlayList[i]; + unqueueBuffers(s->mSourceIndex); + if(s->mSourceIndex != -1 && !gSourceActive[s->mSourceIndex]) { --- NEW FILE: lpc10.h --- /* LPC-10 voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2004 Phil Frisbie, Jr. (ph...@ha...) The VBR algorithm was contributed by Ben Appleton <app...@bi...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ #ifndef LPC10_H #define LPC10_H #ifdef __cplusplus extern "C" { #endif #define LPC10_SAMPLES_PER_FRAME 180 #define LPC10_ENCODED_FRAME_SIZE 7 /* NOTE ON FRAME SIZE The VBR codec creates encoded frame sizes of 1, 4, or 7 bytes. 1 byte, silence frames, about 356 bps 4 bytes, unvoiced frames, about 1422 bps 7 bytes, voiced frames, about 2488 bps */ /* NOTE ON DECODING A VBR STREAM The VBR decoder relies on the frame type encoded into the first byte of the frame. If you receive a stream of more than one frame appended together, there is no way for you to know how many times to call vbr_lpc10_decode() before hand. Therefore, a forth parameter has been added to vbr_lpc10_decode(), the int *p. *p returns with a value to tell you how many bytes were in the frame that was just processed. For example code, see the file decpacket.c, and look at the function vbrlpc10decode(). */ typedef struct lpc10_e_state lpc10_encoder_state; typedef struct lpc10_d_state lpc10_decoder_state; lpc10_encoder_state * create_lpc10_encoder_state (void); void init_lpc10_encoder_state (lpc10_encoder_state *st); int lpc10_encode(short *in, unsigned char *out, lpc10_encoder_state *st); int vbr_lpc10_encode(short *in, unsigned char *out, lpc10_encoder_state *st); void destroy_lpc10_encoder_state (lpc10_encoder_state *st); lpc10_decoder_state * create_lpc10_decoder_state (void); void init_lpc10_decoder_state (lpc10_decoder_state *st); int lpc10_decode(unsigned char *in, short *out, lpc10_decoder_state *st); int vbr_lpc10_decode(unsigned char *in, short *out, lpc10_decoder_state *st, int *p); void destroy_lpc10_decoder_state (lpc10_decoder_state *st); #ifdef __cplusplus } /* extern "C" */ #endif #endif /* LPC10_H */ Index: UIGame.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/UIGame.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** UIGame.h 3 May 2004 22:55:51 -0000 1.5 --- UIGame.h 7 May 2004 02:21:46 -0000 1.6 *************** *** 32,35 **** --- 32,37 ---- #include "gameConnection.h" #include "quickChat.h" + #include "timer.h" + #include "sfx.h" namespace Zap *************** *** 66,84 **** enum { ChatBlinkTime = 100, }; Mode mCurrentMode; ChatType mCurrentChatType; ! char mChatBuffer[50]; ! U32 mChatCursorPos; ! bool mChatBlink; ! U32 mChatLastBlinkTime; ! bool mInScoreboardMode; ! VChatHelper *mVChat; public: GameUserInterface(); void displayMessage(Color messageColor, const char *format, ...); void render(); --- 68,96 ---- enum { ChatBlinkTime = 100, + FirstVoiceAudioSampleTime = 250, + VoiceAudioSampleTime = 100, }; Mode mCurrentMode; ChatType mCurrentChatType; ! char mChatBuffer[50]; ! U32 mChatCursorPos; ! bool mChatBlink; ! U32 mChatLastBlinkTime; ! bool mInScoreboardMode; ! bool mRecordingAudio; ! S16 mMaxAudioSample; ! VChatHelper *mVChat; + Timer mVoiceAudioTimer; + RefPtr<SFXObject> mVoiceSfx; + ByteBufferPtr mUnusedAudio; public: GameUserInterface(); void displayMessage(Color messageColor, const char *format, ...); + void processRecordingAudio(); + void startRecordingAudio(); + void stopRecordingAudio(); void render(); --- NEW FILE: lpc10enc.c --- /* LPC-10 voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2003 Phil Frisbie, Jr. (ph...@ha...) The VBR algorithm was contributed by Ben Appleton <app...@bi...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public [...1429 lines suppressed...] for (i = 0; i < 120; i++) { st->p[i] = 0; } st->ipoint = 0; st->alphax = 0.0f; /* State used by function chanwr */ st->isync = 0; } /* free the memory */ void destroy_lpc10_encoder_state (lpc10_encoder_state *st) { if(st != NULL) { free(st); st = NULL; } } Index: sfx.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** sfx.h 5 May 2004 09:50:35 -0000 1.6 --- sfx.h 7 May 2004 02:21:46 -0000 1.7 *************** *** 31,34 **** --- 31,35 ---- #include "tnlNetBase.h" #include "point.h" + #include "tnlByteBuffer.h" using namespace TNL; *************** *** 38,41 **** --- 39,43 ---- enum SFXProfiles { + SFXVoice, SFXPhaser, SFXPhaserImpact, *************** *** 77,80 **** --- 79,83 ---- Point mPosition; Point mVelocity; + ByteBufferPtr mInitialBuffer; SFXProfile *mProfile; F32 mGain; *************** *** 84,88 **** void updateGain(); void updateMovementParams(); ! SFXObject(U32 profileIndex, F32 gain, Point position, Point velocity); public: ~SFXObject(); --- 87,91 ---- void updateGain(); void updateMovementParams(); ! SFXObject(U32 profileIndex, ByteBufferPtr samples, F32 gain, Point position, Point velocity); public: ~SFXObject(); *************** *** 92,95 **** --- 95,103 ---- void stop(); void setMovementParams(Point position, Point velocity); + void queueBuffer(ByteBufferPtr b); + + static bool startRecording(); + static void captureSamples(ByteBufferPtr sampleBuffer); + static void stopRecording(); static void setMaxDistance(F32 maxDistance); *************** *** 98,103 **** static void process(); static void setListenerParams(Point position, Point velocity); ! static RefPtr<SFXObject> play(U32 profileIndex, F32 gain = 1.0); ! static RefPtr<SFXObject> play(U32 profileIndex, Point position, Point velocity, F32 gain = 1.0); }; --- 106,112 ---- static void process(); static void setListenerParams(Point position, Point velocity); ! static RefPtr<SFXObject> play(U32 profileIndex, F32 gain = 1.0f); ! static RefPtr<SFXObject> play(U32 profileIndex, Point position, Point velocity, F32 gain = 1.0f); ! static RefPtr<SFXObject> playRecordedBuffer(ByteBufferPtr b, F32 gain = 1.0f); }; --- NEW FILE: lpc10dec.c --- /* LPC-10 voice codec, part of the HawkVoice Direct Interface (HVDI) cross platform network voice library Copyright (C) 2001-2004 Phil Frisbie, Jr. (ph...@ha...) The VBR algorithm was contributed by Ben Appleton <app...@bi...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ #ifndef MACOSX #include <malloc.h> #endif #include <stdlib.h> #include <memory.h> #ifdef _MSC_VER #pragma warning (disable:4711) /* to disable automatic inline warning */ #endif #include <math.h> #include "ftol.h" #include "lpc10.h" #define LPC10_BITS_IN_COMPRESSED_FRAME 54 #ifndef TRUE #define TRUE (1) #define FALSE (0) #endif #ifndef min #define min(a,b) ((a) <= (b) ? (a) : (b)) #define max(a,b) ((a) >= (b) ? (a) : (b)) #endif typedef struct lpc10_d_state { /* State used by function decode */ long iptold; /* initial value 60 */ /* State used by function synths */ float buf[360]; long buflen; /* initial value 180 */ /* State used by function pitsyn */ long ivoico; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ long ipito; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ float rmso; /* initial value 1.f */ float rco[10]; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ long jsamp; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ int first_pitsyn; /* initial value TRUE_ */ /* State used by function bsynz */ long ipo; float exc[166]; float exc2[166]; float lpi1; float lpi2; float lpi3; float hpi1; float hpi2; float hpi3; float rmso_bsynz; /* State used by function deemp */ float dei1; float dei2; float deo1; float deo2; float deo3; } lpc10_d_state_t; extern long lpcbits[10]; /* Table of constant values */ static long detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3, 20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36, 3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78, 100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64, 3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128, 3,3,3,3,1,3,3,3,1,3,1,1,1 }; static long rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420, 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102, 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15, 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 }; static long detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92, 96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,127 }; static float descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,.3828f }; static long deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }; static long qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 }; static long nbit[10] = { 8,8,5,5,4,4,4,4,3,2 }; static long kexc[25] = { 8,-16,26,-48,86,-162,294,-502,718,-728,184, 672,-610,-672,184,728,718,502,294,162,86,48,26,16,8 }; static void pitsyn(long *voice, long *pitch, float *rms, float *rc, long *ivuv, long *ipiti, float *rmsi, float *rci, long *nout, float *ratio, lpc10_decoder_state *st) { /* Initialized data */ float *rmso; /* Local variables */ float alrn, alro, yarc[10], prop; long i, j, vflag, jused, lsamp; long *jsamp; float slope; long *ipito; float uvpit; long ip, nl, ivoice; long *ivoico; long istart; float *rco; float xxy; /* Function Body */ ivoico = &(st->ivoico); ipito = &(st->ipito); rmso = &(st->rmso); rco = &(st->rco[0]); jsamp = &(st->jsamp); if (*rms < 1.f) { *rms = 1.f; } if (*rmso < 1.f) { *rmso = 1.f; } uvpit = 0.f; *ratio = *rms / (*rmso + 8.f); if (st->first_pitsyn) { lsamp = 0; ivoice = voice[1]; if (ivoice == 0) { *pitch = LPC10_SAMPLES_PER_FRAME / 4; } *nout = LPC10_SAMPLES_PER_FRAME / *pitch; *jsamp = LPC10_SAMPLES_PER_FRAME - *nout * *pitch; for (i = 0; i < *nout; ++i) { for (j = 0; j < 10; ++j) { rci[j + i * 10] = rc[j]; } ivuv[i] = ivoice; ipiti[i] = *pitch; rmsi[i] = *rms; } st->first_pitsyn = FALSE; } else { vflag = 0; lsamp = LPC10_SAMPLES_PER_FRAME + *jsamp; slope = (*pitch - *ipito) / (float) lsamp; *nout = 0; jused = 0; istart = 1; if (voice[0] == *ivoico && voice[1] == voice[0]) { if (voice[1] == 0) { /* SSUV - - 0 , 0 , 0 */ *pitch = LPC10_SAMPLES_PER_FRAME / 4; *ipito = *pitch; if (*ratio > 8.f) { *rmso = *rms; } } /* SSVC - - 1 , 1 , 1 */ slope = (*pitch - *ipito) / (float) lsamp; ivoice = voice[1]; } else { if (*ivoico != 1) { if (*ivoico == voice[0]) { /* UV2VC2 - - 0 , 0 , 1 */ nl = lsamp - LPC10_SAMPLES_PER_FRAME / 4; } else { /* UV2VC1 - - 0 , 1 , 1 */ nl = lsamp - LPC10_SAMPLES_PER_FRAME * 3 / 4; } ipiti[0] = nl / 2; ipiti[1] = nl - ipiti[0]; ivuv[0] = 0; ivuv[1] = 0; rmsi[0] = *rmso; rmsi[1] = *rmso; for (i = 0; i < 10; ++i) { rci[i] = rco[i]; rci[i + 10] = rco[i]; rco[i] = rc[i]; } slope = 0.f; *nout = 2; *ipito = *pitch; jused = nl; istart = nl + 1; ivoice = 1; } else { if (*ivoico != voice[0]) { lsamp = LPC10_SAMPLES_PER_FRAME / 4 + *jsamp; } else { lsamp = LPC10_SAMPLES_PER_FRAME * 3 / 4 + *jsamp; } for (i = 0; i < 10; ++i) { yarc[i] = rc[i]; rc[i] = rco[i]; } ivoice = 1; slope = 0.f; vflag = 1; } } for(;;) { for (i = istart; i <= lsamp; ++i) { if (uvpit != 0.f) { ip = lrintf(uvpit); } else { ip = lrintf(*ipito + slope * i + .5f); } if (ip <= i - jused) { ipiti[*nout] = ip; *pitch = ip; ivuv[*nout] = ivoice; jused += ip; prop = (jused - ip / 2) / (float) lsamp; for (j = 0; j < 10; ++j) { alro = (float)log((rco[j] + 1) / (1 - rco[j])); alrn = (float)log((rc[j] + 1) / (1 - rc[j])); xxy = alro + prop * (alrn - alro); xxy = (float)exp(xxy); rci[j + *nout * 10] = (xxy - 1) / (xxy + 1); } rmsi[*nout] = (float)(log(*rmso) + prop * (log(*rms) - log(*rmso))); rmsi[*nout] = (float)exp(rmsi[*nout]); ++(*nout); } } if (vflag != 1) { break; } vflag = 0; istart = jused + 1; lsamp = LPC10_SAMPLES_PER_FRAME + *jsamp; slope = 0.f; ivoice = 0; uvpit = (float) ((lsamp - istart) / 2); if (uvpit > 90.f) { uvpit /= 2; } *rmso = *rms; for (i = 1; i <= 10; ++i) { rco[i - 1] = rc[i - 1] = yarc[i - 1]; } } *jsamp = lsamp - jused; } if (*nout != 0) { *ivoico = voice[1]; *ipito = *pitch; *rmso = *rms; for (i = 0; i < 10; ++i) { rco[i] = rc[i]; } } } /* pitsyn_ */ #define MIDTAP 1 #define MAXTAP 4 static short y[MAXTAP+1]={-21161, -8478, 30892,-10216, 16950}; static int j=MIDTAP, k=MAXTAP; static int random16 (void) { int the_random; /* The following is a 16 bit 2's complement addition, * with overflow checking disabled */ y[k] = (short)(y[k] + y[j]); the_random = y[k]; k--; if (k < 0) k = MAXTAP; j--; if (j < 0) j = MAXTAP; return(the_random); } static void bsynz(float *coef, long ip, long *iv, float *sout, float *rms, float *ratio, float *g2pass, lpc10_decoder_state *st) { /* Initialized data */ long *ipo; float *rmso; float *exc; float *exc2; float lpi1; float lpi2; float hpi1; float hpi2; /* Local variables */ float gain, xssq; long i, j, k; float pulse; long px; float sscale; float xy, sum, ssq; float lpi0, hpi0; /* Parameter adjustments */ if (coef) { --coef; } /* Function Body */ ipo = &(st->ipo); exc = &(st->exc[0]); exc2 = &(st->exc2[0]); lpi1 = st->lpi1; lpi2 = st->lpi2; hpi1 = st->hpi1; hpi2 = st->hpi2; rmso = &(st->rmso_bsynz); /* MAXPIT+MAXORD=166 */ /* Calculate history scale factor XY and scale filter state */ /* Computing MIN */ xy = min((*rmso / (*rms + 1e-6f)),8.f); *rmso = *rms; for (i = 0; i < 10; ++i) { exc2[i] = exc2[*ipo + i] * xy; } *ipo = ip; if (*iv == 0) { /* Generate white noise for unvoiced */ for (i = 0; i < ip; ++i) { exc[10 + i] = (float) (random16() >> 6); } px = ((random16() + 32768) * (ip - 1) >> 16) + 10 + 1; pulse = *ratio * 85.5f; if (pulse > 2e3f) { pulse = 2e3f; } exc[px - 1] += pulse; exc[px] -= pulse; /* Load voiced excitation */ } else { sscale = (float)sqrt((float) (ip)) * 0.144341801f; for (i = 0; i < ip; ++i) { float temp; if (i > 27) { temp = 0.f; } else if (i < 25) { lpi0 = temp = sscale * kexc[i]; temp = lpi0 * .125f + lpi1 * .75f + lpi2 * .125f; lpi2 = lpi1; lpi1 = lpi0; } else{ lpi0 = temp = 0.f; temp = lpi1 * .75f + lpi2 * .125f; lpi2 = lpi1; lpi1 = lpi0; } hpi0 = (float)(random16() >> 6); exc[10 + i] = temp + hpi0 * -.125f + hpi1 * .25f + hpi2 * -.125f; hpi2 = hpi1; hpi1 = hpi0; } } /* Synthesis filters: */ /* Modify the excitation with all-zero filter 1 + G*SUM */ xssq = 0.f; for (i = 0; i < ip; ++i) { k = 10 + i; sum = 0.f; for (j = 1; j <= 10; ++j) { sum += coef[j] * exc[k - j]; } sum *= *g2pass; exc2[k] = sum + exc[k]; } /* Synthesize using the all pole filter 1 / (1 - SUM) */ for (i = 0; i < ip; ++i) { k = 10 + i; sum = 0.f; for (j = 1; j <= 10; ++j) { sum += coef[j] * exc2[k - j]; } exc2[k] += sum; xssq += exc2[k] * exc2[k]; } /* Save filter history for next epoch */ for (i = 0; i < 10; ++i) { exc[i] = exc[ip + i]; exc2[i] = exc2[ip + i]; } /* Apply gain to match RMS */ ssq = *rms * *rms * ip; gain = (float)sqrt(ssq / xssq); for (i = 0; i < ip; ++i) { sout[i] = gain * exc2[10 + i]; } st->lpi1 = lpi1; st->lpi2 = lpi2; st->hpi1 = hpi1; st->hpi2 = hpi2; } /* bsynz_ */ static void irc2pc(float *rc, float *pc, float gprime, float *g2pass) { /* System generated locals */ long i2; /* Local variables */ float temp[10]; long i, j; /* Parameter adjustments */ --pc; --rc; /* Function Body */ *g2pass = 1.f; for (i = 1; i <= 10; ++i) { *g2pass *= 1.f - rc[i] * rc[i]; } *g2pass = gprime * (float)sqrt(*g2pass); pc[1] = rc[1]; for (i = 2; i <= 10; ++i) { i2 = i - 1; for (j = 1; j <= i2; ++j) { temp[j - 1] = pc[j] - rc[i] * pc[i - j]; } i2 = i - 1; for (j = 1; j <= i2; ++j) { pc[j] = temp[j - 1]; } pc[i] = rc[i]; } } /* irc2pc_ */ static void deemp(float *x, long n, lpc10_decoder_state *st) { /* Initialized data */ float dei1; float dei2; float deo1; float deo2; float deo3; /* Local variables */ long k; float dei0; /* Function Body */ dei1 = st->dei1; dei2 = st->dei2; deo1 = st->deo1; deo2 = st->deo2; deo3 = st->deo3; for (k = 0; k < n; ++k) { dei0 = x[k]; x[k] = dei0 - dei1 * 1.9998f + dei2 + deo1 * 2.5f - deo2 * 2.0925f + deo3 * .585f; dei2 = dei1; dei1 = dei0; deo3 = deo2; deo2 = deo1; deo1 = x[k]; } st->dei1 = dei1; st->dei2 = dei2; st->deo1 = deo1; st->deo2 = deo2; st->deo3 = deo3; } /* deemp_ */ static void synths(long *voice, long pitch, float rms, float *rc, short *speech, lpc10_decoder_state *st) { /* Initialized data */ float *buf; long *buflen; /* Local variables */ float rmsi[16]; long nout, ivuv[16], i, j; float ratio; long ipiti[16]; float g2pass; float pc[10]; float rci[160] /* was [10][16] */; /* Function Body */ buf = &(st->buf[0]); buflen = &(st->buflen); pitch = max(min(pitch,156), 20); for (i = 0; i < 10; ++i) { rc[i] = max(min(rc[i],.99f), -.99f); } pitsyn(voice, &pitch, &rms, rc, ivuv, ipiti, rmsi, rci, &nout, &ratio, st); if (nout > 0) { for (j = 0; j < nout; ++j) { irc2pc(&rci[j * 10], pc, 0.7f, &g2pass); bsynz(pc, ipiti[j], &ivuv[j], &buf[*buflen], &rmsi[j], &ratio, &g2pass, st); deemp(&buf[*buflen], ipiti[j], st); *buflen += ipiti[j]; } for (i = 0; i < LPC10_SAMPLES_PER_FRAME; ++i) { speech[i] = (short) max(-32768, min(lrintf(8.0f * buf[i]), 32767)); } *buflen -= LPC10_SAMPLES_PER_FRAME; for (i = 0; i < *buflen; ++i) { buf[i] = buf[i + LPC10_SAMPLES_PER_FRAME]; } } } /* synths_ */ static void decode(long ipitv, long irms, long *irc, long *voice, long *pitch, float *rms, float *rc, lpc10_decoder_state *st) { /* Local variables */ long i, i1, i2, i4; long ishift; /* Function Body */ i4 = detau[ipitv]; voice[0] = 1; voice[1] = 1; if (ipitv <= 1) { voice[0] = 0; } if (ipitv == 0 || ipitv == 2) { voice[1] = 0; } *pitch = i4; if (*pitch <= 4) { *pitch = st->iptold; } if (voice[0] == 1 && voice[1] == 1) { st->iptold = *pitch; } if (voice[0] != voice[1]) { *pitch = st->iptold; } /* Decode RMS */ irms = rmst[(31 - irms) * 2]; /* Decode RC(1) and RC(2) from log-area-ratios */ /* Protect from illegal coded value (-16) caused by bit errors */ for (i = 0; i < 2; ++i) { i2 = irc[i]; i1 = 0; if (i2 < 0) { i1 = 1; i2 = -i2; if (i2 > 15) { i2 = 0; } } i2 = detab7[i2 * 2]; if (i1 == 1) { i2 = -i2; } ishift = 15 - nbit[i]; irc[i] = i2 * (2 << (ishift-1)); } /* Decode RC(3)-RC(10) to sign plus 14 bits */ for (i = 2; i < 10; ++i) { i2 = irc[i]; ishift = 15 - nbit[i]; i2 *= (2 << (ishift-1)); i2 += qb[i - 2]; irc[i] = (int)(i2 * descl[i - 2] + deadd[i - 2]); } /* Scale RMS and RC's to floats */ *rms = (float) (irms); for (i = 0; i < 10; ++i) { rc[i] = irc[i] / 16384.f; } } /* decode_ */ static void unpack(long *array, long bits, long *value, long *pointer) { int i; for (i = 0, *value = 0; i < bits; i++, (*pointer)++) *value |= array[*pointer] << i; } static void chanrd(long *ipitv, long *irms, long *irc, long *ibits, int *p, int vbr) { static long bit[] = {0, 1, 2, 4, 8, 16, 32, 64, 128}; long pointer, i; pointer = 0; unpack(ibits, 7, ipitv, &pointer); if(vbr == TRUE) { /* check for silence packet */ if (*ipitv == 127) { *ipitv = 0; *irms = 0; *p = 1; return; } } unpack(ibits, 5, irms, &pointer); *p = 4; for (i = 0; i < 4; ++i) { unpack(ibits, lpcbits[i], &irc[i], &pointer); } if ((*ipitv != 0 && *ipitv != 126) || vbr == FALSE) { *p = 7; for (i = 4; i < 10; ++i) { unpack(ibits, lpcbits[i], &irc[i], &pointer); } } /* Sign extend RC's */ for (i = 0; i < 10; ++i) { if ((irc[i] & bit[lpcbits[i]]) != 0) { irc[i] -= bit[lpcbits[i]] << 1; } } } static int lpc10_decode_int(unsigned char *in, short *speech, lpc10_decoder_state *st, int *p, int vbr) { long bits[LPC10_BITS_IN_COMPRESSED_FRAME]; int i; long irms, voice[2], pitch, ipitv; float rc[10]; long irc[10]; float rms; /* unpack bits into array */ for (i = 0; i < LPC10_BITS_IN_COMPRESSED_FRAME; i++) { bits[i] = (in[i >> 3] & (1 << (i & 7))) != 0 ? 1 : 0; } /* decode speech */ memset(irc, 0, sizeof(irc)); chanrd(&ipitv, &irms, irc, bits, p, vbr); decode(ipitv, irms, irc, voice, &pitch, &rms, rc, st); synths(voice, pitch, rms, rc, speech, st); return LPC10_SAMPLES_PER_FRAME; } int lpc10_decode(unsigned char *in, short *speech, lpc10_decoder_state *st) { int p = 0; return lpc10_decode_int(in, speech, st, &p, FALSE); } int vbr_lpc10_decode(unsigned char *in, short *speech, lpc10_decoder_state *st, int *p) { return lpc10_decode_int(in, speech, st, p, TRUE); } /* Allocate memory for, and initialize, the state that needs to be kept from decoding one frame to the next for a single LPC-10-compressed audio stream. Return 0 if malloc fails, otherwise return pointer to new structure. */ lpc10_decoder_state *create_lpc10_decoder_state(void) { lpc10_decoder_state *st; st = (lpc10_decoder_state *)malloc((unsigned) sizeof (lpc10_decoder_state)); return (st); } void init_lpc10_decoder_state(lpc10_decoder_state *st) { int i; /* State used by function decode */ st->iptold = 60; /* State used by function synths */ for (i = 0; i < 360; i++) { st->buf[i] = 0.0f; } st->buflen = 180; /* State used by function pitsyn */ st->rmso = 1.0f; st->first_pitsyn = TRUE; /* State used by function bsynz */ st->ipo = 0; for (i = 0; i < 166; i++) { st->exc[i] = 0.0f; st->exc2[i] = 0.0f; } st->lpi1 = 0.0f; st->lpi2 = 0.0f; st->lpi3 = 0.0f; st->hpi1 = 0.0f; st->hpi2 = 0.0f; st->hpi3 = 0.0f; st->rmso_bsynz = 0.0f; /* State used by function deemp */ st->dei1 = 0.0f; st->dei2 = 0.0f; st->deo1 = 0.0f; st->deo2 = 0.0f; st->deo3 = 0.0f; } void destroy_lpc10_decoder_state (lpc10_decoder_state *st) { if(st != NULL) { free(st); st = NULL; } } |
From: Mark F. <mar...@us...> - 2004-05-07 02:21:55
|
Update of /cvsroot/opentnl/tnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16254/tnl Modified Files: tnlEndian.h Log Message: Added Win32 recording code to Zap SFX layer Added HawkVoice's lpc10 codec Added key bindings to voice record/encode/decode/playback Index: tnlEndian.h =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnlEndian.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tnlEndian.h 20 Apr 2004 04:27:18 -0000 1.1 --- tnlEndian.h 7 May 2004 02:21:45 -0000 1.2 *************** *** 98,102 **** inline S16 convertBEndianToHost(S16 i) { ! return S16(convertBEndianToHost(S16(i))); } --- 98,102 ---- inline S16 convertBEndianToHost(S16 i) { ! return S16(convertBEndianToHost(U16(i))); } |
From: Mark F. <mar...@us...> - 2004-05-07 02:21:53
|
Update of /cvsroot/opentnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16254 Modified Files: tnl.sln Log Message: Added Win32 recording code to Zap SFX layer Added HawkVoice's lpc10 codec Added key bindings to voice record/encode/decode/playback Index: tnl.sln =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl.sln,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tnl.sln 24 Apr 2004 23:52:32 -0000 1.3 --- tnl.sln 7 May 2004 02:21:44 -0000 1.4 *************** *** 61,69 **** {5FAF4911-1DA7-44FE-9DA1-49AE25B11250}.Release Xbox.Build.0 = Release|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug.ActiveCfg = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug Win32.ActiveCfg = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug Xbox.ActiveCfg = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug Xbox.Build.0 = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release.ActiveCfg = Release|Win32 - {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release.Build.0 = Release|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release Win32.ActiveCfg = Release|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release Win32.Build.0 = Release|Win32 --- 61,69 ---- {5FAF4911-1DA7-44FE-9DA1-49AE25B11250}.Release Xbox.Build.0 = Release|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug.ActiveCfg = Debug|Win32 + {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug.Build.0 = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug Win32.ActiveCfg = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug Xbox.ActiveCfg = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Debug Xbox.Build.0 = Debug|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release.ActiveCfg = Release|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release Win32.ActiveCfg = Release|Win32 {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release Win32.Build.0 = Release|Win32 *************** *** 71,79 **** {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release Xbox.Build.0 = Release|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug.ActiveCfg = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug Win32.ActiveCfg = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug Xbox.ActiveCfg = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug Xbox.Build.0 = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release.ActiveCfg = Release|Win32 - {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release.Build.0 = Release|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release Win32.ActiveCfg = Release|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release Win32.Build.0 = Release|Win32 --- 71,79 ---- {2BF337F1-B812-4324-A9BA-E4D580C8CFF1}.Release Xbox.Build.0 = Release|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug.ActiveCfg = Debug|Win32 + {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug.Build.0 = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug Win32.ActiveCfg = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug Xbox.ActiveCfg = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Debug Xbox.Build.0 = Debug|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release.ActiveCfg = Release|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release Win32.ActiveCfg = Release|Win32 {2BC8A06B-B9E6-4C92-9E10-6B5E37CBFF96}.Release Win32.Build.0 = Release|Win32 *************** *** 92,100 **** {3F7F7B79-4473-4CAB-A54E-4274A9F1A01A}.Release Xbox.Build.0 = Release|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug.ActiveCfg = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug Win32.ActiveCfg = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug Xbox.ActiveCfg = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug Xbox.Build.0 = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release.ActiveCfg = Release|Win32 - {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release.Build.0 = Release|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release Win32.ActiveCfg = Release|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release Win32.Build.0 = Release|Win32 --- 92,100 ---- {3F7F7B79-4473-4CAB-A54E-4274A9F1A01A}.Release Xbox.Build.0 = Release|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug.ActiveCfg = Debug|Win32 + {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug.Build.0 = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug Win32.ActiveCfg = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug Xbox.ActiveCfg = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Debug Xbox.Build.0 = Debug|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release.ActiveCfg = Release|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release Win32.ActiveCfg = Release|Win32 {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release Win32.Build.0 = Release|Win32 *************** *** 102,110 **** {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release Xbox.Build.0 = Release|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug.ActiveCfg = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug Win32.ActiveCfg = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug Xbox.ActiveCfg = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug Xbox.Build.0 = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release.ActiveCfg = Release|Win32 - {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release.Build.0 = Release|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release Win32.ActiveCfg = Release|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release Win32.Build.0 = Release|Win32 --- 102,110 ---- {CE4F0113-8119-491D-BCBE-20F5C3A555FC}.Release Xbox.Build.0 = Release|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug.ActiveCfg = Debug|Win32 + {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug.Build.0 = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug Win32.ActiveCfg = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug Xbox.ActiveCfg = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Debug Xbox.Build.0 = Debug|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release.ActiveCfg = Release|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release Win32.ActiveCfg = Release|Win32 {F931A5FA-FF37-4977-8493-786AFD5D71EC}.Release Win32.Build.0 = Release|Win32 |