Page 1 of 1

VS1053 record OOG silent

Posted: Tue 2019-09-17 7:02
by tuyenpham
Dear all,
I'm using vs1053 evm board. I can play file audio well. But when i record oog file then i can open by Window Media but it's only heard "buzz buzz".
This is my setup. please give me a recommence
The kit
https://www.flipkart.com/kitsguru-vs105 ... x8tmxmpva8
Firmware setup
/* Set clock to a known, high value. */
VS1003_WriteReg(SPI_CLOCKF, 0xC000);
while( MP3_DREQ ==0 );
reg = VS1003_ReadReg(SPI_CLOCKF);
printf("SPI_CLOCKF: %x <====\r\n", reg);
/* Ogg Vorbis recording from line in. */
/* Clear SCI_BASS */
VS1003_WriteReg(SPI_BASS, 0);

/* First reset VS1053 to remove any patches. */
// reg = VS1003_ReadReg(SPI_MODE);
// printf("reg 1: %x <====\r\n", reg);
VS1003_WriteReg(SPI_MODE, SM_SDINEW | SM_RESET);
while( MP3_DREQ ==0 );
// reg = VS1003_ReadReg(SPI_MODE);
// printf("SPI_MODE: %x <====\r\n", reg);
/* Disable interrupts as instructed in the VS1053b Ogg Vorbis Encoder
documentation. */
// WriteVS10xxMem(0xc01a, 0x2);
VS1003_WriteReg(SPI_WRAMADDR, 0xc01a);
reg = VS1003_ReadReg(SPI_WRAMADDR);
printf("SPI_WRAMADDR: %x <====\r\n", reg);

VS1003_WriteReg(SPI_WRAM, 0x02);
reg = VS1003_ReadReg(SPI_WRAM);
printf("SPI_WRAM: %x <====\r\n", reg);
//load plugin
plugin_start = vs1053_prepare_record_ogg("profiles/venc08k1q05.img");
printf("pluginStartAddr %x \r\n",plugin_start); //Get 0x34!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

ff_result = f_open(&file, file_name, FA_CREATE_ALWAYS | FA_WRITE);
if (ff_result != FR_OK)
{
printf("Unable to open or create file: %s\r\n", file_name);
return;
}
printf("Created file %s ok --> Starting recording\r\n", file_name);
/* Turn SCI_MODE bits. */
// printf("TEST: %x\r\n", (~SM_LINE1));
VS1003_WriteReg(SPI_MODE, SM_SDINEW | SM_ADPCM);
// VS1003_WriteReg(SPI_MODE, SM_SDINEW | SM_ADPCM | SM_LINE1);
while( MP3_DREQ ==0 );
reg = VS1003_ReadReg(SPI_MODE);
printf("SPI_MODE: %x <====\r\n", reg);

/* Reset VU meter */
VS1003_WriteReg(SPI_AICTRL0, 0x8080);
VS1003_WriteReg(SPI_AICTRL1, 1024); /* 1024 = gain 1 = best quality */
reg = VS1003_ReadReg(SPI_AICTRL1);
printf("SPI_AICTRL1: %x <====\r\n", reg);

VS1003_WriteReg(SPI_AICTRL2, 0);
reg = VS1003_ReadReg(SPI_AICTRL2);
printf("SPI_AICTRL2: %x <====\r\n", reg);

VS1003_WriteReg(SPI_AICTRL3, 0);
reg = VS1003_ReadReg(SPI_AICTRL3);
printf("SPI_AICTRL3: %x <====\r\n", reg);

VS1003_WriteReg(SPI_AIADDR, plugin_start);
while( MP3_DREQ ==0 );
reg = VS1003_ReadReg(SPI_AIADDR);
printf("SPI_AIADDR: %x <====\r\n", reg); //It show 0 ???????????????????????????????????????????????????????????
/* Activate recording */
// VS1003_WriteReg(SPI_AIADDR, 0x34);

/* Check what samplerate the plugin is running the ADC. This is not
necessarily the same as recording samplerate. E.g. at a 44100 Hz
profile this will read as 48000 Hz. */
sampleRate = VS1003_ReadReg(SPI_AUDATA) & ~1;
printf("sampleRate: %d <=====\r\n", sampleRate);


