Encoding problem - no data (VS1053b)

Writing software that inputs and/or outputs audio and performs DSP algorithms such as filters, new codecs or audio effects.
Mister110
User
Posts: 9
Joined: Mon 2012-03-26 12:57

Encoding problem - no data (VS1053b)

Postby Mister110 » Mon 2012-03-26 13:57

Hi everyone,

I'm actually using VS1053b encoder/decoder and I have a problem with the encoding mode (decoding is OK). I have to encode audio and generate a Ogg file but it seems that no data are encoded (only file's header is sent and status is OK).

To generate an Ogg file, I have to load a plugin. I think that it's OK (I followed the example "How to Load an .IMG File" from "VS1053B OGG VORBIS ENCODER" PDF).

When I start to encode data, I first read SCI_HDAT1 register to see how many words are waiting in the buffer. The answer is 700 so I send all these data. Apparently, these data contain the ogg file's header because I can see the ogg's header end sequence [4F 67 67 53 00 00 ... 02 00 00 00].

The problem occurs when I want to read SCI_HDAT1 register another time. The answer is always 0 and I can't encode any other data.

- Can someone help me to receive and encode data after the ogg's header?

I think that I haven't any electrical or hardware problem with my microphone because I can activate it and hear my voice via connected headphones. I suppose only a register's configuration problem or something wrong in my code. I attach my code and the generated OGG file just below.

This is my configuration for the plugin (it seems OK because returning address is 0x34 -> SCI_AIADDR register):

Code: Select all

void init_record_mode()
{
   /* Set VS1053 clock to 4.5x = 55.3 MHz */
   VS_writeRegister(SCI_CLOCKF, 0xC000);

   /* Clear SCI_BASS */
   VS_writeRegister(SCI_BASS, 0);

   /* Reset VS1053 */
   VS_writeRegister(SCI_MODE, SM_RESET);

   // Disable all interrupts except SCI   
   VS_writeRegister(SCI_WRAMADDR, 0xC01A);
   VS_writeRegister(SCI_WRAM, 0x2);

   /* Load the recorder application to VS1053 */
   //Open index file
   pluginRecordFile = FSfopen(pluginRecordFilename, mode_record_read);

   if (pluginRecordFile)
   {
      //Find plugin address start (if OK, return 0x34)
      pluginStartAddr = pluginAddressStart(pluginRecordFile);

      close(&pluginRecordFile);
   }

   /* Set VS1053 mode bits as instructed in the VS1053b Ogg Vorbis Encoder
                manual. Note: for microphone input, leave SMF_LINE1 unset! */
   VS_writeRegister(SCI_MODE, VS_readRegister(SCI_MODE) | SM_ADPCM);   //Set SM_ADPCM

   /* Rec level: 1024 = 1. If 0, use AGC */
   VS_writeRegister(SCI_AICTRL1, 1024);
   /* Maximum AGC level: 1024 = 1. Only used if SCI_AICTRL1 is set to 0. */
   VS_writeRegister(SCI_AICTRL2, 0);
   /* Miscellaneous bits that also must be set before recording. */
   VS_writeRegister(SCI_AICTRL3, 0);

   /* Activate recording from the address we got. */
   VS_writeRegister(SCI_AIADDR, pluginStartAddr);
}


This is my code for the encoding mode:

Code: Select all

#define SIZE_OF_BUFFER   64

                [...]
   
   unsigned short wordsToRead;
   unsigned short wordsWaiting = 0;
   unsigned char buffer[SIZE_OF_BUFFER];
   unsigned char i;
   unsigned short t;

   [...]

                init_record_mode();

   while(1) //until user choose to quit record mode (then close file)
   {
      if (!wordsWaiting)
      {
         wordsWaiting = VS_readRegister(SCI_HDAT1);
      }   
      
      while(wordsWaiting)
      {
         if (wordsWaiting >= (SIZE_OF_BUFFER/2))
         {
            wordsToRead = (SIZE_OF_BUFFER/2);
         }
         else
         {
            wordsToRead = wordsWaiting;
         }
            
         for (i = 0; i < (wordsToRead); i++)
         {
            t = VS_readRegister(SCI_HDAT0);
            buffer[2*i] = ((t>>8)&0x00FF);
            buffer[(2*i)+1] = (t&0xFF);
         }

         wordsWaiting -= wordsToRead;
         
         FSfwrite(buffer, 1, 2 * wordsToRead, file);
      }
   }


And the generate file:

