how to record my voice in Vs1003?

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
mf1364
Senior User
Posts: 25
Joined: Sun 2012-09-02 7:53

Re: how to record my voice in Vs1003?

Post by mf1364 » Mon 2014-05-26 14:31

thanks
my problem is that I am recording just one block and I don't know how continue recording for long time could you please learn me by an example ? if you can put for me codes is so appreciated

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

Re: how to record my voice in Vs1003?

Post by Panu » Mon 2014-05-26 19:29

Maybe you can share your code and I can show how you can change it?

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

cluster
User
Posts: 7
Joined: Tue 2013-12-17 14:15

Re: how to record my voice in Vs1003?

Post by cluster » Tue 2014-05-27 10:27

Panu wrote:Ok we can do it step by step.

First create a file on the SD card. Write this data into the file:

Code: Select all

const unsigned char RIFFHeader0[] = {
 'R' , 'I' , 'F' , 'F' , // Chunk ID (RIFF)
 0x70, 0x70, 0x70, 0x70, // Chunk payload size (calculate after rec!)
 'W' , 'A' , 'V' , 'E' , // RIFF resource format type
 
 'f' , 'm' , 't' , ' ' , // Chunk ID (fmt )
 0x14, 0x00, 0x00, 0x00, // Chunk payload size (0x14 = 20 bytes)
 0x11, 0x00,             // Format Tag (IMA ADPCM)
 0x01, 0x00,             // Channels (1)
 0x80, 0x3e, 0x00, 0x00, // Sample Rate, 0x3e80 = 16.0kHz
 0xd7, 0x0f, 0x00, 0x00, // Average Bytes Per Second
 0x00, 0x01,             // Data Block Size (256 bytes) 
 0x04, 0x00,             // ADPCM encoded bits per sample (4 bits)
 0x02, 0x00,             // Extra data (2 bytes)
 0xf9, 0x01,             // Samples per Block (505 samples)
 
 'f' , 'a' , 'c' , 't' , // Chunk ID (fact)
 0xc8, 0x01, 0x00, 0x00, // Chunk payload size (456 bytes (zeropad!))
 0xff, 0xff, 0xff, 0xff  // Number of Samples (calculate after rec!)
 };
Then add 448 bytes of zero to the file. Then add this data to the file.

Code: Select all

const unsigned char RIFFHeader504[] = {
 'd' , 'a' , 't' , 'a' , // Chunk ID (data)
 0x70, 0x70, 0x70, 0x70  // Chunk payload size (calculate after rec!)
 };
 
There should now be 512 bytes of data in the file.

Let's continue after you have completed this step.

-Panu
Hello Panu,

I tried to record voice and used the below header but when i try to play it window media player is unable to recognize it. Also can you please tell how is headers 512 bytes long? i calculated and it comes out to be 508 bytes

Code: Select all

const unsigned char header[]={
   'R' , 'I' , 'F' , 'F' , // Chunk ID (RIFF)
   0x70, 0x70, 0x70, 0x70, // Chunk payload size (calculate after rec!)
   'W' , 'A' , 'V' , 'E' , // RIFF resource format type

   'f' , 'm' , 't' , ' ' , // Chunk ID (fmt )
   0x14, 0x00, 0x00, 0x00, // Chunk payload size (0x14 = 20 bytes)
   0x11, 0x00,             // Format Tag (IMA ADPCM)
   0x01, 0x00,             // Channels (1)
   0x80, 0x3e, 0x00, 0x00, // Sample Rate, 0x3e80 = 16.0kHz
   0xd7, 0x0f, 0x00, 0x00, // Average Bytes Per Second
   0x00, 0x01,             // Data Block Size (256 bytes)
   0x04, 0x00,             // ADPCM encoded bits per sample (4 bits)
   0x02, 0x00,             // Extra data (2 bytes)
   0xf9, 0x01,             // Samples per Block (505 samples)

   'f' , 'a' , 'c' , 't' , // Chunk ID (fact)
   0xc8, 0x01, 0x00, 0x00, // Chunk payload size (456 bytes (zeropad!))
   0xff, 0xff, 0xff, 0xff,  // Number of Samples (calculate after rec!)
   0x00, 0x00, 0x00, 0x00, // Insert 448 zeroes here!
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
'd' , 'a' , 't' , 'a' , // Chunk ID (data)
0x70, 0x70, 0x70, 0x70  // Chunk payload size (calculate after rec!)
};
this is the code for reading, temp_buffer stores about 31KB of data

Code: Select all

