VS1053b recording file does not play

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
Post Reply
Koyh
User
Posts: 5
Joined: Mon 2017-10-23 0:50

VS1053b recording file does not play

Post by Koyh » Mon 2017-10-23 9:57

Hello,

I would like to record in ADPCM in my project and play it on my computer.

The problem is that the wav file does not play.

The wav file causes the following error code in the Groove Player for Windows 10: 0xc00d5213

My header file is as follows.

Do you have any idea what I'm doing wrong?

Code: Select all

//ATMEGA128
unsigned char adpcm0[504] = {
  'R', 'I', 'F', 'F',
  0x70, 0X70, 0X70, 0X70,
  'W', 'A', 'V', 'E',
  'f', 'm', 't', ' ',
  0x14, 0, 0, 0,          /* 20 */
  0x11, 0,                /* IMA ADPCM */
  0x01, 0,                 /* chan */
  0x0, 0x0, 0x0, 0x0,     /* sampleRate */
  0x0, 0x0, 0x0, 0x0,     /* byteRate */
  0, 1,                   /* blockAlign */
  4, 0,                   /* bitsPerSample */
  2, 0,                   /* byteExtraData */
  0xf9, 0x1,              /* samplesPerBlock = 505 */
  'f', 'a', 'c', 't',     /* subChunk2Id */
  0xc8, 0x01, 0, 0,           /* subChunk2Size */
  0xFF, 0xFF, 0xFF, 0xFF, /* numOfSamples */
  
};

const unsigned char adpcm504[]={
  'd', 'a', 't', 'a',
  0xFF, 0xFF, 0xFF, 0xFF
};

void recordtest(){
    unsigned char *rbp=file.buf;
    int i,k,j=0,l; 

    vs_write(0x0c,8000);
    vs_write(0x0d,0);
    vs_write(0x0e,4096);
    vs_write(0x0f,0); 
    delay_ms(500);
    
    create_file();
    
    //header file write
    
    set16(adpcm0+22,1);
    set32(adpcm0+24,8000);
    set32(adpcm0+28,8000*2*256/505);
    set16(adpcm0+32,512);
    
    for(i=52;i<504;i++){
        adpcm0[i]=0;
    }
    
    f_write(&file,adpcm0,sizeof(adpcm0),&nbyte);
    
    vs_write(0x00,(0<<14)|(1<<12)|(1<<2));
    delay_ms(500);
    LoadPlugin(plugin,sizeof(plugin)/sizeof(plugin[0]));
    delay_ms(500);
    
    f_lseek(&file,512);
    while(1){
                                                       
        if(vs_read1(0x09)>512){
            rbp=file.buf;
            for(i=0;i<256;i++){
                k=vs_read1(0x08);
                *rbp++=(unsigned char)(k&0xff);
                *rbp++=(unsigned char)(k>>8);
            }
            
            f_write(&file,file.buf,sizeof(file.buf),&nbyte);
            j++;          
        }
        delay_us(100);
        if((!sw2)) break;
    }
    
    vs_write(0x00,(1<<2));
    delay_ms(100);

    f_lseek(&file,0);
    
    set32(adpcm0+4, j*512+52);
    set32(adpcm0+48, j*505);
    f_write(&file,adpcm0,sizeof(adpcm0),&nbyte);
    
    set32(adpcm504+4, j*512);
    f_write(&file,adpcm504,sizeof(adpcm504),&nbyte);
    
    vs_write(0x00,(1<<2));
    
    f_close(&file))==FR_OK);
    while(1);
}
Attachments
HEADER.PNG
HEADER.PNG (25.22 KiB) Viewed 767 times

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

Re: VS1053b recording file does not play

Post by pasi » Mon 2017-10-23 10:39

Can you attach your file?

It looks like you only update two bytes of the 4-byte fields (chunk sizes and number of samples), or you have a sign-extension or some other arithmetic issue in your code that causes the 2 most-significant bytes to become 0xff. Check your set32() function.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Koyh
User
Posts: 5
Joined: Mon 2017-10-23 0:50

Re: VS1053b recording file does not play

Post by Koyh » Mon 2017-10-23 12:09

Hello,

thanks a lot for your answers.

My set32 () function looks like this:

Code: Select all

void set32(unsigned char *d,unsigned long n){
    int i;
    for(i=0;i<4;i++){
        *d++ = n;
        n>>=8;
    }
}
I also attach my wav file. Is this what you demanded?
Attachments
rec01.wav
(19.5 KiB) Downloaded 25 times

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