4F 67 67 53 00 02 00 00 00 00 00 00 00 00 78 56 34 12 00 00 00 00 B1 6B 91 B6 01 1E 01 76 6F 72 62 69 73 00 00 00 00 01 44 AC 00 00 00 00 00 00 58 2E 01 00 00 00 00 00 B8 01 4F 67 67 53 00 00 00 00 00 00 00 00 00 00 78 56 34 12 01 00 00 00 29 87 CB 3B 01 38 03 76 6F 72 62 69 73 10 00 00 00 56 4C 53 49 20 53 6F 6C 75 74 69 6F 6E 20 4F 79 01 00 00 00 14 00 00 00 45 4E 43 4F 44 45 52 3D 56 53 31 30 35 33 20 76 31 2E 37 30 01 4F 67 67 53 00 00 00 00 00 00 00 00 00 00 78 56 34 12 02 00 00 00 87 7B 55 06 05 FF FF FF FF CE 05 76 6F 72 62 69 73 0D 42 43 56 01 00 40 00 00 26 49 92 24 49 92 24 49 92 24 49 92 2C CB B2 2C CB B2 2C CB B2 2C CB B2 34 4D D3 34 4D D3 34 4D D3 34 4D D3 34 4D D3 34 4D D3 34 4D D3 34 4D D3 80 D0 90 55 00 00 10 00 80 45 51 14 C7 71 1C 49 92 24 CB B2 2C 4D D3 34 CF F3 3C 51 14 45 D3 34 4D 55 55 55 D7 75 5D 59 96 65 DB B6 6D 5D D7 75 DF F7 7D 61 18 86 61 18 86 20 34 64 15 00 00 04 00 60 51 14 C5 71 1C 47 92 24 C9 B2 2C 4B D3 34 CD F3 3C 4F 14 45 D1 34 4D 53 55 55 D5 75 5D 57 96 65 D9 B6 6D 5B D7 75 DD F7 7D 5F 18 86 61 18 86 21 08 0D 59 05 00 00 01 00 58 14 45 71 1C C7 91 24 49 B2 2C CB D2 34 4D F3 3C CF 13 45 51 34 4D D3 54 55 55 75 5D D7 95 65 59 B6 6D DB D6 75 5D F7 7D DF 17 86 61 18 86 61 08 42 43 56 01 00 40 00 00 16 45 51 1C C7 71 24 49 92 2C CB B2 34 4D D3 3C CF F3 44 51 14 4D D3 34 55 55 55 5D D7 75 65 59 96 6D DB B6 75 5D D7 7D DF F7 85 61 18 86 61 18 82 D0 90 15 01 40 14 00 80 CF F3 3C CB F3 3C CF B3 3C CB B1 3C CB F3 3C CF B3 3C CF F3 3C CB B3 1C CB B3 3C CB B1 1C C3 D2 2C CD D3 3C CD F2 3C CF F3 3C CF F3 3C CF F3 3C CF F3 2C CF F3 3C CF F3 3C CF F3 3C 4F 00 00 40 80 03 00 40 80 05 52 68 C8 4A 00 20 03 00 C0 66 39 96 66 39 8A A3 49 8A A2 48 9A E4 48 9A A7 59 9A 27 00 00 60 C0 01 00 20 C0 04 A2 51 68 C8 4A 00 20 06 00 C0 66 59 96 65 69 9A 65 49 96 A5 59 96 E4 48 96 65 49 8E E3 48 96 65 49 92 64 59 9A 65 59 96 A5 69 9A 65 59 9A 26 00 00 70 C0 01 00 20 C0 04 A2 B1 16 1A B2 0A 00 78 00 00 F0 69 96 E4 28 86 A1 38 92 A5 69 9E 00 00 E0 02 07 00 80 00 1B 10 32 54 76 98 BA DC 2E 34 64 15 00 F0 03 00 60 18 86 DF D7 75 DB 96 65 D7 55 55 D3 14 45 CF D3 34 CB 92 24 C7 51 14 45 71 1C 49 B2 2C 4D F3 3C 51 34 4D 55 75 5D 59 B6 6D 5D F7 7D 5F 18 86 01 00 F0 09 0E 00 00 01 56 80 40 18 88 C2 38 90 44 59 98 C6 79 A0 48 9A A8 CA BA B0 4C DB B8 CE FB C0 50 1C C9 D2 3C D1 54 5D D9 D6 7D E1 58 9E E9 DA BE F1 5C DF F9 DE 17 1A B2 12 00 08 07 00 70 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A2 69 9A A6 69 9A A6 69 9A A6 29 8A A2 69 9A A6 69 9A A6 69 9A A2 28 8A A6 69 9A A6 69 9A A6 69 8A A2 25 8A A6 69 9A A6 69 9A A6 28 5A 96 25 8A A6 69 9A A6 69 8A A2 65 59 96 28 8A A6 69 9A A6 28 8A 96 25 58 96 28 8A A6 69 9A A6 28 8A 96 65 89 A2 68 9A A6 69 9A A6 28 8A 96 28 8A A6 69 9A A6 69 9A A6 28 8A A2 68 9A A6 69 9A A6 69 9A A6 28 8A A6 69 9A A6 69 9A A6 69 9A A6 68 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A6 69 9A A6 69 0A 00 4E AC 70 00 10 7E B0 01 21 43 65 87 A9 CB ED 42 43 56 02 00 E1 00 00 5E D7 55 55 55 55 55 55 55 5D D7 75 5D 55 55 55 D5 54 55 55 55 5D D7 55 55 55 55 4D D3 54 55 55 55 5D 55 55 55 D5 34 4D D3 54 55 55 55 55 55 55 4D D3 D4 4C D3 54 55 55 55 55 D5 34 4D 4D D3 4C D3 54 55 55 55 4D D3 D4 34 47 D3 4C D3 54 55 D5 34 4D 4D 73 04 47 D3 4C D3 54 55 D5 34 4D 4D 73 34 D3 34 4D 55 55 55 D5 34 4D 53 33 4D D3 54 55 55 55 55 D5 34 4D D3 34 4D 55 55 55 55 55 55 D5 34 4D D3 54 55 55 55 5D 55 55 55 D5 34 4D 55 55 55 D5 75 5D 55 55 55 D5 54 55 55 55 5D D7 75 5D 55 55 55 55 55 55 D5 75 5D 01 00 A4 0D 0E 00 E0 07 36 20 64 A8 EC 30 75 B9 5D 68 C8 2A 00 E0 01 00 C0 E3 38 8E E3 38 8A E3 38 8E E3 38 02 00 80 0B 1C 00 00 02 6C 40 C8 50 D9 61 EA 72 BB D0 90 95 00 40 0C 00 80 C5 74 65 59 B6 4D C5 91 34 D5 95 1D C5 B1 44 55 96 1C 49 F2 4C D9 B3 2C 4B 13 65 55 F1 34 CD B3 5D 57 35 45 11 00 00 00 41 00 40 83 08 11 91 99 99 19 10 00 04 C0 00 20 F8 48 0C 1A 01 83 82 22 20 A0 16 90 1C 00 10 21 42 44 64 66 66 66 66 06 04 00 01 30 00 08 D6 2F 20 40 0B 01 10 90 D1 91 00 06 30 40 81 11 8C 84 E3 95 07 A9 83 00 00 00 00 00 30 00 80 07 00 00 A3 01 22 22 E2 0A 0C 0E 10 12 14 16 18 02 00 00 00 00 00 06 00 3E 00 00 8C 06 88 88 88 2B 30 38 40 48 50 58 60 08 00 00 00 00 00 00 00 00 00 02 02 02 00 00 00 00 00 01 00 00 00 02 02

