Discussion:
[Freetel-codec2] CODEC problem
Anomadarshi Barua Shuvro
2016-06-12 09:08:39 UTC
Permalink
Hi,
I have been using this codec for transmission of voice over wireless
network. Because of my hardware constraint , I am sampling the voice with
4KHz with 16 bit resolution . After compression at the transmitter side and
decompression at the receiver side the voice quality is very poor. I saw
that the codec is written for 8KHz sampling rate .
Will it be possible to use it for 4kHz sampling rate with good voice
quality and if yes how ?

kind regards
Anomadarshi
glen english
2016-06-12 09:43:46 UTC
Permalink
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
Anomadarshi Barua Shuvro
2016-06-12 12:11:27 UTC
Permalink
Hi Glen,
Thank you very much for your reply . I have few confusions. If I would use
8bit resolution per sample , then I would need to change line 3 in the
following piece of code , right ? If I would change line 3 to buf =
(char*)malloc(nsam*sizeof(char)) , will it work ? I mean do I need to
change anything inside of the codec ?

Line 1: codec2 = codec2_create(CODEC2_MODE_1300);
Line 2: nsam = codec2_samples_per_frame(codec2);
Line 3: buf = (short*)malloc(nsam*sizeof(short));
Line 4: nbit = codec2_bits_per_frame(codec2);
Line 5: bits = (unsigned char*)malloc(nbit*sizeof(char));


kind regards
Anomadarshi
Anomadarshi,
simply implement a 1:2 upsampler and 2:1 downsampler
this will provide your required functionality.
Sampling a speech signal at only 4kHz, that is a nyquist freq of 2kHz,
likely leading to a audio input bandwidth of perhaps 1.7kHz will provide
very very poor quality speech. A minimum of 2.4kHz audio bandwidth is
suggestion.
The use of 16 bits would seem to be a waste of time.
I would suggest changing your hardware to 8kHz sample rate and 8 bits. Or
even 6 bits.
Use of an AGC ahead of codec2 might improve results.
regards
glen english
vk1xx
Hi,
I have been using this codec for transmission of voice over wireless
network. Because of my hardware constraint , I am sampling the voice with
4KHz with 16 bit resolution . After compression at the transmitter side and
decompression at the receiver side the voice quality is very poor. I saw
that the codec is written for 8KHz sampling rate .
Will it be possible to use it for 4kHz sampling rate with good voice
quality and if yes how ?
kind regards
Anomadarshi
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
Jeroen Vreeken
2016-06-12 12:23:13 UTC
Permalink
Hi Anomadarshi,
Post by Anomadarshi Barua Shuvro
Hi Glen,
Thank you very much for your reply . I have few confusions. If I would
use 8bit resolution per sample , then I would need to change line 3 in
the following piece of code , right ? If I would change line 3 to buf
= (char*)malloc(nsam*sizeof(char)) , will it work ? I mean do I need
to change anything inside of the codec ?
No, that won't work.
The codec expects a buffer of shorts. So even if you sample only bytes
you would still have to convert them to shorts.

This is the prototype of the encode function:
void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits,
short speech_in[]);

It has not changed by your change.

Regards,
Jeroen
Anomadarshi Barua Shuvro
2016-06-12 12:43:52 UTC
Permalink
Hi,

Thank you very much...You guys are doing really fantastic jobs..

kind regards
Anomadarshi
Post by Jeroen Vreeken
Hi Anomadarshi,
Post by Anomadarshi Barua Shuvro
Hi Glen,
Thank you very much for your reply . I have few confusions. If I would
use 8bit resolution per sample , then I would need to change line 3 in
the following piece of code , right ? If I would change line 3 to buf
= (char*)malloc(nsam*sizeof(char)) , will it work ? I mean do I need
to change anything inside of the codec ?
No, that won't work.
The codec expects a buffer of shorts. So even if you sample only bytes
you would still have to convert them to shorts.
void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits,
short speech_in[]);
It has not changed by your change.
Regards,
Jeroen
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
glen english
2016-06-12 12:54:10 UTC
Permalink
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
Anomadarshi Barua Shuvro
2016-06-12 13:19:30 UTC
Permalink
Hi Glen,

My hardware bottleneck is for low speed . I am using nRF52 which is a
CortexM4 microcontroller with 64MHz clock speed and 64 KB of RAM . The
problem is if I use 8KHz sampling rate the frame size is 20 ms for 160
samples ( 3200 kbps) . But conversion time to compress 20 ms frame is
around 60 ms if I want to use 3200kbps CODEC . So I am missing 3 frames for
each compression . So I am using 4 KHz sampling rate because 4KHz sampling
rate would give me 40ms frame for 160 samples .


