Codec2, FS-1015, Speex e.t.c. in VS10XX

Designing hardware that uses VLSI Solution's devices as slave codecs such as an external MP3 decoder chip for a host microcontroller.
User avatar
devicedeveloper
Senior User
Posts: 86
Joined: Sun 2016-07-24 11:30

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by devicedeveloper » Sat 2016-09-24 9:13

Henrik, thank you for your help!

I tried to MP3 decoder for 4 kbit / s as you wrote.
On the receiving side also had to set the reference divider (set SM_CLK_RANGE bit), but writing 4000 to SCI_AUDATA did not help.
So I left it to 8000 kHz value.

Secondly, I tried to OGG encoder similarly. It had non-linear bitrate and very large buffer filling and really eat more than 4 kbit/s.
Playing OGG sound in such case, without the lag could not!

The LoRa-modem bitrate calculated by the formula:

Rb=(SF*4*BW)/((4+CR)*2^SF)

For example SF=9 (spread factor 9 => 512 chips per byte), BW=500 kHz(receiver bandwidth), CR=3 (error code rate 4/7), the bitrate is 5022 bit/s.

It is more than 4 kbit/s, but we have additional overhead with Preamble, Header and CRC. So real USEFUL(equivalent) bitrate will be less.
Practically I found that the supply of the bit rate should be 20%, and in this case - we have sound reproduction without lag.

The next step is increase SF to 10, that gives an increase to the budget Radio-Link: +3 dB.
But it will require a reduction of the bit rate is not less than 2 times => 2 kbit/s.

But we need to change, the encoder principle, because it is already at 4 kbit / s 70% speech unintelligible. It is terrible to imagine what will happen at speeds of 2 and 1 kbit / s !!!

In this case, we need a speech encoder, not in the music encoder! Because music encoders bitrate reduction leads to a cut-off frequency higher than half the value of the bit rate.

A most informative speech band 1..3 kHz. The rest of the left and right can be cut. The remaining 1-3 kHz shake encoder.
Therefore, all hope for you that you are porting a speech codec with a low bit rate and good speech intelligibility!

It will be ideal, If VLSI developers write plugin one of the codecs: Opus, MELP, Speex, Codec2 for VS1063 :)
I'm thinking yourself take the case.....

User avatar
Henrik
VLSI Staff
Posts: 1150
Joined: Tue 2010-06-22 14:10

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by Henrik » Mon 2016-09-26 11:00

Hello!

And thanks for your informative post! It is always interesting to read about people trying to do different things with our ICs.

Below are comments to some points of your message:
devicedeveloper wrote:I tried to MP3 decoder for 4 kbit / s as you wrote.
On the receiving side also had to set the reference divider (set SM_CLK_RANGE bit), but writing 4000 to SCI_AUDATA did not help.
So I left it to 8000 kHz value.
Yes, you have to do one of them, not both. But you already noticed that!
devicedeveloper wrote:The next step is increase SF to 10, that gives an increase to the budget Radio-Link: +3 dB.
But it will require a reduction of the bit rate is not less than 2 times => 2 kbit/s.

But we need to change, the encoder principle, because it is already at 4 kbit / s 70% speech unintelligible. It is terrible to imagine what will happen at speeds of 2 and 1 kbit / s !!!
Well, I promised you that sound quality would already be very bad at 4 kHz!
devicedeveloper wrote:In this case, we need a speech encoder, not in the music encoder! Because music encoders bitrate reduction leads to a cut-off frequency higher than half the value of the bit rate.
Yes.
devicedeveloper wrote:It will be ideal, If VLSI developers write plugin one of the codecs: Opus, MELP, Speex, Codec2 for VS1063 :)
We have been looking at Speex some time ago, and at Opus recently. But, unfortunately, we don't yet have any schedule for implementing Opus. So, for the time being, the support we now have is all we have.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

User avatar
devicedeveloper
Senior User
Posts: 86
Joined: Sun 2016-07-24 11:30

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by devicedeveloper » Tue 2016-09-27 12:17