// VS1003_Record_Init();

//start recording
set_record_time(0);
// while(get_record_time() < 10) /* ֹͣ¼Òô */
while (state < 3)
{
/* Check when to end recording. The function EndRecording() is
microcontroller specific and should be implementing separately
for each application. */
if (EndRecording() && !state)
{
printf("End\r\n");
state = 1;
VS1003_WriteReg(SPI_AICTRL3, 1); // Send VS1053 request to stop recording
}
/* See how many 16-bit words there are waiting in the VS1053 buffer */
wordsWaiting = VS1003_ReadReg(SPI_HDAT1);

/* If user has requested stopping recording, and VS1053 has
stopped recording, proceed to the next state. */
if (state == 1 && VS1003_ReadReg(SPI_AICTRL3) & (1<<1))
{
printf("state = 2\r\n");
state = 2;
/* It is important to reread the HDAT1 register once after
VS1053 has stopped. Otherwise there is the chance that
a few more words have just arrived although we just
read this register. So, do NOT optimize the following
line away! */
wordsWaiting = VS1003_ReadReg(SPI_HDAT1);
}

/* Read and transfer whole 512-byte (256-word) disc blocks at
the time. The only exception is when recording ends: then
allow for a non-full block. */
while (wordsWaiting >= ((state < 2) ? 256 : 1))
{
wordsToRead = min(wordsWaiting, 256);
wordsWaiting -= wordsToRead;

/* If this is the very last block, read one 16-bit word less,
because it will be handled later separately. */
if (state == 2 && !wordsWaiting)
wordsToRead--;
/* Transfer one full data block, or if this is the very last
block, all data that's left except for the last word. */
{
uint16_t i;
uint16_t t;
dataBufPtr = buffer;

// printf("wordsToRead: %d\r\n", wordsToRead);
for (i=0; i < wordsToRead; i++)
{
t = VS1003_ReadReg(SPI_HDAT0);
*dataBufPtr++ = (uint8_t)(t >> 8);
*dataBufPtr++ = (uint8_t)(t & 0xFF);
// f_write(&file, buffer, 2, &br);
// hi = (uint8_t)(t >> 8);
// lo = (uint8_t)(t & 0xFF);
// f_write(&file, &hi, 1, &br);
// f_write(&file, &lo, 1, &br);
// fputc(t >> 8 , &file);
// fputc(t & 0xFF, &file);
}
f_write( &file, buffer, sizeof(buffer) , &br );
}

/* If this is the last data block... */
if (wordsToRead < 256)
{
printf("state = 3\r\n");
state = 3;

/* ... read the very last word of the file */
lastWord = VS1003_ReadReg(SPI_HDAT0);

/* Always write first half of the last word. */
// fputc(lastWord >> 8 , outFP);
buffer[0] = lastWord >> 8;
f_write(&file, buffer, 1, &br);

/* Read twice SCI_AICTRL3, then check bit 2 of latter read. */
VS1003_ReadReg(SPI_AICTRL3);
if (!(VS1003_ReadReg(SPI_AICTRL3) & (1<<2)))
{
/* Write last half of the last word only if bit 2 is clear. */
// fputc(lastWord & 0xFF, outFP);
buffer[0] = lastWord & 0xFF;
f_write(&file, buffer, 1, &br);
}
} /* if (wordsToRead < 256) */
} /* while (wordsWaiting >= ((state < 2) ? 256 : 1)) */

}

VS1003_WriteReg(SPI_MODE, SM_SDINEW | SM_RESET);

// VS1003_WriteReg(SPI_AICTRL3, 1); // Send VS1053 request to stop recordin


f_close(&file);
printf("Record Completed\r\n");

regrads

Re: VS1053 record OOG silent

Posted: Tue 2019-09-17 14:14
by pasi
tuyenpham wrote:
Tue 2019-09-17 7:02

Code: Select all

    VS1003_WriteReg(SPI_WRAMADDR, 0xc01a);
    reg = VS1003_ReadReg(SPI_WRAMADDR);
    printf("SPI_WRAMADDR: %x <====\r\n", reg); 

    VS1003_WriteReg(SPI_WRAM, 0x02);
    reg = VS1003_ReadReg(SPI_WRAM);
    printf("SPI_WRAM: %x <====\r\n", reg);
