Page 1 of 1

Opus support for VS1005 / VSOS

Posted: Thu 2021-09-30 11:22
by Henrik
Dear Forum Members,

it is with great pleasure and pride that I present you our latest addition for the VS1005 / VSOS audio codec family: an Opus speech encoder / decoder. Our new encoder can encode speech at data rates as staggeringly low as 8 kbit/s! To hear what kind of quality to expect, check out the samples attached to this message.

The package contains a README.TXT file that I have included below:

Code: Select all

	Opus Encoder / Decoder v1.00
	  for VSOS 3.63 or higher
	 2021-09-30  VLSI Solution

This package contains an Opus Encoder / Decoder for VS1005 running VSOS.

To test and use the encoder and decoder:
1) Copy the files in the SYS/ directory to your VS1005 Developer Board's
   SYS/ directory.
2) Copy example Opus RAW .OPR files from the Opus/ directory to the main
   directory of an SD card.
3) See the provided config.txt file, and use portions of it as appropriate
   in your S:CONFIG.TXT.
3.1) Note the "dec6" option on the AUIADC / AuInput command lines. The option
     allows for 8 and 16 kHz sample rates, required by the Opus Encoder and
     otherwise unavailable.

To test playback of an opus file, try either command:

S:>AuInfo d:16KQ10.OPU
     size: 34.6 KiB
   format: Raw Opus
     conf: 1 channels at 16000 Hz
     time: 0:04.8 seconds
  bitrate: 58.6 kbit/s
  analyze: 0.01 seconds
S:>PlayFile d:16KQ10.OPU
Playing '16KQ10.OPU'
[00:04]Decode finished.

... or ...

D: SD/SD Card
[... etc ...]

To record, do the following. Note that The VS1005 Opus Library is intended
as a speech codec: it can only record in mono, and only at 8 or 16 kHz.

S:>rec -h
Usage: Rec [-fm|-fo|-ff|-cs|-cm|-cl|-cr|-q{x}|-b{x}|-r{x}|-f|+f|-h] outFile
-fm|-fv|-fo|-ff	Format MP3|Ogg Vorbis|Opus|FLAC (alternative: file suffix)
-cs|-cm|-cl|-cr	Stereo|Mono|Left|Right
-qx	Set quality to x (0-10, higher is better)
-bx	Set bitrate to x kbit/s (1-511)
-rx	Set sample rate to x Hz, or x kHz if x<1000
-f/+f	Use / Don't Use FILEBUF library for audio data buffering
-h	Show this help
outFile	The output file name (e.g. D:REC.MP3|.OGG|.OPR|.FLA)
S:>Rec -cr -q5 -r8 d:08kq05.opr
Recording Opus: 8000 Hz mono at quality 5
[... when ready, push 'q' to end recording ...]

The format created by the Opus Encoder is VLSI Proprietary Opus Raw,
which is suitable for streaming. The format is very simple: there is
no file header, and each raw frame consists of the following bytes:

n    - 1 byte telling how many bytes there are going to be in the Opus frame.
data - n bytes of data.

A converter running on a Microsoft Windows PC that can convert from
VLSI Opus Raw to standard Ogg Opus is provided by VLSI Solution. The
converter is used as follows:

C:\>oggopus 08kq05.opr 08kq05.opus

where 08kq05.opr is the VLSI Opus Raw file to read, and 08kq05.opus is
the Ogg Opus file to write. The Ogg Opus file can be opened with any
standard software that can read the format, like the open source audio
tool Audacity.

Future expansion

This is the first pre-release of the Opus RAW encoder / decoder.
In time, the package will be expanded with:

1) Opus RAW codec that can do full-duplex encoding / decoding in real time.
   This can be used for low-latency low-bitrate communications.

2) Ogg Opus decoder that can decode everything Opus in mono/stereo up to
   48 kHz.
The package contains example audio files in the VLSI Proprietary Opus Raw format. To make it easier to have an idea of what kind of a sound quality you get at each setting, I have attached to this message a couple of the example files converted to standard .WAV format.

