VS1053b ADTS Stream does not play

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
StefanM
User
Posts: 8
Joined: Thu 2017-08-24 23:18

VS1053b ADTS Stream does not play

Post by StefanM » Thu 2017-08-24 23:38

Hi,

I am using a VS1053b and a ESP8266 (NodeMCU) to play mp3-files from network (wifi) - that works great!
But I also want to play ADTS and m4a/aac files, but this does not work (yet) ;-)

These are my parameters:
SCI_CLOCKF: 0x9000
SCI_MODE: 0x8020
SCI_AUDATA: 44101
SCI_VOL: 0x2020

When sending the ADTS-Stream, the SCI Registers look like this:
SCI_STATUS: 0x0040
SCI_HDATA1 0x4154
SCI_HDATA0 0x0000
SCI_AUDATA 0xAC45

When sending the m4a/aac file, the SCI Registers look like this:
SCI_STATUS: 0x8040
SCI_HDATA1 0xAD34
SCI_HDATA0 0x0000
SCI_AUDATA 0xAC44

The attachments contain a sample. I do not load any plugin.
Can somebody shed a light on me and tell me my mistakes or can confirm that my files are playable?

I am thankful for all help and information.

Best Regards
Stefan
Attachments
Sample ADTS and AAC.zip
(1.55 MiB) Downloaded 9 times

User avatar
Panu
VLSI Staff
Posts: 2418
Joined: Tue 2010-06-22 13:43

Re: VS1053b ADTS Stream does not play

Post by Panu » Mon 2017-08-28 8:47

Hi, and welcome to the forum!

We're looking into it. Probably you need to load a patch.
Which software are you using on the ESP8266 side?

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

StefanM
User
Posts: 8
Joined: Thu 2017-08-24 23:18

Re: VS1053b ADTS Stream does not play

Post by StefanM » Mon 2017-08-28 20:09

Hi,

the ESP8266 runs a ported Version of your "VLSI Solution generic microcontroller example player / recorder for VS1053" in v1.10 2016-05-09 HH.
Programming is done with "https://github.com/esp8266/Arduino".

The VS1053b is placed on a Board identical to this one: http://www.geeetech.com/wiki/index.php/ ... th_SD_card

In the meanwhile I tried to load the plugins "vs1053b-patches.plg" and "vs1053b-patches-latm.plg" with your LoadPlugin(const u_int16 *d, u_int16 len)-Function.
After Loading the Plugin (each on a seperated test) the hdata1-Register does not contain 0x4154 or 0xAD34 when sending the m4a or adts data, anymore.

I am not quite sure, whether the plugin is loaded correctly, can I check this out reading some register?
Do I need to write some "Start-Address" to SCI_AIADDR after I called LoadPlugin() ?

~Stefan

User avatar
pasi
VLSI Staff
Posts: 1412
Joined: Thu 2010-07-15 16:04

Re: VS1053b ADTS Stream does not play

Post by pasi » Tue 2017-08-29 12:54

The vs1053b patches will start automatically by having a write to AIADDR as the last operation in it.

So, apparently something goes wrong in the patch upload.

Are you writing SCI_CLOCKF before loading the patch? Are you waiting for DREQ to rise? What is your SPI speed?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

StefanM
User
Posts: 8
Joined: Thu 2017-08-24 23:18

Re: VS1053b ADTS Stream does not play

Post by StefanM » Tue 2017-08-29 23:09

Yes, I write SCI_CLOCKF before loading the patch. After writing SCI_CLOCKF and after loading the patch I wait until DREQ becomes HIGH.
My Start-SPI-Speed is 250KH. After writing to SCI_CLOCKF I set it to 4MHz. Than I call LoadPlugin(..).

Here is some Code of mine:

Code: Select all

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);

  pinMode(reset_pin, OUTPUT);
  digitalWrite(reset_pin, LOW);		//Do a Reset

  pinMode(cs_pin, OUTPUT);
  pinMode(dcs_pin, OUTPUT);
  digitalWrite(cs_pin, HIGH);		//Deselect
  digitalWrite(dcs_pin, HIGH);

  pinMode(dreq_pin, INPUT);

  SPI.setClockDivider(SPI_CLOCK_DIV64);  // Slow: 250 KHz

  digitalWrite(reset_pin, HIGH);		//Clear Reset
  write_register(SCI_MODE, _BV(SM_RESET) | _BV(SM_SDINEW) | _BV(SM_LAYER12));
  
  await_data_request();   //Wait for DREQ			
  write_register(SCI_CLOCKF, HZ_TO_SC_FREQ(12288000) | 0x8000 | 0x0800);
  delay(1);			     //Wait 1 millisecond
  await_data_request();  //Wait for DREQ	

  
  SPI.setClockDivider(SPI_CLOCK_DIV4); // Fast: 4MHz
  

  write_register(SCI_WRAMADDR, PAR_CONFIG1);	//Set SBR
  write_register(SCI_WRAM, PAR_CONFIG1_AAC_SBR_SELECTIVE_UPSAMPLE);	
  
  write_register(SCI_VOL,0x2020);	  //Set Volume
  

  LoadPlugin(plugin, sizeof(plugin)/sizeof(plugin[0]));
  delay(100);	//Wait 100 milliseconds
  await_data_request();	//Wait for DREQ 
	
  
  Serial.println("VS1053 Ready\r\n");

  uint16_t result = read_register(SCI_MODE);
  Serial.print("SCI_MODE: 0x");
  Serial.println(result, HEX);
  

User avatar
pasi
VLSI Staff
Posts: 1412
Joined: Thu 2010-07-15 16:04

Re: VS1053b ADTS Stream does not play

Post by pasi » Wed 2017-08-30 13:20

