Introduction: Ethernet Voice Streaming

About: I am SoC engineer of Korea. I developed several comunication SoCs. Now I'm very interesting in IoT with ethernet. and Open Hardware platform.

Hi

Today I will introduce a project which I made.

It is "Ethernet voice streaming"

It will send anyone's voice to where ever internet enabled area as real time.

With this project, you can listen your honey voice everyday with free if you have internet.

Most of all, this system is very simple. So you can make it with low price.

Are you interresting in?

Just follow it next every steps.

Step 1: Prepare Meterials

For this project we need few meterials.

1. WIZwiki-W7500 : 2ea (One will trasmit voice, the other will receive voice)

This is one of Open Sourced Hardware platform(mbed). especailly it have hardware ethernet function.
https://developer.mbed.org/platforms/WIZwiki-W7500...

2. Microphone

https://developer.mbed.org/components/Electret-Microphone-Amplifier-MAX9814/

3. Speaker

Any Speaker is okay. You can listen.

4. R C

For RC low pass filter (R : 2.7Kohm / C : 0.01uF)

And last

Visit https://developer.mbed.org/ and join then you can use mbed web compiler.

How about these meterials.

It is very simple as I let you know in first step.

Step 2: Hardware Connection

As you see meterials before.

Of course hardware connection is simple.

For transmition device it need a microphone.

And it need a speaker and RC filter for receive device.

That is all for hardware connection.

See the picture for detail, you can know how to connection very clearly.

Step 3: Analog Out for Speaker (PWM DAC, RC Filter)

There is no analog out IP in WIZwiki-W7500.

(Most of mcu don't have DAC ip also include Arduino.)

But we can generate analog out from PWM out operation.

Below article is part of already existed instructable which is creating a read DAC.

Creating a real DAC
Fortunately, it is easy to convert a PWM output to an analog voltage level, producing a true DAC. All that is needed is a simple low-pass filter made from a resistor and a ceramic capacitor. The simple RC low-pass filter shown in the third photo converts the PWM signal to a voltage proportional to the duty cycle. For the Arduino, an R value = 3.9K and a C value = 0.1uF works well for most applications.
https://www.instructables.com/id/Analog-Output-Conv...

From this instructable, you can make read DAC.

I will explain more with picture.

Let's see the picture. It shows that how PWM out makes analog out well.

And Here is a more project which use PWM as DAC out

https://www.instructables.com/id/Simple-Wav-Player-...

Step 4: Software - How to Download

You can download software of this project with below link.

(You need mbed.org ID)

Visit code web page.

https://developer.mbed.org/teams/WIZnet/code/Ethernet_Voice_Streaming/

And Click "Import this program" as picture.

Then this program will install in your work space of web compiler.

Now you can see the software code.

You can compile this program and download on platform board and run.

Step 5: Explain Operation (Ethernet UDP Setting)

To send voice data, we will use UDP mode not TCP mode.

Because UDP don't do "retransmision" even if there is a lost data.

To send data as real time it is not need to retransmision.

Anyway picture shows how to set up UDP mode.

Code explain (with picture)

[1] - Defines of IP address (Server and Client)

Server : Receive data (UDP server)
Client : Transmision data (UDP client)

[2] - Setting for ethernet operation

[3] - Setting for UDP server

[4] - Setting for UDP client




Step 6: Explain Operation (UDP Send Data & Receive Data)

Now we have to send data and receive with UDP mode.

As see the picture,

this operation is very simple.

For send data we need below fucntion

sock.sendTo(echo_server, ad_data_buf0, MAX_BUF_SIZE);

For receive data we need below fuction

server.receiveFrom(client, ad_data_buf0, sizeof(ad_data_buf0));

Step 7: Explain Operation (ADC & PWM DAC)

To generate voice data, Client device need ADC operation.

ADC acquisite voice analog data. And they will save to buffer.

And in this project I decide the acquisition interval as 100usec as below

// Start acquisition (interval 100usec)
trigger_o.period_us(100);
trigger_o.write(0.50f);

Then adcTickfunc() function will be excute every 100usec.

Now we have to know what will happen in this function.

void adcTickfunc() {
# if defined (UDPServer)
if (buf_sel) aout.write((float)ad_data_buf1[i]/256*1.32);
else aout.write((float)ad_data_buf0[i]/256*1.32);
i++;

if (i == MAX_BUF_SIZE) i = MAX_BUF_SIZE - 1;
# else
if (buf_sel == 0) ad_data_buf0[i] = mic.read_u16() >> 4;
else ad_data_buf1[i] = mic.read_u16() >> 4;
i++;

if (i == MAX_BUF_SIZE) {
i = 0;
toggle = !toggle;
if (buf_sel) buf_sel = 0; else buf_sel = 1;
send_udp = 1;
sent = 1;
}
#endif
}

In Client mode,

To generate voice data, data will saving to the buffer every 100usec.

ad_data_buf0[i] = mic.read_u16() >> 4;

And in server mode,

To play voice data, data will send to PWM operation.

aout.write((float)ad_data_buf1[i]/256*1.32);

Step 8: Trouble Shooting

Double buffer

I used double buffer to solve real time operation problem,

As you can see the picture,

One buffer is data gathering while the other buffer is processing.

Data resizing

Two device's clock speed is different and communication speed is different every time.

So receive device must need to resize the data count.

Ex) Picture explain this case
Assume that TX device will send 1024 byte in every 100usec.
RX device can play only 1000 byte before new data arrive.
Or RX device play all received data (2014 byte) and remain time before new data arrive.

To solve this problem,

When RX device clock is faster than TX device, RX device must need to add last data.

if (i == MAX_BUF_SIZE) i = MAX_BUF_SIZE - 1;

When RX device clock is slower than TX device, RX device must need to rid remain data.

if (buf_sel) buf_sel = 0; else buf_sel = 1;
i = 0; // buffer index change to 0 as force.

Then played sound is differ from original sound.

But is it ok to listen.

For this case, Lower buffer size is better.

Step 9: Final

You can see the demo video which Ethernet Voice Streaming is working.

// I will update it soon.

In this project,

I bet you can use UDP protocol with WIZwiki-W7500 platform

and voice streaming service.

I think you can upgrade project with this project.

Thank you.

Step 10: