Discussion:
[Freetel-codec2] Codec on STM32
Marat Galyamov
2016-09-16 20:38:15 UTC
Permalink
Hello.
I try to use the Codec2 on the STM32F746 microcontroller. For a start, I took files of the codec and collected the project for the PC in the CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place successfully, the regenerated file has high quality.
Then I collected the project in the IAR IDE (for STM32F746-Discovery board) and added to it the same files of the codec which I used in the project for the PC.
Coding and decoding took place successfully, quality of the regenerated file seemed a little worse, and if to compare contents of regenerated files, then in between there is a difference. Files of 48 kilobyte in size have about 400 different bytes - checked the special utility which compares files is byte-serial.
Why between regenerated files (the PC and STM32) the difference is? How it can be corrected?
Thanks. Excuse for my English.
--
Marat Galyamov
Steve
2016-09-16 21:24:45 UTC
Permalink
I'm having the same problem. When I change the

COMP W[FFT_ENC];

to

float W[FFT_ENC];

(to save 2k bytes) I get different data output. Even though none of
the algorithms use the imaginary data part (I edit the other files to
use the new float).

I haven't been able to figure it out yet, but the audio sounds the same to me.

Bottom line, 400 bytes out of 48k bytes is probably nothing to worry
about. Of those bytes, it's probably just a couple of bits flipped.

I think most of it is GCC compiler related.

Steve
Post by Marat Galyamov
Hello.
I try to use the Codec2 on the STM32F746 microcontroller. For a start, I took files of the codec and collected the project for the PC in the CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place successfully, the regenerated file has high quality.
Then I collected the project in the IAR IDE (for STM32F746-Discovery board) and added to it the same files of the codec which I used in the project for the PC.
Coding and decoding took place successfully, quality of the regenerated file seemed a little worse, and if to compare contents of regenerated files, then in between there is a difference. Files of 48 kilobyte in size have about 400 different bytes - checked the special utility which compares files is byte-serial.
Why between regenerated files (the PC and STM32) the difference is? How it can be corrected?
Thanks. Excuse for my English.
--
Marat Galyamov
------------------------------------------------------------------------------
David Rowe
2016-09-16 22:18:55 UTC
Permalink
Hello Marat and Steve,

The problem of comparing two versions of the codec is difficult. It is
very easy for a bug to slip in, so we need a good way of comparing.

Listening tests are unreliable. We need an objective measure.

The best test I have come up with is comparing the two waveforms using a
utility like some Octave code. Plot the synthesised speech from the two
versions on top of each other. Plot the difference. Measure the mean
square error between them over a test utterance. Minor differences (say
1 part in 1000) are OK.

You need a file I/O system running on the target hardware for this, like
semi-hosting or an equivalent tool in your IDE.

Sources of differences include float representation/precision, system
calls with different initial states or implementations like random
number generators, compiler differences. Small round off errors can
accumulate over many frames in a state based/recursive system like codec 2.

Fixed point code is actually easier to verify that float, as it can be
bit exact across platforms.

When I ported codec 2 to the STM32F4 a few years ago I recall the only
difference was in unvoiced speech, perhaps due to the noise generation.
I accepted this two noise sequences can sound the same even though not
identical in the time domain. However I would love to see this fully
tracked down.

It would be nice to have a standard go/no-go test for codec 2 porting,
like I have for the fdmdv and cohpsk modems.

Cheers,

David
Post by Marat Galyamov
Hello.
I try to use the Codec2 on the STM32F746 microcontroller. For a start, I
took files of the codec and collected the project for the PC in the
CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place successfully, the
regenerated file has high quality.
Then I collected the project in the IAR IDE (for STM32F746-Discovery
board) and added to it the same files of the codec which I used in the
project for the PC.
Coding and decoding took place successfully, quality of the regenerated
file seemed a little worse, and if to compare contents of regenerated
files, then in between there is a difference. Files of 48 kilobyte in
size have about 400 different bytes - checked the special utility which
compares files is byte-serial.
Why between regenerated files (the PC and STM32) the difference is? How
it can be corrected?
Thanks. Excuse for my English.
--
Marat Galyamov
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
glen english
2016-09-16 22:52:37 UTC
Permalink
I have another take on this

As Steve pointed out, there are sections of the code that produce non
zero, but near zero.
specifically the imag component here and there.

Without looking at it carefully (That is to say, talking out of my arse)
, I would guess that the imprecision of floating point numbers led to
there being non zero values where you might get zero with infinite
precision floating point (conceptually of course) .

Now, the slight bit difference in output due using zeros, not the non
zeros (but almost zeros) is most likely insignificant.
OR
it messes something up (based on assumptions ) and it corrected
elsewhere inadvertently.
***********************************************