StefanM wrote:
Thu 2017-08-24 23:38
SCI_CLOCKF: 0x9000
SCI_MODE: 0x8020

The attachments contain a sample. I do not load any plugin.
Hi Stefan,

I looked at the files. The M4A.m4a in your samples should play with or without the patch. I recommend setting a fixed 4.5x clock though (0xc000).

ADTS.ts is a transport stream, so I don't expect to play with or without the patch unless you remove the TS wrapper.

Are you using just one SPI for the SCI (xCS) and SDI (xDCS)? SCI_MODE should probably be 0x8800 for the new communication mode. Also, if the crystal is 12.288MHz, you should not set the top bit, SCI_MODE should be 0x0800.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

StefanM
User
Posts: 8
Joined: Thu 2017-08-24 23:18

Re: VS1053b ADTS Stream does not play

Post by StefanM » Wed 2017-08-30 23:02

Hi,
thanks for your work!
pasi wrote:
Wed 2017-08-30 13:20
StefanM wrote:
Thu 2017-08-24 23:38
SCI_MODE: 0x8020
I am sorry, this was a typo :oops:
SCI_MODE was 0x0802.

So I set:
SCI_MODE to 0x0800
SCI_CLOCKF to 0xC000
And removed all Code for plugin loading.
I read SCI_MODE and SCI_CLOCK after writing to verify the values.
MP3 Files still play but M4A dont.

M4a was my first choice, so it is good that these can be played. ADTS.ts was my last choice, because I can fetch it only via HTTPS and that reduced my available memory for buffering extremly.

I am using xCS and xDCS and SM_SDISHARE is off. I take care that xCS and xDCS are never low at the same time. I also test all clock and phase polarity possiblities.

Do you have a guess what my problem could be?

User avatar
pasi
VLSI Staff
Posts: 1412
Joined: Thu 2010-07-15 16:04

Re: VS1053b ADTS Stream does not play

Post by pasi » Thu 2017-08-31 11:44

StefanM wrote:
Wed 2017-08-30 23:02
MP3 Files still play but M4A dont.
mp4 files may not be streamable if they have the "mdat" atom before the decoding parameters. However, the one you attached decodes fine with vs1053b.

Do the mp3 files play 100% correctly?

You may have some subtle error in the number of bytes you send to SDI. mp3 can synchronize to all audio frames even when there are extra bytes, but the mpeg-1/mpeg-2 container starts with structures that require the correct number of bytes.

You do get "M4" in HDAT1, so the first bytes are correct (the decoder detects the mp4 container), but you should get 44100Hz/stereo (AUDATA=0xac45) or 22050Hz/stereo depending to SCI_CLOCKF and your capability of servicing the SDI.

So, check your chip select and DREQ handling. Only change chip selects the the SPI is idle (not transmitting).
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

StefanM
User
Posts: 8
Joined: Thu 2017-08-24 23:18

Re: VS1053b ADTS Stream does not play

Post by StefanM » Thu 2017-08-31 22:37

pasi wrote:
Thu 2017-08-31 11:44
mp4 files may not be streamable if they have the "mdat" atom before the decoding parameters. However, the one you attached decodes fine with vs1053b.
All my m4a files are provided by the same service and encoded with Dolby Pulse Encoder 1.1.4 sbr: 4.0. So I guess they are almost all streamable.
But for testing I use the attached sample, to be sure.
pasi wrote:
Thu 2017-08-31 11:44
Do the mp3 files play 100% correctly?
No, there are some noise. At the beginning I had some buffering problems (because of less memory), I thought this was the reason of the noise.
I fixed this issue by now, but the noise is still there.
The noises are short impulsives and turns on almost regulary in 100ms intervalls. Indeed I send 1600 Bytes (in 32 Byte Chunks) each 100ms, approximately, that matches the 128kbit/s of the mp3 file.

So I think you are right: (timing) problems on SPI.

Here is me Code for SDI-Transfer. Do you see something weird?

Code: Select all

void VS1053::playChunk(uint8_t* data, size_t len)
{
    digitalWrite(dcs_pin, LOW);
    delayMicroseconds(1);
    await_data_request();		//wait until DREQ is high - do not wait when DREQ is high already
    while ( len )
    {
          SPI.transfer(*data++);
	  len--;
    }
    delayMicroseconds(1); 
    digitalWrite(dcs_pin, HIGH);
}

Code: Select all

for(int i = 0; i < 48 && buffer->space < 1024; i++) {	//as long as fifo is not empty and not more than 48*32 bytes
       player->playChunk(buffer->read(), 32);	//buffer->read() returns a char* (size of 32 Bytes) on my fifo
    }

Thanks for your work! But I think we are searching in the dark. If you dont see something wrong at once, I will ask me University for a oscilloscope.
I will post it, if I find the solution. But in the moment I have less time, because I have to write some exams.

~Stefan


EDIT:
Fun Fact: When I play "a a a a Very Good Song" (take a look at https://www.google.de/search?q=a+a+a+a+ ... +Good+Song. I have no noise.
"a a a a Very Good Song" is a song without any sound.

User avatar
pasi
VLSI Staff
Posts: 1412
Joined: Thu 2010-07-15 16:04

Re: VS1053b ADTS Stream does not play

Post by pasi » Fri 2017-09-01 14:17

playChunk looks fine. I assume SPI.transfer() returns when the transfer has been finished (does it have a return value?), in which case the delays are not necessary.

The one suspect thing is using two conditions in the byte send loop (i < 48 && buffer->space < 1024). 48 tells me you have a 48*32 = 1536-byte buffer, which is 3 disk blocks. What does buffer->space contain? Can the loop be exited early in some cases?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Post Reply

Who is online

Users browsing this forum: No registered users