Note that writing and reading SPI_WRAM autoincrements the address, so you are not reading the 0xc01a address where you wrote the 0x02. (You're reading from 0xc01b INT_GLOB_DIS, which may or may not be a problem.)

Can you attach an example .ogg file?

Re: VS1053 record OOG silent

Posted: Wed 2019-09-18 3:59
by tuyenpham
Thanks Pasi,
I only wold like debug all register setup. About SPI_WRAMADDR and SPI_WRAM read/write value same. But SPI_AIADDR then is not same, I wrote 0x34 to this register but get 0x00 when read. Is it normal?
BTW, I had some question.
how to check whether we can load plugin is ok?
Plugin file in format .img and .plg are same?
Do we need load any patch for oog record?
I also attach my record oog file. Please help to check

Re: VS1053 record OOG silent

Posted: Wed 2019-09-18 9:10
by pasi
tuyenpham wrote:
Wed 2019-09-18 3:59
But SPI_AIADDR then is not same, I wrote 0x34 to this register but get 0x00 when read. Is it normal?
You write 0x34 to start the application. The application intentionally clears the value after starting, so reading back 0x0000 is ok. However, reading SPI_AIADDR seems to cause a call to AudioSet(), which could interfere with the Ogg Encoder application, for example set the DAC samplerate to an unexpected value. I recommend not reading from SPI_AIADDR.
tuyenpham wrote:
Wed 2019-09-18 3:59
how to check whether we can load plugin is ok?
You seem to get a valid Ogg Vorbis file (except the last block flag is not set, so there probably is something wrong when you end recording), so it seems the plugin has been loaded correctly.

You can verify the correct loading by loading the code without starting it, then going through the loading tables or plugin again, but instead of writing to WRAM, you read from WRAM and compare to the value - you do perform the writes to other registers including WRAMADDR during the verify.
tuyenpham wrote:
Wed 2019-09-18 3:59
Plugin file in format .img and .plg are same?
Do we need load any patch for oog record?
The .img version is a SPI boot image, and .plg is loadable through SCI. You only need the encoding application, you do not need any patches. (The application uses all of the memory anyway.)

So, your record.ogg is (almost) a valid Ogg Vorbis file, so the issue is probably in the microphone connection or (software) gain control.

Re: VS1053 record OOG silent

Posted: Tue 2019-09-24 10:41
by tuyenpham
Hi Pasi,
I don't know why must enable bit SM_LINE1 while i'm using microphone recording input???
VS1003_WriteReg(SPI_MODE, SM_SDINEW | SM_ADPCM); ---> Not working
VS1003_WriteReg(SPI_MODE, SM_SDINEW | SM_ADPCM | SM_LINE1); --> Working
The EVB kit have something wrong???
regards,
Tuyen

Re: VS1053 record OOG silent

Posted: Tue 2019-09-24 14:46
by pasi
tuyenpham wrote:
Tue 2019-09-24 10:41
I don't know why must enable bit SM_LINE1 while i'm using microphone recording input???
Check pins 1 and 2 of the vs1053. If they are accidentally connected together (e.g. too much solder), it would explain what you see. (I.e. If MICP and MICN are shorted, when microphone amp is selected, MICP and MICN follow each other, thus no signal, and when line input is selected, only MICP/LINE1 pin is considered and you get signal - but much lower level signal.)

Re: VS1053 record OOG silent

Posted: Thu 2019-09-26 8:20
by tuyenpham
Hi Pasi,
That weird, MICN and MICP not shorted at all. It seem hw is ok. I also isolate jack line-in but the issue still remain.

regards

Re: VS1053 record OOG silent

Posted: Thu 2019-09-26 9:25
by pasi
Yes, strange.

SM_LINE1 is a hardware bit. It directly switches between using a mic amplifier (MICP + MICN) and not using mic amplifier (LINE1).

It could also be a co-incidence. After each recording you should give a hardware reset, otherwise it is possible the ADC channels get swapped when the ADC gets reinitialized. This would route the (unconnected?) LINE2 to LINE1/MIC, producing no audio.