I hope you find this new package useful!

Kind regards,
- Henrik

Re: Opus support for VS1005 / VSOS

Posted: Sun 2021-11-07 6:50
by lorenzo318
Dear Henrik.

Tranks a lot.

Why a propetary opus format and not a standard one?

I should encode realtime audio in vs1005 codec and send audio compressed to a Linux server. Are there library and not only binary i could use in order to decode such data?

Thanks a lot.

Re: Opus support for VS1005 / VSOS

Posted: Mon 2021-11-08 11:28
by Henrik
Hello Lorenzo!
lorenzo318 wrote: Sun 2021-11-07 6:50 Why a propetary opus format and not a standard one?
The reason is streaming. We intend to implement a full duplex audio link later, but wrapping the stream in the standard Ogg wrapper that is used for files will unfortunately either:
A) Increase bitrate significantly (Ogg Header overhead is 27+ bytes per Ogg Frame)
B) Increase delay signficantly (If several Opus packets are wrapped in an Ogg Frame)
We found both options unacceptable.

So we made a minimum effort proprietary version of Opus that is exceedingly simple. It consists of following, repeated pairs:

1) N - 1 byte, tells how many bytes will follow in the Opus packet
2) Data - N bytes, the actual Opus packet raw data

And that's it.
lorenzo318 wrote: Sun 2021-11-07 6:50 I should encode realtime audio in vs1005 codec and send audio compressed to a Linux server. Are there library and not only binary i could use in order to decode such data?
To convert from our proprietary format, you could do something like the following (non-tested) pseudo code below on the Linux server:

Code: Select all

unsigned char buf[127];
int n;
int outOfSync = 0;

while ((n = fgetc(inFile)) != EOF) { // For each packet...
  if (n > 0) { // If there is data in the Opus frame...
    if (n < 128) { // Accept only frames of less than 128 bytes
      fread(buf, sizeof(buf[0]), n, inFile); // Read Opus packet
      if ((buf[0] & 0xBF) == 0x08) {  // Is Opus Header byte ok? (our encoder only makes mono 8 or 16 kHz Silk frames)
        OutputOpusPacket(buf, n); // Opus Header ok: Send the packet forwards
      } else {
        outOfSync = 1; // Opus Header bad: We are out of sync with the file and must resynchronize
    } else {
      outOfSync = 1; // Opus frame size >= 128: We are out of sync with the file and must resynchronize
  if (outOfSync) {
    outOfSync = ResynchronizeOpus(inFile); // Shouldn't happen if communication is good
Kind regards,
- Henrik

Re: Opus support for VS1005 / VSOS

Posted: Thu 2021-11-18 8:11
by lorenzo318
Thanks a lot Henrik.

May I ask why only Mono? ("our encoder only makes mono 8 or 16 kHz Silk frames").

Don't you believe it's an important limitation?

Are you thinking of extend OPUS to stereo audio or it depends on a HW limitation which will never permit to implement it?

Thanks a lot,

Re: Opus support for VS1005 / VSOS

Posted: Tue 2021-11-23 13:19
by Henrik
Hello Lorenzo,

we have chosen to only support mono with our encoder to make it as small as possible and so as not to consume excessive amounts of CPU. Also, mono is usually enough when speech is coded, particularly if you are really looking to get as low a bitrate as possible.

Our future plan for Opus is to get it working in full-duplex mode (encoding+decoding at the same time) along with Acoustic Echo Cancallation. As an example, think of a door phone or similar headphoneless communications system. In that case no single part may eat up all our resources.

Still, this will only be a limit of this encoder/decoder pair. We are also in the process of writing a full Ogg Opus decoder that supports all sample rates and modes. So, if someone has created standard Opus files on a PC or some other device, we will in the future be able to decode it.

For applications that require encoding with stereo sound and potentially higher sample rates than 16 kHz, we have excellent Ogg Vorbis and MP3 encoders available, and if bitrate is no issue, we can offer lossless FLAC encoding, or up to 4-channel 96 kHz 24-bit PCM encoding.

Kind regards,
- Henrik