g
Post by David Rowe
Hello Marat and Steve,
The problem of comparing two versions of the codec is difficult. It is
very easy for a bug to slip in, so we need a good way of comparing.
------------------------------------------------------------------------------
glen english
2016-09-16 22:57:27 UTC
Permalink
Hi Merit

you could be looking at the difference in the floating point units
between the processors- the F7 and the F4 have slightly different versions.

What compiler- linker processor flags have you used -?

If you use the F4 processor flags you may almost certainly get a
different / wrong result..

In addition to very subtle differences, some of the F7s have double
precision FPUs instead of single precision FPUs

do you have doubles forced to floats ?

have you a verification method / check in place to ensure you are not
blowing/ overwriting memory somewhere ?


g
Post by Marat Galyamov
Hello.
I try to use the Codec2 on the STM32F746 microcontroller. For a start,
I took files of the codec and collected the project for the PC in the
CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place successfully, the
regenerated file has high quality.
Then I collected the project in the IAR IDE (for STM32F746-Discovery
board) and added
------------------------------------------------------------------------------
glen english
2016-09-17 02:08:20 UTC
Permalink
David
you are the man to ask this one

Why do (or why do you think) relatively benign companding algorithms
like Alaw, uLaw, that are commonly used for encoding for VOIP links for
radio systems (and other) , sounds so awful when they pass AMBE/ AMBE2
etc processed speech ?

Must be something to do we the re distribution of the quantizating noise
characteristics?

Not sure what the effect is yet with codec2, but that would be a cinch
to test up.


g




------------------------------------------------------------------------------
David Rowe
2016-09-17 05:46:54 UTC
Permalink
It's a good question Glen, off the top of my head I'm not sure. When
one or more codecs are combined it's called transcoding and IIRC often
causes problems.

Alaw/mulaw are rather non-linear operations. That could upset the
parameter estimation algorithms.

- David
Post by glen english
David
you are the man to ask this one
Why do (or why do you think) relatively benign companding algorithms
like Alaw, uLaw, that are commonly used for encoding for VOIP links for
radio systems (and other) , sounds so awful when they pass AMBE/ AMBE2
etc processed speech ?
Must be something to do we the re distribution of the quantizating noise
characteristics?
Not sure what the effect is yet with codec2, but that would be a cinch
to test up.
g
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
glen english
2016-09-17 08:28:04 UTC
Permalink
Yeah.

Cascading codecs is always trouble.

BTW My understand of the word TRANSCODING is going between one encoded
method and another without going back all the way to uncompressed. Going
between different video encoding methods usually done by transcoding.
Most video encoding is all DCT / macroblock based so is probably more
relationship between codecs than speech codec variations....


In this problematic voip case: uncoded PCM (microphone) >> AMBE2 >>
over air >> decoded >> PCM >> uLaw encode>> ulaw decode >> headset. (and
reverse) .


regards
Post by David Rowe
It's a good question Glen, off the top of my head I'm not sure. When
one or more codecs are combined it's called transcoding and IIRC often
causes problems.
Alaw/mulaw are rather non-linear operations. That could upset the
parameter estimation algorithms.
- David
Post by glen english
David
you are the man to ask this one
Why do (or why do you think) relatively benign companding algorithms
like Alaw, uLaw, that are commonly used for encoding for VOIP links for
radio systems (and other) , sounds so awful when they pass AMBE/ AMBE2
etc processed speech ?
Must be something to do we the re distribution of the quantizating noise
characteristics?
Not sure what the effect is yet with codec2, but that would be a cinch
to test up.
g
------------------------------------------------------------------------------
Stuart Longland
2016-09-17 11:12:19 UTC
Permalink
Post by glen english
Yeah.
Cascading codecs is always trouble.
BTW My understand of the word TRANSCODING is going between one encoded
method and another without going back all the way to uncompressed. Going
between different video encoding methods usually done by transcoding.
Most video encoding is all DCT / macroblock based so is probably more
relationship between codecs than speech codec variations....
In this problematic voip case: uncoded PCM (microphone) >> AMBE2 >>
over air >> decoded >> PCM >> uLaw encode>> ulaw decode >> headset. (and
reverse) .
Transcoding is going from one format to another, and when the
destination is a lossy format, that will mean a reduction in quality.

Decoding to uncompressed shouldn't incur loss compared with a
hypothetical conversion from AMBE2 direct to µ-law, more likely the
assumptions made by the µ-law CODEC don't hold true for the synthesized
voice from the AMBE2 CODEC, and that would be why it sounds so terrible.

Regards,
--
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
...it's backed up on a tape somewhere.