End of header sequence
File size: 1400 bytes (700 words)

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

Re: Encoding problem - no data (VS1053b)

Postby pasi » Tue 2012-03-27 14:19

A quick first thing: do not read AIADDR, it can set the samplerate to some low value (8000 Hz).
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Mister110
User
Posts: 9
Joined: Mon 2012-03-26 12:57

Re: Encoding problem - no data (VS1053b)

Postby Mister110 » Tue 2012-03-27 14:50

pasi wrote:A quick first thing: do not read AIADDR, it can set the samplerate to some low value (8000 Hz).


OK, but I never directly read AIADDR register. 0x34 is just the return of my function like it's done with function SpiLoadImageInto1053(inFP) in the "VS1053B OGG VORBIS ENCODER" PDF .

PDF, page 18, chapter 2.4.5 vs1053oggrec.c

Code: Select all

/* Load the recorder application to VS1053
This source code uses .img image files for loading.
If you use .plg files, use the source as described
in the VS1053b Ogg Vorbis Encoder application manual. */
inFP = fopen("venc44k2q05.img", "rb");
if (!inFP)
goto end;
pluginStartAddr = SpiLoadImageInto1053(inFP);
fclose(inFP);


I wrote these details about 0x34 to say that there's probably no problem with the plugin .

Something that I forgot to tell: I'm working with a Microchip PIC18f46j50.

Mister110
User
Posts: 9
Joined: Mon 2012-03-26 12:57

Re: Encoding problem - no data (VS1053b)

Postby Mister110 » Fri 2012-03-30 15:31

Hi everyone,