Hello!

I take care of the GNU software and downloaded MinGW package to compile programs.
As I understand it, at low bitrates human speech be synthesized, rather than compress. This is - a separate big topic: vocoders!

I managed to find and successfully compiled the source code for the following vocoders:
LPC10 @ 2400 bps
MELP @ 2400 bps
MELPe @ 1200 bps (Fixedpoint implementation with transcoder)
Codec2 @ 1200 and 700 bps

This source code not compiled under Visual C++, because authors of this code used static array constructions with non-constant volume, for example:

Code: Select all

void examplefunction(int p)
{
 float Z[p];
}
Visual C++ compiler will generates an error, but GCC will eat it successfully! :D

I was surprised in a good way, that speech intelligibility for 1200 and even 700 bps is saved!

I really want to find TWELP vocoder at 300 bps, but I'm afraid that is not easy! :(

The maximum spread factor of LoRa modem is 12, and maximum error coderate 4/8 - in result it requires bitrate less few than 500 bps. In this case sensivity of receiver will be excellent and radiolink budget will be increased +9 dB.


With regards to architecture VS1063, it supports floating point or not? Or only fixed point?

User avatar
Henrik
VLSI Staff
Posts: 1150
Joined: Tue 2010-06-22 14:10

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by Henrik » Wed 2016-09-28 13:53

Hello!

The issue is that VS1063 is a DSP. DSP code can be very efficient (both in power consumption and in clock cycles), but codes that compile on generic processors require lots of work to port to DSPs. It is usually not possible to just take some generic codec and compile it to a DSP architecture. The algorithm needs to be understood, and usually the code needs to be written from scratch, partly in assembler. So implementing a new codec takes a lot of time.

As for floating point, VS1063 has a floating point library, but it is slow. Natively the processor supports 16-bit and 40-bit fixed point numbers.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

User avatar
devicedeveloper
Senior User
Posts: 86
Joined: Sun 2016-07-24 11:30

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by devicedeveloper » Thu 2016-09-29 18:11

Hello!

Later, I found and built sourcecode of Codec2 at 450 bit/s. It sounds a bit synthetic, but the clarity is satisfactory!

My opinion is that the code should be cross-platform and assembly applications make it not portable. Especially the version with lower bitrates to the less demanding computing forces the processor. Or am I mistaken?

You performed calculations about how much it is necessary MIPS to start Codec2 at 700/450 kbit / s?

Lately, I transformed 600 bps Codec2 from 700 bps. It sounds beetween 450 and 700 bps with few tone distortions in some cases. I reduced LSPs 18 bit to 15 bit and disabled reservoir bit(i checked it is not used and =0)

User avatar
devicedeveloper
Senior User
Posts: 86
Joined: Sun 2016-07-24 11:30

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by devicedeveloper » Thu 2016-10-20 6:13

Hello everybody!

I was able to port a Codec2 on STM32F4Discovery Evaluation Board (configuration 450 bit/s). Built-in ADC and DAC at STM32 have bad parameters(SNR-ratio, bad influences isolation at power and GND, no LPF) when compared with VS1063. So I decided to use VS1063 as the ADC-DAC amplifier and data FIFO accumulator. VS1063 runs in codec mode (full duplex, with loaded patches v. 1.9) in PCM 16 bit mode.

I was surprised in a good way that VS1063 at a sampling rate of 8 kHz is quiet and does not crackle (as compared to the STM32 DAC) and prevents interference by the input power supply and the GND!

I attached some vocoded voice examples in English which is obtained by this pipeline:
Microphone => Amplifier => ADC => FIFO => Encoder => Decoder => FIFO => DAC => Amplifier => Speaker

Use only VS1063 for Codec2 is not possible, because Codec2 uses intensive floating point instructions (STM32F407 can calculate floating point instructions per 1 CPU clock) and requires HEAP over 32 kBytes and has very large codebook ~20 kB in 450bps mode.