------------------------------------------------------------------------------
Marat Galyamov
2016-09-19 09:12:49 UTC
Permalink
Hello, Glen.

In Windows I use CodeBlocks IDE with MinGW compiler, info from readme-file :

=== TDM-GCC Compiler Suite for Windows ===
--- GCC 4.6 & 4.7 Series ---
*** Standard MinGW 32-bit Edition ***
For microcontroler I use IAR IDE (iar.com) with her own compiler.
I experiment with STM32F746-Discovery board.


In CodeBlocks IDE I switched off optimization. 

In IAR IDE I have turned on optimization in Mdeium level.
I left settings of a linker by default, but I have increased the sizes of a stack and heap.

 STM32F746NG has single precision FPU.

I made a screenshot - compared two output files, version from PC and version from STM32.
All incoincident bytes differ on one value. Sorry for my english.
Post by glen english
Hi Merit
you could be looking at the difference in the floating point units
between the processors- the F7 and the F4 have slightly different versions.
What compiler- linker processor flags have you used -?
If you use the F4 processor flags you may almost certainly get a
different / wrong result..
In addition to very subtle differences, some of the F7s have double
precision FPUs instead of single precision FPUs
do you have doubles forced to floats ?
have you a verification method / check in place to ensure you are not
blowing/ overwriting memory somewhere ?
g
Post by Marat Galyamov
Hello.
I try to use the Codec2 on the STM32F746 microcontroller. For a start,
I took files of the codec and collected the project for the PC in the
CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place successfully, the
regenerated file has high quality.
Then I collected the project in the IAR IDE (for STM32F746-Discovery
board) and added
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
glen english
2016-09-19 09:37:12 UTC
Permalink
------------------------------------------------------------------------------
Marat Galyamov
2016-09-19 10:03:03 UTC
Permalink
Glen, I used only CODEC2_MODE_1200.

What IDE for STM32 you use?
Hi Marat
My *simplistic * observations is that these are due to variations
in the FPUs/ rounding error/ bias.
What codec bit are these variations in ?
IE
    Parameter                      frame 2  frame 4   Total
    -------------------------------------------------------
    Harmonic magnitudes (LSPs)      0       27        27
    Energy+Wo                       8        8        16
    Voicing (10ms update)           2        2         4
    Spare                           0        1         1
    TOTAL                          10       38        48
regards
On 19/09/2016 7:12 PM, Marat Galyamov
Post by Marat Galyamov
Hello, Glen.
In Windows I use CodeBlocks IDE with MinGW compiler, info from
=== TDM-GCC Compiler Suite for Windows ===
--- GCC 4.6 & 4.7 Series ---
*** Standard MinGW 32-bit Edition ***
For microcontroler I use IAR IDE (iar.com) with her own compiler.
I experiment with STM32F746-Discovery board.
In CodeBlocks IDE I switched off optimization. 
In IAR IDE I have turned on optimization in Mdeium level.
I left settings of a linker by default, but I have increased the sizes of a stack and heap.
 STM32F746NG has single precision FPU.
I made a screenshot - compared two output files, version from
PC and version from STM32.
Post by Marat Galyamov
All incoincident bytes differ on one value. Sorry for my english.
СуббПта, 17 сеМтября 2016, 1:57 +03:00 Пт
Hi Merit
you could be looking at the difference in the floating
point units
Post by Marat Galyamov
between the processors- the F7 and the F4 have slightly
different versions.
Post by Marat Galyamov
What compiler- linker processor flags have you used -?
If you use the F4 processor flags you may almost
certainly get a
Post by Marat Galyamov
different / wrong result..
In addition to very subtle differences, some of the F7s
have double
Post by Marat Galyamov
precision FPUs instead of single precision FPUs
do you have doubles forced to floats ?
have you a verification method / check in place to
ensure you are not
Post by Marat Galyamov
blowing/ overwriting memory somewhere ?
g
Post by Marat Galyamov
Hello.
I try to use the Codec2 on the STM32F746
microcontroller. For a start,
Post by Marat Galyamov
Post by Marat Galyamov
I took files of the codec and collected the project
for the PC in the
Post by Marat Galyamov
Post by Marat Galyamov
CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place
successfully, the
Post by Marat Galyamov
Post by Marat Galyamov
regenerated file has high quality.
Then I collected the project in the IAR IDE (for
STM32F746-Discovery
Post by Marat Galyamov
Post by Marat Galyamov
board) and added
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
Post by Marat Galyamov
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
glen english
2016-09-19 11:10:13 UTC
Permalink
I use Rowley Crossworks for ARM

