Trouble Using VS1053 Record_Ogg Example

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
ParallaxMoon
 
Posts: 11
Joined: Mon Sep 08, 2014 1:47 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by ParallaxMoon »

Also about corrupt ogg files:
If you are having trouble with receiving data, notice that all Ogg Vorbis files always begin
with the following 4 bytes: 0x4f 0x67 0x67 0x53 (the string “OggS”). If you get 0x67 0x4f
0x53 0x67 (“gOSg”) instead, you are storing the least and most significant byte in the
16-bit data words incorrectly. If you get 0x00 0x00 0x67 0x53, you have read data from
SCI_HDAT0 too soon after starting the application.
I havent got the chance to look over the hex files of the corrupted ogg files, but perhaps there is a way to make sure the arduino/vs1053 store the bytes correctly

User avatar
ParallaxMoon
 
Posts: 11
Joined: Mon Sep 08, 2014 1:47 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by ParallaxMoon »

zakhounet wrote:Same proble than ParallaxMoon. When i play the the OGG file every 2-3 secs no sound for 2 seconds ....

This BoB drive me crazy.

Any support please ?

PS :
rename record00.txt in .ogg and Max volume if you want to hear the sample attached.
GOT IT! ive got low bat, so ill edit this later but:

its because the library assumes that the external clk speed is ~=12MHz, while the arduino is 16mhz

go into the library, and where it says the max clock speed is 0xC000, put instead 0x8700

EDIT:

Right, so if you go into the Arduino/Libraries/Adafruit_VS1053/Adafruit_VS1053.cpp and go to where the recorder is prepped (starting at line 513 in the commit):

Code: Select all