I can reduce codebook size : convert floating single constant to single byte constant, but in this case we lose precision of codec2.
So Codec2 is possible in conjunction VS1063 and powerful CPU with hardware FPU.
vocoder_en.rar
(1.33 MiB) Downloaded 256 times
Last edited by devicedeveloper on Thu 2016-10-20 6:20, edited 1 time in total.

User avatar
devicedeveloper
Senior User
Posts: 86
Joined: Sun 2016-07-24 11:30

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by devicedeveloper » Thu 2016-10-20 6:15

This is my layout of the board with VS1063 and STM32..
Attachments
2.jpg
2.jpg (68.67 KiB) Viewed 2310 times
1.jpg
1.jpg (189.29 KiB) Viewed 2310 times

User avatar
Henrik
VLSI Staff
Posts: 1150
Joined: Tue 2010-06-22 14:10

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by Henrik » Thu 2016-10-20 9:45

Hello!

I think what you have done is highly impressive! I am also happy to hear you like VS1063's audio quality at 8 kHz. We put a lot of thought into the digital hardware sample rate converter that lets playback sound good at any sample rate (up to the maximum 48 kHz).

Kind regards,
- Henrik
Good signatures never die. They just fade away.

User avatar
devicedeveloper
Senior User
Posts: 86
Joined: Sun 2016-07-24 11:30

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by devicedeveloper » Fri 2016-10-21 3:21

Hello, Support!

I want to use STM32 DMA to send/receive data on SPI to/from VS1063. Optimal portion size: 320 words (this is 1 frame for Codec2 at 450 bps).

I use such function for data transmit to VS1063:

Code: Select all

void VS10x3_OutBuffer(s16* buf,u32 s)
{
 XDCS0;
 while(s--)
 {
  if(!(s&0xF))while(!DREQ)delay_us(10);
  spi3(*buf);
  spi3(*buf++>>8);
 }
 XDCS1;
}
Here it is possible to make DMA transmissions.

But in receiving code :

Code: Select all

void VS10x3_InBuffer(s16* buf,u32 s)
{
 while(VS10x3_InReg(SCI_HDAT1)<s)delay_us(10);
 while(s--)*buf++=VS10x3_InRegBE(SCI_HDAT0);
}
DMA implementation not possible, because VS1063 needs in XCS switch 0/1 for each word:

Code: Select all

s16 VS10x3_InRegBE(u8 a) //BigEndian
{
 s16 r;
 while(!DREQ)delay_us(10);
 XCS0;
 spi3(0x03);
 spi3(a);
 *((u8*)(&r)  )=spi3(0xFF);
 *((u8*)(&r)+1)=spi3(0xFF);
 XCS1;
 return r;
}
Please, help me : how I can get data from the encoder buffer another way?
I use VS1063A and full patch v. 1.9

Please say base address of the encoder buffer (the pointer to the beginning) and RAM type(X or Y) in the PCM encoder mode.
In this case it is possible to implement DMA read from this buffer, throw:

Code: Select all

 #define SCI_WRAM        0x6
#define SCI_WRAMADDR    0x7
with auto-increment address.

The second question: how I can send to de-coder more than 32 bytes? Optimal sise is also 320 words (one frame for Codec2)

User avatar
Henrik
VLSI Staff
Posts: 1150
Joined: Tue 2010-06-22 14:10

Re: Codec2, FS-1015, Speex e.t.c. in VS10XX

Post by Henrik » Mon 2016-10-24 12:39

Hello!

Unfortunately our SPI / SCI interface is limited by hardware so that you need to read the data one word at a time, requiring a 32-bit transfer to get 16 bits, and toying around with the chip select.

The only easy way to get data without such a 100% overhead is to use UART for output in codec mode. For this, set "UART TX enable" (bit 13 in SCI_AICTRL3) before starting encoding. For details, see VS1063 Datasheet Chapter 11.6.1, Encoding Control Registers.

Another option that requires some programming would be to implement a software Master SPI bus using four GPIO pins. In codec mode there should be enough free CPU to implement it. That way VS1063 could output audio data as soon as it gets it.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

Post Reply