but it is all GCC (4.9)
Glen, I used only CODEC2_MODE_1200.
What IDE for STM32 you use?
------------------------------------------------------------------------------
glen english
2016-09-19 22:26:41 UTC
Permalink
He's is an experience to share... and all this I know already but when
you experience just how frugal codec2 is on speech bits, it is
enlightenment.....

I am doing a project that uses Codec2 and sends data over Si4460
transceiver chips.

one thing that has become apparent is there is not much data coming out...

I send a packet every 20mS so that lost packets don't matter so much.
But.. all there is to transmit is ... 8 bytes ! :-) there is 12 bytes
wrapped around it..... Ha !

which means the data rate (and BW) has to go up to cope with the
overhead..... and David has worked so hard to get the bits down, and I
just throw 1.5x excess in radio overhead...

So I went up to 3 frames 60mS (24 bytes) plus the 12 byte overhead per
transmission....A bit better...

A lost packet hurts more, but the operating bandwidth is less. With the
diversity operation (I use TWO of the Si4460 chips simultaneously with
two antennas) , overall the reduction in BW has reduced packet loss.

In the single antenna no diversity option, it is better to have short
packets and a higher threshold (due to higher bit rate)

It's just I am used to 64kbps... not 3.2kbps.

g








------------------------------------------------------------------------------
Stuart Longland
2016-09-20 05:29:41 UTC
Permalink
Post by glen english
He's is an experience to share... and all this I know already but when
you experience just how frugal codec2 is on speech bits, it is
enlightenment.....
I am doing a project that uses Codec2 and sends data over Si4460
transceiver chips.
one thing that has become apparent is there is not much data coming out...
I send a packet every 20mS so that lost packets don't matter so much.
But.. all there is to transmit is ... 8 bytes ! :-) there is 12 bytes
wrapped around it..... Ha !
which means the data rate (and BW) has to go up to cope with the
overhead..... and David has worked so hard to get the bits down, and I
just throw 1.5x excess in radio overhead...
One option might be to use some forward erasure coding on each Codec2
frame to give you two 8-byte packets, then in each RF frame, you send
packet 2 (or zeros if it's the first packet) from the previous Codec2
frame concatenated with packet 1 from the current Codec2 frame.

You double your data rate, but if an RF frame gets lost, you can still
recover the full message with no delay or loss.
--
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
...it's backed up on a tape somewhere.
glen english
2016-09-20 07:49:20 UTC
Permalink
------------------------------------------------------------------------------
David Rowe
2016-09-19 10:08:00 UTC
Permalink
Hello Marat,

I just tested a patch from Danilo that replaced the complex FFT with a
real one. I used the codec2-dev/octave/pl2.m utility to compare and
plot the decoded speech output files from the before/after versions of
the code. As he reported with a similar Python utility - just one LSB
difference, which is fine.

It's a good idea to have support (i.e semi-hosting) for processing files
of samples on your target hardware that can then be compared on a Host PC.

I compared the difference over a 30 second speech file,
codec2-dev/raw/hts.raw.

Cheers,

David
Post by Marat Galyamov
Hello, Glen.
=== TDM-GCC Compiler Suite for Windows ===
--- GCC 4.6 & 4.7 Series ---
*** Standard MinGW 32-bit Edition ***
For microcontroler I use IAR IDE (iar.com) with her own compiler.
I experiment with STM32F746-Discovery board.
In CodeBlocks IDE I switched off optimization.
In IAR IDE I have turned on optimization in Mdeium level.
I left settings of a linker by default, but I have increased the sizes of a stack and heap.
STM32F746NG has single precision FPU.
I made a screenshot - compared two output files, version from PC and version from STM32.
All incoincident bytes differ on one value.
Sorry for my english.
Суббота, 17 сентября 2016, 1:57 +03:00 от glen english
Hi Merit
you could be looking at the difference in the floating point units
between the processors- the F7 and the F4 have slightly different versions.
What compiler- linker processor flags have you used -?
If you use the F4 processor flags you may almost certainly get a
different / wrong result..
In addition to very subtle differences, some of the F7s have double
precision FPUs instead of single precision FPUs
do you have doubles forced to floats ?
have you a verification method / check in place to ensure you are not
blowing/ overwriting memory somewhere ?
g
Post by Marat Galyamov
Hello.
I try to use the Codec2 on the STM32F746 microcontroller. For a
start,
Post by Marat Galyamov
I took files of the codec and collected the project for the PC in the
CodeBlocks IDE with the compiler GCC.
Coding and decoding of the raw-file took place successfully, the
regenerated file has high quality.
Then I collected the project in the IAR IDE (for STM32F746-Discovery
board) and added
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
_______________________________________________
Freetel-codec2 mailing list
https://lists.sourceforge.net/lists/listinfo/freetel-codec2
------------------------------------------------------------------------------
Loading...