kind regards
Anomadarshi
Nice one Jereon.
Anomadarshi,
where is your hardware bottleneck- why the sample rate limit- help us
understand .
I thought that if you had a hardware bit rate limit, then going for 8 kHz
sampling and 8 bit samples would be the same information rate as 4 Khz
sampling and 16 bit samples.
As Jereon says, you will need to format to suit the buffers and structs.
regards
Hi,
Thank you very much...You guys are doing really fantastic jobs..
kind regards
Anomadarshi
Post by Jeroen Vreeken
Hi Anomadarshi,
Post by Anomadarshi Barua Shuvro
Hi Glen,
Thank you very much for your reply . I have few confusions. If I would
use 8bit resolution per sample , then I would need to change line 3 in
the following piece of code , right ? If I would change line 3 to buf
= (char*)malloc(nsam*sizeof(char)) , will it work ? I mean do I need
to change anything inside of the codec ?
No, that won't work.
The codec expects a buffer of shorts. So even if you sample only bytes
you would still have to convert them to shorts.
void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits,
short speech_in[]);
It has not changed by your change.
Regards,
Jeroen
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports.
https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
Dean Hall
2016-06-12 14:57:43 UTC
Permalink
I agree with other replies that a 4 kHz sample rate will only capture 2 kHz of the voice spectrum which will result in loss of key sounds, or aliasing that will distort the sound even without any compression/decompression happening.
"But conversion time to compress 20 ms frame is around 60 ms if I want to use 3200kbps CODEC"
First thing to do is to make sure your 60 ms number is correct and a real limit.
How did you measure the 60 ms?
Have you turned on your compiler's optimization?
How are you obtaining the audio samples? I presume the SAADC on the nRF52. Is that causing any delay other than copying a buffer? Can you use DMA to copy the buffer rather than memcpy()?

If you are truly limited by CPU cycles, then consider your choice of codec variant. The 3200 kbps codec will sound better than the 1600 kbps, but the lower bit rate codecs throw away bits that have lesser significance so your CPU will have less number crunching (maths) to do.

Lastly, your CPU has SIMD instructions that could really increase your computational power if you have the expertise and time to commit to re-coding all the maths.

!!Dean
KC4KSU
Hi Glen,
My hardware bottleneck is for low speed . I am using nRF52 which is a CortexM4 microcontroller with 64MHz clock speed and 64 KB of RAM . The problem is if I use 8KHz sampling rate the frame size is 20 ms for 160 samples ( 3200 kbps) . But conversion time to compress 20 ms frame is around 60 ms if I want to use 3200kbps CODEC . So I am missing 3 frames for each compression . So I am using 4 KHz sampling rate because 4KHz sampling rate would give me 40ms frame for 160 samples .
kind regards
Anomadarshi
Nice one Jereon.
Anomadarshi,
where is your hardware bottleneck- why the sample rate limit- help us understand .
I thought that if you had a hardware bit rate limit, then going for 8 kHz sampling and 8 bit samples would be the same information rate as 4 Khz sampling and 16 bit samples.
As Jereon says, you will need to format to suit the buffers and structs.
regards
Post by Anomadarshi Barua Shuvro
Hi,
Thank you very much...You guys are doing really fantastic jobs..
kind regards
Anomadarshi
Hi Anomadarshi,
Post by Anomadarshi Barua Shuvro
Hi Glen,
Thank you very much for your reply . I have few confusions. If I would
use 8bit resolution per sample , then I would need to change line 3 in
the following piece of code , right ? If I would change line 3 to buf
= (char*)malloc(nsam*sizeof(char)) , will it work ? I mean do I need
to change anything inside of the codec ?
No, that won't work.
The codec expects a buffer of shorts. So even if you sample only bytes
you would still have to convert them to shorts.
void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits,
short speech_in[]);
It has not changed by your change.
Regards,
Jeroen
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports.
https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
glen english
2016-06-12 22:42:25 UTC
Permalink
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
Steve
2016-06-12 19:11:59 UTC
Permalink
The actual minimum speed in order to use the codec2 vocoder is the
processing of 80 samples in 10 ms. The older speeds of 3200 and 2400 both
use two of these segments, and the rest use four. These segments also
require a lot of time to interpolate, and should be less than 20 ms for the
older modes, and 40 ms for the newer modes.

But that is only if you want to operate in real time. If you don't need
real time, you can take as long as you want. I can think of a lot of
communications, where non-real time would be "good enough".

In playing with the vocoder, I have found the first few segments take more
time, than after it gets going. So, the worse case is about the first 120
ms of startup, then it averages much lower processing time.

I did secure voice on a 10 MHz Z-80, but no vocoder :-) I just digitized
the audio and shifted the time segments around, and then back to analog.

Sometimes analog is good enough.
Bruce Perens
2016-06-12 19:57:12 UTC
Permalink
If you have a way to modify the hardware, 8 bits at 8 KHz would work better
than 16 bits at 4 KHz.
Post by Steve
The actual minimum speed in order to use the codec2 vocoder is the
processing of 80 samples in 10 ms. The older speeds of 3200 and 2400 both
use two of these segments, and the rest use four. These segments also
require a lot of time to interpolate, and should be less than 20 ms for the
older modes, and 40 ms for the newer modes.
But that is only if you want to operate in real time. If you don't need
real time, you can take as long as you want. I can think of a lot of
communications, where non-real time would be "good enough".
In playing with the vocoder, I have found the first few segments take more
time, than after it gets going. So, the worse case is about the first 120
ms of startup, then it averages much lower processing time.
I did secure voice on a 10 MHz Z-80, but no vocoder :-) I just digitized
the audio and shifted the time segments around, and then back to analog.
Sometimes analog is good enough.
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
Continue reading on narkive:
Loading...