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;
|