Re: VS1053b recording file does not play

Post by pasi » Mon 2017-10-23 16:20

That set32() seems to work now.

The IMA ADPCM frames seem broken. The third byte of each frame should be 0x00.

You may have:
1. byte/word mismatch - are you reading the correct number of words from SCI_HDAT?
2. your read/save/storage is too slow, so you miss some data.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Koyh
User
Posts: 5
Joined: Mon 2017-10-23 0:50

Re: VS1053b recording file does not play

Post by Koyh » Tue 2017-10-24 4:51

The header file issue has been fixed!

The variable j used in the set32 () function was a problem. This changes the data type of the variable j to 32
bit.

But I have faced new problems ...

It is estimated that there is a problem with the recorded data.

Attach the modified source and wav file.

Code: Select all

void recordtest(){
    unsigned char *rbp=file.buf;
    int i,j=0; 
    int hdat1;
    long file_s;
    unsigned int k;

    vs_write(0x0c,0x0009);
    vs_write(0x0d,0x1000); 
    //vs_write(0x0c,samplerate);
    //vs_write(0x0d,0);
    //vs_write(0x0e,4096);
    //vs_write(0x0f,0); 
    delay_ms(500);
    
    create_file();
    
    //header file write
    
    set16(adpcm0+22,1);
    set32(adpcm0+24,samplerate);
    set32(adpcm0+28,0x00000fd7);
    set16(adpcm0+32,256*chan);
    
    for(i=52;i<504;i++){
        adpcm0[i]='0';
    }
    
    f_write(&file,adpcm0,sizeof(adpcm0),&nbyte);
    
    vs_write(0x00,(0<<14)|(1<<12)|(1<<2));
    delay_ms(500);
    LoadPlugin(plugin,sizeof(plugin)/sizeof(plugin[0]));
    delay_ms(500);
    
    f_lseek(&file,512);
    while(1){
    
        hdat1=vs_read1(0x09);                                               
        if(hdat1>=256 && hdat1<896){
            rbp=file.buf;
            for(i=0;i<256;i++){
                k=vs_read1(0x08);
                *rbp++=(unsigned char)(k>>8);
                *rbp++=(unsigned char)(k&0xff);
            }
            
            if((res=f_write(&file,file.buf,sizeof(file.buf),&nbyte))==FR_OK) j++;
            else error(res);           
        }
        //delay_us(100);
        if((!sw2)) break;
    }
    //file_s=(j+1)*chan*256;
    vs_write(0x00,(1<<2));
    delay_ms(100);

    f_lseek(&file,0);
    
    set32(adpcm0+4, ((long)j+(2/chan))*chan*256-8);
    set32(adpcm0+48, (long)j*505);
    f_write(&file,adpcm0,sizeof(adpcm0),&nbyte);     

    set32(adpcm504+4, (long)j*chan*256);
    f_write(&file,adpcm504,sizeof(adpcm504),&nbyte);
    
    vs_write(0x00,(1<<2));
    
    if((res=f_close(&file))==FR_OK){
        sprintf(text,"File Closed");
        glcd_outtextxy(0,0,text);
    }else error(res);
    printf("\n\r\n\r%d\n\r",j);
    while(1);
}
Attachments
rec01.wav
(107.5 KiB) Downloaded 25 times

Koyh
User
Posts: 5
Joined: Mon 2017-10-23 0:50

Re: VS1053b recording file does not play

Post by Koyh » Tue 2017-10-24 10:23

Hello.

Fortunately, the above problem has been solved, but a new problem has occurred.

WAV files can be recorded and played back, but recording
File noise is very large.

The modified sources are:

Is there a problem with the header file?

(Please note playback, noise is very large)

I am using a oscillator with a frequency of 12.288 MHz.

Code: Select all



void vs_init (void)
{                                  
    //SPI_Mode0();
    //VS1033_io_Init();
    vs_reset();

    vs_read(0x00);

    vs_write(0x03, 0x6000);
}

