|
Hi!
Could you tell me how to buid a project using client/server.
i want write a simple server, and client
when a client connect to server (only connect)the server
print a message to other client
but i can't write it in java,
could you teach me.
Thank you
|
|
|
|
|
i have a problem in your voice chat program i want to change the pcm waveform to adpcm and i don't know how to add this code to your program.
Please teach my how to add this code for your project thank you for your kindness .
-------------------------------------------------------------------------
#include "adpcm.h"
#include <stdio.h> /*DBG*/
#ifndef __STDC__
#define signed
#endif
/* Intel ADPCM step variation table */
static int indexTable[16] = {
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8,
};
static int stepsizeTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
void
adpcm_coder(indata, outdata, len, state)
short indata[];
char outdata[];
int len;
struct adpcm_state *state;
{
short *inp; /* Input buffer pointer */
signed char *outp; /* output buffer pointer */
int val; /* Current input sample value */
int sign; /* Current adpcm sign bit */
int delta; /* Current adpcm output value */
int diff; /* Difference between val and valprev */
int step; /* Stepsize */
int valpred; /* Predicted output value */
int vpdiff; /* Current change to valpred */
int index; /* Current step change index */
int outputbuffer; /* place to keep previous 4-bit value */
int bufferstep; /* toggle between outputbuffer/output */
outp = (signed char *)outdata;
inp = indata;
valpred = state->valprev;
index = state->index;
step = stepsizeTable[index];
bufferstep = 1;
for ( ; len > 0 ; len-- ) {
val = *inp++;
/* Step 1 - compute difference with previous value */
diff = val - valpred;
sign = (diff < 0) ? 8 : 0;
if ( sign ) diff = (-diff);
/* Step 2 - Divide and clamp */
/* Note:
** This code *approximately* computes:
** delta = diff*4/step;
** vpdiff = (delta+0.5)*step/4;
** but in shift step bits are dropped. The net result of this is
** that even if you have fast mul/div hardware you cannot put it to
** good use since the fixup would be too expensive.
*/
delta = 0;
vpdiff = (step >> 3);
if ( diff >= step ) {
delta = 4;
diff -= step;
vpdiff += step;
}
step >>= 1;
if ( diff >= step ) {
delta |= 2;
diff -= step;
vpdiff += step;
}
step >>= 1;
if ( diff >= step ) {
delta |= 1;
vpdiff += step;
}
/* Step 3 - Update previous value */
if ( sign )
valpred -= vpdiff;
else
valpred += vpdiff;
/* Step 4 - Clamp previous value to 16 bits */
if ( valpred > 32767 )
valpred = 32767;
else if ( valpred < -32768 )
valpred = -32768;
/* Step 5 - Assemble value, update index and step values */
delta |= sign;
index += indexTable[delta];
if ( index < 0 ) index = 0;
if ( index > 88 ) index = 88;
step = stepsizeTable[index];
/* Step 6 - Output value */
if ( bufferstep ) {
outputbuffer = (delta << 4) & 0xf0;
} else {
*outp++ = (delta & 0x0f) | outputbuffer;
}
bufferstep = !bufferstep;
}
/* Output last step, if needed */
if ( !bufferstep )
*outp++ = outputbuffer;
state->valprev = valpred;
state->index = index;
}
void
adpcm_decoder(indata, outdata, len, state)
char indata[];
short outdata[];
int len;
struct adpcm_state *state;
{
signed char *inp; /* Input buffer pointer */
short *outp; /* output buffer pointer */
int sign; /* Current adpcm sign bit */
int delta; /* Current adpcm output value */
int step; /* Stepsize */
int valpred; /* Predicted value */
int vpdiff; /* Current change to valpred */
int index; /* Current step change index */
int inputbuffer; /* place to keep next 4-bit value */
int bufferstep; /* toggle between inputbuffer/input */
outp = outdata;
inp = (signed char *)indata;
valpred = state->valprev;
index = state->index;
step = stepsizeTable[index];
bufferstep = 0;
for ( ; len > 0 ; len-- ) {
/* Step 1 - get the delta value */
if ( bufferstep ) {
delta = inputbuffer & 0xf;
} else {
inputbuffer = *inp++;
delta = (inputbuffer >> 4) & 0xf;
}
bufferstep = !bufferstep;
/* Step 2 - Find new index value (for later) */
index += indexTable[delta];
if ( index < 0 ) index = 0;
if ( index > 88 ) index = 88;
/* Step 3 - Separate sign and magnitude */
sign = delta & 8;
delta = delta & 7;
/* Step 4 - Compute difference and new predicted value */
/*
** Computes 'vpdiff = (delta+0.5)*step/4', but see comment
** in adpcm_coder.
*/
vpdiff = step >> 3;
if ( delta & 4 ) vpdiff += step;
if ( delta & 2 ) vpdiff += step>>1;
if ( delta & 1 ) vpdiff += step>>2;
if ( sign )
valpred -= vpdiff;
else
valpred += vpdiff;
/* Step 5 - clamp output value */
if ( valpred > 32767 )
valpred = 32767;
else if ( valpred < -32768 )
valpred = -32768;
/* Step 6 - Update step value */
step = stepsizeTable[index];
/* Step 7 - Output value */
*outp++ = valpred;
}
state->valprev = valpred;
state->index = index;
}
---------------------------------------------------------------------------
|
|
|
|
|
Anyone knows where to get sample codes that uses JMF
|
|
|
|
|
hi..
Presently i am playing with jmf ....with audio and video.
I have developed some sample codes for audio /video
However you can get lot of codes on the internet
java.sun.com/products/java-media/jmf/
www.mindspring.com/~lindend/corejmf
www.javaworld.com/javaworld/jw-04-1997/jw-04-jmf.html
www.blackdown.org/java-linux/jdk1.2-status/ jmf-status.html
hope you can find good examples on these sites...
bye
|
|
|
|
|
hi there... thanks alot for replying... and yeah ur urls are quite helpful.. i found some good examples... for now i think should be enough of information.. sooner or later i think i will have problems in compressing audio and tranfering them.. anyway when time comes. i will be back to ask for help from experts in this forum
thank you very much again
|
|
|
|
|
Just visit and download source code
http://javasolution.blogspot.com/2007/04/simple-application-for-voice.html
http://javasolution.blogspot.com/2007/04/voice-chat-using-java.html
|
|
|
|
|
hello nsry ( may i know ur name ?)
i am trying to convert ur PCM stream in mp3 format . How can i do it ? . U have said GSM compression is possible but i want to convert the (2000 bytes of)sound packet inmmediately into mp3 then pass it on to the server . and in the client side i want to reverse engineer the received mp3 data into PCM so that it can be played by the speaker .
Could u hlep me plz?
dharani
|
|
|
|
|
Hi NSRY After i download your program and use it in my project. I want to fix some ability in your program e.g : add compress sound like pcm adpcm
Can u advice me for something? Thank you.
And last one i want to add more buffer. How?
Wait for your answer
|
|
|
|
|
Hi..
You can compression issues by changing the wave format details during initialization of WAVEFORMATEX structure. GSM format also supported. But some systems don't support this formats.Look in msdn for more details..
If your drivers support then you can use it.
You can change the buffer size by changing the PreCreatBuffer() function in both RecordSound and PlaySound class.(for playsound PreCreateBuffer() is present in the Display class)
from
Nagareshwar (nsry - codename)
|
|
|
|
|
Thank You for your advice and i 'going to chang buffer size.
and maybe in the next time i may beg you to give me some advice.
Thank You Very Much.
|
|
|
|
|
This code's a good beginning for people. I haven't seen sample code that does this posted anywhere before. Thanks.
There are a couple of bugs:
1. Typecast problems (easy to fix), and in mysocket.h, setparent returns an int but really doesn't.
2. Your use of mixer devices won't work on a lot of PCs. There are solutions out there that don't have muxes or mixers, so you have to brute-force look for the mute button and volume control IDs. I've seen sample code posted somewhere on how to do this. I just forget where....
3. If the connection to localhost (server) is blocked (lets say with ZoneAlarm), the latest instance of Internet Explorer hangs for a long long time before it gets restarted. This is an interesting bug.
4. You use WAVEOUTCAPS before filling. Maybe you need to add something like this to PlaySound1::GetDevProperty()
void PlaySound1::GetDevProperty()
{
CString format;
WAVEOUTCAPS wavecap;
MMRESULT mmReturn = 0;
int numdevs;
numdevs = waveOutGetNumDevs();
if (NULL != numdevs - 1)
{
//there's more than one wave out device, you need to add code
//here to let a user select which one he wants to play.
//for example, you may have an audio out card with no speakers
//attached, but a USB speaker set plugged in and being used.
}
mmReturn = ::waveOutOpen( &m_hPlay, WAVE_MAPPER,
&m_WaveFormatEx, ::GetCurrentThreadId(), 0, CALLBACK_THREAD);
mmReturn = waveOutGetDevCaps(numdevs - 1, &wavecap, sizeof(WAVEOUTCAPS));
mmReturn = waveOutClose(m_hPlay); //safest if there's multiple waveout devices
int propno[]= {
etc etc
and in PlaySound1::PlaySound1(CDialog *dialog) move
GetDevProperty();
to after the WAVEFORMATEX structure is initialized.
Thanks for posting it. Jim
|
|
|
|
|
How would one fix the typecast problems? - I guess they're not _so_ easy to fix.
-Jesse
|
|
|
|
|
yes - how would you fix the typecast issues?
|
|
|
|
|
hello angreswar
U have really helped me to make my dream come true ..ur project helped me right in time ..carry on..as others said the way u have handled the buffer is excellent ..bye
dharani
|
|
|
|
|
hi,I'd like to know how to support a microphone in C#?
Can you help me?
|
|
|
|
|
Hello,
A great project! I wanna know, from your server coding, i see there is a checking if the received buffer size exceeding 2020 or not. Why ? Is there a case that the buffer size will be too large ? What's the cases ? What problem you met while u do the project ?
I did the same kind of project as you in fact, but with enchanced feature that the voice data will be compressed. However, problem arises. The voice data in this way will be too small and fast to be sent to the server, according to the TCP mechanism, data sent in this way will be merged together due to Nagle algorithm present in default. Do u meet this kind of problem ? I solved it by disable the Nagle Algorithm, However, it arises again while added firewall support (surely the firewall haven't disable the Nagle).
Since I see you didn't disable Nagle and your data is not small in fact (2000 bytes per sound packet). But the overall performance work very well. Why you buffer up to 2000 and send ? Is that you tested many times ?
Anyway, Thx for your reading.
Best regards,
BB
|
|
|
|
|
Hi...
I have not used any compression ...I tried to use GSM compression ..but some audio cards doesnot support...
2000 buffer size is w.r.t the wave format that i have used.
To get good quality buffer size should be compatible with the wave format...
I am hearing the word Nagle First time...I have no idea..
Thanks...
from
Nagareshwar (nsry)
|
|
|
|
|
I've tried to launch 2 clients on a same PC. It causes an GPF error.
Very interesting however, thanks for sharing your code.
Best regards.
Always look on the bright side of life.
|
|
|
|
|
Copy the exe of the application into different folder and run...the problem is due to the log files created during exectution....
From
nagareshwar(nsry)
|
|
|
|
|
Hi,
That's OK, I'll test it soon.
Thanks for your quick answer.
Best regards
Always look on the bright side of life.
|
|
|
|
|
It is a great article! It works fine in my local network!
But it doesn't work through the internet, I can connect to other clients, but I hear Nothing! any comment?
Thanx!
|
|
|
|
|
I have not tested in the internet....But it has to work....
I will try here ...
From
nagareshwar(nsry)
|
|
|
|
|
oh,wonderful!
Hello Every One
|
|
|
|
|
It is because one of the client is behind firewall or private network while other client is in public network(Internet).
Regards,
Kent Tham
thamyk@inovas.com
|
|
|
|
|
Really Nice Article Sir!!!!.
Thanks,Atleast i understand working of UI thread.
Thanks Once Again
"I Think this Will Help"
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|