void cpyADPCMHeader(char * buffer) {
    //strcpy(buffer, header);
    int temp = 0;
    for(temp=0; temp<508; temp++) {
        buffer[temp] = header[temp];
    }
}

void VSRecordOn() {
    //setVSRegister(SPI_VS_CLOCKF, 0x68, 0x48);
    setVSRegister(SPI_VS_AICTRL0, 0x00, 0x06);
    //setVSRegister(SPI_VS_AICTRL0, 0x00, 0x09);
    setVSRegister(SPI_VS_AICTRL1, 0x10, 0x00);
    setVSRegister(SPI_VS_MODE, 0x18, 0x04);
}

cpyADPCMHeader(&temp_buffer);
    temp_buffer_counter = 508;
    VSRecordOn();
    while(temp_buffer_counter<30743) {
        temp_len = 0;
        while(temp_len < 256 || temp_len >= 896) {
            temp_len = getVSRegister(0x09);
        }
        for(temp=0; temp<temp_len; temp++) {
            temp_data = getVSRegister(0x08);
            temp_buffer[temp_buffer_counter] = temp_data >> 8;
            temp_buffer_counter++;
            temp_buffer[temp_buffer_counter] = temp_data&255;
            temp_buffer_counter++;
        }
    }
    VSReset();
Attachments
RECORD.WAV
(30.5 KiB) Downloaded 235 times

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

Re: how to record my voice in Vs1003?

Post by Panu » Tue 2014-05-27 16:40

Hi!

Hmmh, I am not sure. Perhaps I miscalculated the number of zero padding required? I added 4 more zeros so that the data chunk starts at offset 504 and now your file plays. I can hear you tapping someting :)

-Panu
Attachments
RECORD.WAV
Fixed :)
(30.5 KiB) Downloaded 256 times
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

cluster
User
Posts: 7
Joined: Tue 2013-12-17 14:15

Re: how to record my voice in Vs1003?

Post by cluster » Wed 2014-05-28 2:31

Thank You!
I have just one more question is it possible to force VS1003 to output mono instead of stereo? I want to connect a single (mono) amplifier with vs1003, how should i connect it? should i simply short left and right channel and use as one channel?

thanks

mf1364
Senior User
Posts: 25
Joined: Sun 2012-09-02 7:53

Re: how to record my voice in Vs1003?

Post by mf1364 » Wed 2014-05-28 7:16

Panu wrote:Maybe you can share your code and I can show how you can change it?

-Panu

I used that codes that I put in several days ago (please refer to post "Thu May 22, 2014 11:12 am") and you said the header isn't same by your header, notice I used your header but it didn't work! so I use myself header codes, and with that software I can record WAV till 75kb so just tell me which filed of header file I should change till can record for example 150kb? notice if you can give me some example for different file size is so appreciated

mf1364
Senior User
Posts: 25
Joined: Sun 2012-09-02 7:53

Re: how to record my voice in Vs1003?

Post by mf1364 » Sat 2014-05-31 13:01

Hi every body
I could record different WAV file size by changing the amount of Chunk size and subchunk3 size, that was too easy. in the following I have two question, please guide me
1- how can I distinguish the volume of wav file after recording if I want to change the header file after recording ?
2- during recording,there is an Echo and I can hear my voice from speaker while recording so I would like to know how can I cancel Echo due to not to hear my voice from speaker while I am recording
fast reply is too appreciated.

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

Re: how to record my voice in Vs1003?

Post by Panu » Mon 2014-06-02 19:28

Hi!

To not hear the echo, write to VOLUME register (set volume low)

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

mf1364
Senior User
Posts: 25
Joined: Sun 2012-09-02 7:53

Re: how to record my voice in Vs1003?

Post by mf1364 » Tue 2014-06-03 11:44

Panu wrote:Hi!

To not hear the echo, write to VOLUME register (set volume low)

-Panu
Mr Panu
thank you very much I removed Echo but how about my first question?
1- how can I distinguish the volume of wav file after recording if I want to change the header file after recording ?

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

Re: how to record my voice in Vs1003?

Post by Panu » Tue 2014-06-03 15:25

1- how can I distinguish the volume of wav file after recording if I want to change the header file after recording ?
I am sorry, but I don't understand this question. Can you ask it with different words, perhaps with an example of a problem?

To change the header:
- if your microcontroller supports fseek: fseek to the beginning of the file and write a new header.
- if your microcontroller does not support fseek, you must:
1) determine the sector location of the start of the file
2) read the first sector of the file (first 512 bytes) to RAM
3) change the bytes in RAM
4) write the sector back to the disk (into same position) from the RAM

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

Post Reply