My problem is still not fixed and I wonder if there's a hardware problem with my VS1053b decoder/encoder.

This, because I can read and send ogg file's header from the buffer (apparently, this header is correct) but no data come afterward.

Do you think that it could be a hardware problem with my encoder?

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

Re: Encoding problem - no data (VS1053b)

Postby pasi » Sat 2012-03-31 11:35

One thing that comes to mind is that the Vox pause mode has been somehow activated. Are you using a profile, which supports Vox/Pause?

Try writing 0x180f to WRAMADDR, then 2 to WRAM.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Mister110
User
Posts: 9
Joined: Mon 2012-03-26 12:57

Re: Encoding problem - no data (VS1053b)

Postby Mister110 » Mon 2012-04-02 12:23

pasi wrote:One thing that comes to mind is that the Vox pause mode has been somehow activated. Are you using a profile, which supports Vox/Pause?

Try writing 0x180f to WRAMADDR, then 2 to WRAM.


Yes, I'm using a profil wich supports Vox/Pause. I tried to write 0x180f to WRAMADDR, then 2 to WRAM, but the problem isn't solved. No data is waiting in the buffer.

My status report:

- I can play ogg'files (decoder is OK)
- I can activate the microphone (and hear my voice via the encoder/decoder)
- I can send the plugin via the encoder
- I can't record anything because no data is waiting in the buffer

Mister110
User
Posts: 9
Joined: Mon 2012-03-26 12:57

Re: Encoding problem - no data (VS1053b)

Postby Mister110 » Tue 2012-04-03 16:27

I tried also with a plugin wich don't support VOX/pause but the problem is the same.

Could somebody tell me if there's something wrong in my code? If it could be a hardware problem wich execute everything except encoding?

I'm a little lost...

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

Re: Encoding problem - no data (VS1053b)

Postby pasi » Tue 2012-04-03 21:58

I don't see anything suspicious in your code.

How long are you waiting (probably indefinitely)? 4kB of Ogg Vorbis can take a while to appear if you are using low bitrates.

How does your VS_readRegister() look like? Do you see AICTRL0 changing? How is DREQ behaving?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Mister110
User
Posts: 9
Joined: Mon 2012-03-26 12:57

Re: Encoding problem - no data (VS1053b)

Postby Mister110 » Wed 2012-04-04 16:18

pasi wrote:I don't see anything suspicious in your code.

How long are you waiting (probably indefinitely)? 4kB of Ogg Vorbis can take a while to appear if you are using low bitrates.

How does your VS_readRegister() look like? Do you see AICTRL0 changing? How is DREQ behaving?


Thank you for checking my code...

Exactly, I'm waiting indefinitely, but I've always no data in buffer. Even if I wait during 30-40sec or more.

For my VS_readRegister(), I put the code just below, but I don't think there's any problem with this function because I'm using it when I'm reading SCI_HDAT1 register (to read how many data are waiting in buffer): it returns apparently a good value when the ogg's header is waiting, because this function tells me that 699 words are in the buffer.

I can read and write these 699 words so I haven't any problem reading AICTRL0 register. This register's value changes as you can see in my first message (the generated file). The DREQ behavior seems to be OK for the same reason.

Code: Select all

unsigned int VS_readRegister(unsigned char register_addr)
{
   unsigned int returnVal;
   unsigned char original_D_REQ, original_INT0IE, i;
   
   //save original value
   original_D_REQ = VS_DREQ;
   original_INT0IE = INTCONbits.INT0IE;
   
   VS_XCS = 0;  //Chip select goes to '0'

   INTCONbits.INT0IE = 0;      //INT0 disable cleared

   WriteSPIM(SCI_READ_CMD);
   WriteSPIM(register_addr);
   returnVal = (((unsigned int)ReadSPIM())<<8)&0xFF00;
   returnVal |= ReadSPIM();
   
   VS_XCS = 1;  //Chip select goes to '1'

   while(!VS_DREQ)
   {
      i++;

      if (i >= 10)
      {
         break;
      }
   }

   if (original_D_REQ)
   {
      INTCONbits.INT0IF = 0;      //INT0 flag cleared
   }   
   
   INTCONbits.INT0IE = original_INT0IE;
   
   return returnVal;
}

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

Re: Encoding problem - no data (VS1053b)

Postby pasi » Fri 2012-04-06 1:14

Mister110 wrote:I can read and write these 699 words so I haven't any problem reading AICTRL0 register.


I mean do the VU meter values change in AICTRL0?

And you do get the line /mic input signal played at the left+right outputs?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook


Return to “DSP and Audio Software”

Who is online

Users browsing this forum: No registered users