boolean Adafruit_VS1053::prepareRecordOgg(char *plugname) {
  sciWrite(VS1053_REG_CLOCKF, 0xC000);  // set max clock
  delay(1);    while (! readyForData() );
Now we wanna try to match the clock of the VS1053 to as close to 55.3MHz,(I believe this is the rounded number, if I find the exact, I will edit). Since the Arduino runs at a clock of 16MHz, we wanna find the what hex multiplies by 16 to make 55.3.
55.3/16= 3.45625
Taking a quick look at the preset value, 0xC000, which is dec equivalent to 49152, we see that we need 5 significant digits represented. Therefore our target value is actually 34560, which in hex is 0x8700!

leaving you with:

Code: Select all

boolean Adafruit_VS1053::prepareRecordOgg(char *plugname) {

  sciWrite(VS1053_REG_CLOCKF,     0x8700    );  // set max clock

  delay(1);    while (! readyForData() );

User avatar
zakhounet
 
Posts: 11
Joined: Tue Jul 30, 2013 10:37 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by zakhounet »

Thanks for the explanation, but with the value 0x8700, I have indeed no more hiccup but the the sound is accelerated ;)

Do you have the same result ?

btw I am using a Mega (but still at 16MhZ)

User avatar
ParallaxMoon
 
Posts: 11
Joined: Mon Sep 08, 2014 1:47 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by ParallaxMoon »

On phone. So I'm not by my circuit. But I will be tomorrow.

But what do you mean by accelerated?

A note, the preset value, I believe is supposed to be 45000 or 4.5. But it's not. I'm not sure how they got that hexdec number. Anyone got any ideas? Am I wrong/crazy.

User avatar
zakhounet
 
Posts: 11
Joined: Tue Jul 30, 2013 10:37 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by zakhounet »

But what do you mean by accelerated?
example with CLOCKF = 0x8700 : see atached (please rename it from .txt to .ogg)
A note, the preset value, I believe is supposed to be 45000 or 4.5. But it's not. I'm not sure how they got that hexdec number. Anyone got any ideas? Am I wrong/crazy.
For the calculation of CLOCKF (16 bits register), my guess is based on page 42 from the vs1053 datasheet :
http://www.adafruit.com/datasheets/vs1053.pdf.

Please feel free to correct me if I am wrong :
SC_MULT calculation (bit 15,14,13) :
Max VS1053 Clock value is 55.3 MhZ
Arduino Mega Clock is 16 Mhz
55.3/16 = 3,45625 ==> X3 (3 because VS1053B OGG VORBIS ENCODER (page 9) : "Set the VS1053b clock to the highest value just below 55.3 MHz"http://www.adafruit.com/datasheets/Vorb ... er170c.pdf
So SC_MULT = 3 (Mask : 0x6000)
SC ADD calculation (bit 12 ,11) :
easy = 0 because it's for ogg not for WMA or ACC)
so SC_ADD = 0
SC_FREQ calculation (bit 10,... ,0) :
if XTALI is different to 12,288MhZ, then the formula for calculating the correct value for this register is [(XTALI−8000000)/4000] (XTALI is in Hz).
in Arduino case XTALI is 16 MhZ, so SC_FREQ = 2000 or 0x07D0 (Note : if XTALI is equl to 12,288MhZ then SC_FREQ = 0)

Conclusion the value of CLOCKF should be :
67D0
with this value still no hiccup but still accelerated.

I can't test it on UNO but If you can give a try with an Arduino UNO just to check ...
Attachments
test0x67D0.txt
sciWrite(VS1053_REG_CLOCKF, 0x67D0) (to play rename it in .ogg)
(225 KiB) Downloaded 252 times
test0x8700.txt
sciWrite(VS1053_REG_CLOCKF, 0x8700) (to play rename it in .ogg)
(563.5 KiB) Downloaded 237 times

User avatar
zakhounet
 
Posts: 11
Joined: Tue Jul 30, 2013 10:37 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by zakhounet »

My bad, the Adafruit BoB is actually using an external crystal at 12,288 MhZ (see schematic : https://learn.adafruit.com/assets/11221 ) therefore the CLOCKF value of 0xC000 is the right one, nothing to change here.

Going back to square one ...

I am still stuck to get one good (no hiccup) recording file !!

User avatar
zakhounet
 
Posts: 11
Joined: Tue Jul 30, 2013 10:37 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by zakhounet »

Ok, end result of my crazy journey with this great Adafruit product and well done for the library (the must complete VS1053 library for Arduino, available on the market) :

Further discussion with VLSI (VS1053 maker) it appears to me, that the current Adafruit Library is writing to the SD card without using Multiple Block Write mode therefore it is not optimized (to an execution speed stand point) for mono 44.1KHz, HiFi Voice plugging.
(See my Thread : http://www.vsdsp-forum.com/phpbb/viewto ... =11&t=1563 ).

First improvement, not too hard to do, is to use SdFat library (https://github.com/greiman/SdFat) instead of the SD library.
To do this, (after having installed the SdFat library ;) http://arduino.cc/en/guide/libraries), you need to :

Change the record_ogg.ino file like this :

Code: Select all

// #include <SD.h>
#include <SdFat.h>
SdFat SD;
Then in Adafruit_VS1053.cpp change the SD.h include like this (don't forget the word extern) :

Code: Select all

// #include <SD.h>
#include <SdFat.h>
extern SdFat SD;
And finally in Adafruit_VS1053.h file change :

Code: Select all

// #include <SD.h>
#include <SdFat.h>
I have tried with a fresh new Sandisk ultra (micro SDHC 4 Go) : it works, with a really good recording quality :-)

Unfortunately, if you are using a SD card with a too high writing latency (it was my case) than this improvement is still not enough to not overflow the VS1053 buffer and you ogg file will be corrupted. Hopefully someone will, one day, improve the library by developing the multiple blocks mode SD card writing.

Meanwhile, the only workaround, I found so far, is to reduce the recording quality by changing the mono 44.1KHz, HiFi Voice plugin ("v44k1q05.img") by a mono 16KHz Wideband Voice ("venc16k1q05.img"), you just have to download it at http://www.vlsi.fi/fileadmin/software/V ... r-170c.zip.
You will get a quiet acceptable recording quality.

-----------

Now regarding the ability to record more than one file in each round ("the 1Ko file size issue), this is because you need to reload every time the vorbis-encoder plugin (confirm by VLSI). My solution is to add the line "musicPlayer.prepareRecordOgg("v44k1q05.img");" like this :

Code: Select all

if (isRecording)
    saveRecordedData(isRecording);
  if (isRecording && !digitalRead(REC_BUTTON)) {
    Serial.println("End recording");
    musicPlayer.stopRecordOgg();
    isRecording = false;
    // flush all the data!
    saveRecordedData(isRecording);
    // close it up
    recording.close();
    delay(1000);
    musicPlayer.prepareRecordOgg("v44k1q05.img"); // Add this line to re-launch the plugin
  }
You should be now, able to record as much file as you want in each round (limited by the SD size !).

-----------

To conclude, I have seen several time the same question about how downloading a patch (i.e a .plg file) to the VS1053, as it not so well documented ;)
Here is the 5 steps, I followed, to patch succesfuly my VS1053 :
1) Of course download your file and take the .plg extension. (http://www.vlsi.fi/en/support/software/ ... ugins.html)
2)Copy from the line "#ifndef SKIP_PLUGIN_VARNAME" till the end (should be "#endif").
3)Paste it, at the very beginning of your sketch
4)Change the plugin[] definition as below :
from

Code: Select all

const unsigned short plugin[] = { /* Compressed plugin */
to

Code: Select all

PROGMEM const uint16_t plugin[] = { /* Compressed plugin */
5)Into your Setup, add the following line, after having initialized the music player :

Code: Select all

// initialise the music player
  if (!musicPlayer.begin()) {
    Serial.println("VS1053 not found");
    while (1);  // don't do anything more
  }
musicPlayer.applyPatch(plugin, PLUGIN_SIZE);// Add here ...
Et voila ...

Please note that VS1053b is not updated as such with the patches. They are loaded to RAM memory, so they need to be reloaded and activated every time VS1053 is started. ;(

Hope this post will help other people, looking after voice recording solution.

Wish you all a nice Easter break.

User avatar
gchristopher
 
Posts: 7
Joined: Wed May 10, 2017 8:56 pm

Re: Trouble Using VS1053 Record_Ogg Example

Post by gchristopher »

zakhounet wrote:Meanwhile, the only workaround, I found so far, is to reduce the recording quality by changing the mono 44.1KHz, HiFi Voice plugin ("v44k1q05.img") by a mono 16KHz Wideband Voice ("venc16k1q05.img"), you just have to download it at http://www.vlsi.fi/fileadmin/software/V ... r-170c.zip.
Thanks zakhounet, for the last piece in making the VS1053 breakout board work for continuous recording! With the lower bitrate, the SD card can keep up and I don't get weird gaps and other probably SD-write-latency related artifacts in the audio.

Thanks, Adafruit, for the breakout board and library on a relatively difficult topic. Going from soldering the breakout boards to having surprisingly great continuous audio recording (especially for a bunch of analog connections on a breadboard) was only half a day's worth of work! (Using the MAX9814 breakout's output going to Mic+ with a 10uF cap in serial, and Mic- tied to ground.)

User avatar
fatman1
 
Posts: 12
Joined: Fri Aug 03, 2018 3:33 am

Re: Trouble Using VS1053 Record_Ogg Example

Post by fatman1 »

Hi, I am still confused on how can I load the new plugin can anyone explain please, thanks.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”