void recordtest(){
    unsigned char *rbp=file.buf;
    int i,j=0; 
    unsigned int hdat1=0;
    unsigned int k;
 
    vs_write(0x0c,samplerate); //16000hz
    vs_write(0x0d,0);          //auto gain
    vs_write(0x0e,4096);       //maximum autogain amplification
    vs_write(0x0f,0);          //joint stereo(common AGC)
    delay_ms(500);
    
    create_file();             //Create file to SD Card and Open File
    
    set32(adpcm0+24,samplerate);                //set header Samplerate
    set32(adpcm0+28,samplerate*chan*256/505);   //set header Byterate
    set16(adpcm0+32,256*chan);                  //set header BlockAlign
    
    for(i=52;i<504;i++){
        adpcm0[i]='0';
    }
    
    f_write(&file,adpcm0,sizeof(adpcm0),&nbyte);
    
    vs_write(0x00,(0<<14)|(1<<12)|(1<<2));               //SM_LINE1:MICP, SM_ADPCM:yes, SM_RESET:reset, 
    delay_ms(100);
    LoadPlugin(plugin,sizeof(plugin)/sizeof(plugin[0])); //patch plugin
    delay_ms(100);
    
    f_lseek(&file,512); //go to 512byte .
                        
    while(1){
    
        hdat1=vs_read1(0x09);                  				//read HDAT1                                             
        if(hdat1>=512 && hdat1<896){
            rbp=file.buf;
            for(i=0;i<256;i++){
                k=vs_read1(0x08);
                *rbp++=(unsigned char)(k>>8);
                *rbp++=(unsigned char)(k&0xff);
            }
            f_write(&file,file.buf,sizeof(file.buf),&nbyte);
            j++;                                    					//audioblock++
       
        }
        if((!sw2)) break;
    }

    f_lseek(&file,0);                               				//go to 0byte
    
    set32(adpcm0+4, ((long)j+(2/chan))*chan*256-8); //set header ChunkSize(filesize -8)
    set32(adpcm0+48, (long)j*chan*505);             //set header NumOfSamples
    f_write(&file,adpcm0,sizeof(adpcm0),&nbyte);     
    
    set32(adpcm504+4, (long)j*chan*256);            //set header SubChunk3Size(Data size)
    f_write(&file,adpcm504,sizeof(adpcm504),&nbyte);
    
    vs_write(0x00,(1<<2));                         //SM_RESET:reset
    
    if((res=f_close(&file))==FR_OK){
        sprintf(text,"File Closed");
        glcd_outtextxy(0,0,text);
    }else error(res);
    printf("\n\r\n\r%d\n\r",j);
    while(1);
}
Attachments
rec01.wav
(55 KiB) Downloaded 27 times

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

Re: VS1053b recording file does not play

Post by pasi » Tue 2017-10-24 16:49

Something really strange is going on.

The data looks good. The linear sample and state look good at the beginning of each frame, and then the amplitude just gets out of control during each frame. The left channel has the mic amplifier on, and the output corresponds to that - the left channel gets out of control much faster.

It would be explained by sign-extension or transfer issues.

What's your SPI clock speed? Also check the SPI mode.

Could you try a lower samplerate, 1 channel, and/or linear PCM?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Koyh
User
Posts: 5
Joined: Mon 2017-10-23 0:50

Re: VS1053b recording file does not play

Post by Koyh » Fri 2017-10-27 9:25

The recording operation now works perfectly.

Many thanks for your help.

But I have a new problem.

The mp3 player does not work properly.

 It worked perfectly before I created the recording source, but it does not work right now.

This source does not work during normal MCU reset.

It only worked when the power supply was stopped for more than 5 seconds and then the power was supplied again.

I thought of the register setting problem of VS1053b and confirmed the register value.

1. When operating, the register values ​​are as follows.

0x0 (SCI_MODE): 0X4800
0X1 (STATUS): 0x0048
0X5 (AUDATA): 0x1F40

2. When not operating, the register values ​​are as follows.

0x0 (SCI_MODE): 0x4890
0X1 (STATUS): 0x0040
0X5 (AUDATA): 0xAC45

3. When register value is forced by 1, the register value is as follows.

0x0 (SCI_MODE): 0x4800
0X1 (STATUS): 0x0048
0X5 (AUDATA): 0x1F41

This also does not work.

What is the problem?

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

Re: VS1053b recording file does not play

Post by pasi » Fri 2017-10-27 13:31

You have accidentally entered the real-time MIDI mode. Probably your GPIO0 and/or GPIO1 are floating. Pull both to GND.

(Also, don't write 0x48 to SCI_STATUS. It will turn off analog drivers.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

Post Reply