Send Audio Data over the network using socket in c++ -
can body tell me how can packet audio data , send client client can play audio has been received ? how program start recording audio microphone:
{ waveoutreset (hwaveout) ; waveinreset (hwavein) ; pbuffer1=reinterpret_cast <pbyte> (malloc(inp_buffer_size) ); pbuffer2= reinterpret_cast <pbyte> ( malloc(inp_buffer_size) ); if (!pbuffer1 || !pbuffer2) { if (pbuffer1) free (pbuffer1); if (pbuffer2) free (pbuffer2); messagebox (hwnd, szmemerror, null, mb_iconexclamation|mb_ok) ; return true ; } // open waveform audio input waveform.wformattag = wave_format_pcm ; waveform.nchannels = 1; waveform.nsamplespersec = 11025 ; waveform.navgbytespersec = 11025 ; waveform.nblockalign = 1 ; waveform.wbitspersample = 8 ; waveform.cbsize = 0 ; if (waveinopen (&hwavein, wave_mapper, &waveform, (dword) hwnd, 0, callback_window)) { free (pbuffer1) ; free (pbuffer2) ; } // set headers , prepare them pwavehdr1->lpdata = reinterpret_cast <char*>( pbuffer1 ) ; pwavehdr1->dwbufferlength = inp_buffer_size ; pwavehdr1->dwbytesrecorded = 0 ; pwavehdr1->dwuser = 0 ; pwavehdr1->dwflags = 0 ; pwavehdr1->dwloops = 1 ; pwavehdr1->lpnext = null ; pwavehdr1->reserved = 0 ; waveinprepareheader (hwavein, pwavehdr1, sizeof (wavehdr)) ; pwavehdr2->lpdata = reinterpret_cast <char*>(pbuffer2 ) ; pwavehdr2->dwbufferlength = inp_buffer_size ; pwavehdr2->dwbytesrecorded = 0 ; pwavehdr2->dwuser = 0 ; pwavehdr2->dwflags = 0 ; pwavehdr2->dwloops = 1 ; pwavehdr2->lpnext = null ; pwavehdr2->reserved = 0 ; waveinprepareheader (hwavein, pwavehdr2, sizeof(wavehdr)); } break;
and socket version accept, receive , send data:
switch(wsagetselectevent(lparam)) { case fd_accept: if((new_socket = accept(wparam, null, null)) == -1){ messagebox(null, l"error while accepting connection", l"error", mb_ok); break; } // prepare accepted socket read, write, , close notification if(wsaasyncselect(new_socket,hwnd, wm_socket,fd_read|fd_write|fd_close) == -1){ messagebox(null, l"error while intialization", l"error", mb_ok); break; } break; case fd_read: // receive data socket in wparam break; case fd_write: // socket in wparam ready sending data break; case fd_close: // connection closed closesocket((socket)wparam); break; }
the problem can't pack audio data send client , how client going unpack again , play audio
all replies appreciated thanks
you're learning c++, , trying take many steps @ once. try recording file, , playing file. give sound-to-bytes , bytes-to-sound parts. don't try use specific file format, write , read raw audio data.
Comments
Post a Comment