VS1003 IMA ADPCM Recording

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
Post Reply
qpdkvn
User
Posts: 3
Joined: Tue 2019-08-06 10:53

VS1003 IMA ADPCM Recording

Post by qpdkvn » Tue 2019-08-06 11:45

I'm trying to record file with VS1003, but it gives me strange data.
RecordTest.wav
(86.78 KiB) Downloaded 5 times
This is the data that VS1003 gave. But when I play this file into play mode, It plays strange sound.

These are the value that I write into the register.
VS1003_MODE = 0x5800 or 0x1800 (Both doesn't work)
VS1003_CLOCKF = 0xc430 (((12288000-8000000+2000)/4000) | 0xc000)
VS1003_VOLUME = 0xFEFE
VS1003_AICTRL0 = 0x0018 (int)(4.0*12288000/256/8000+0.5)
VS1003_AICTRL1 = 0

And this is the code that puts a header into the file.

Code: Select all

void VS1003_WAV_AddHeader(SD_VS1003 *SD, const char *fileName)
{
	UINT temp;

	uint8_t ch = 1;
	uint8_t bps = 16;											//Bits Per Sample
	uint16_t sampleRate = 8000;

	f_open(&USERFile, fileName, FA_WRITE);

	f_puts("RIFF", &USERFile);										//Chunk ID
	*(uint32_t*)WAV_HEADER.ChunkSize = USERFile.fsize - 8;
	f_write(&USERFile, WAV_HEADER.ChunkSize, 4, &temp);				//Chunk Size
	f_puts("WAVE", &USERFile);									//Format

	f_puts("fmt ", &USERFile);										//SubChunk1 ID
	*(uint32_t*)WAV_HEADER.SubChunk1Size = 0x00000014;
	f_write(&USERFile, WAV_HEADER.SubChunk1Size, 4, &temp);			//SubChunk1 Size

	*(uint16_t*)WAV_HEADER.AudioFormat = 0x0011;
	f_write(&USERFile, WAV_HEADER.AudioFormat, 2, &temp);			//Audio Format
	*(uint16_t*)WAV_HEADER.NumOfChannels = ch;
	f_write(&USERFile, WAV_HEADER.NumOfChannels, 2, &temp);			//NumOfChannels

	*(uint32_t*)WAV_HEADER.SampleRate = sampleRate;
	f_write(&USERFile, WAV_HEADER.SampleRate, 4, &temp);				//Samplerate

	*(uint32_t*)WAV_HEADER.ByteRate = (uint32_t)sampleRate * 256 / 505;
	f_write(&USERFile, WAV_HEADER.ByteRate, 4, &temp);				//Byterate

	*(uint16_t*)WAV_HEADER.BlockAlign = 0x0100;
	f_write(&USERFile, WAV_HEADER.BlockAlign, 2, &temp);				//Block Align
	*(uint16_t*)WAV_HEADER.BitsPerSample = 0x04;
	f_write(&USERFile, WAV_HEADER.BitsPerSample, 2, &temp);			//BitsPerSample

	*(uint16_t*)WAV_HEADER.ByteExtraData = 0x0002;
	f_write(&USERFile, WAV_HEADER.ByteExtraData, 2, &temp);			//ByteExtraData
	*(uint16_t*)WAV_HEADER.ExtraData = 0x01f9;
	f_write(&USERFile, WAV_HEADER.ExtraData, 2, &temp);				//ExtraData

	f_puts("fact", &USERFile);										//SubChunk2 ID
	*(uint32_t*)WAV_HEADER.SubChunk2Size = 0x00000004;
	f_write(&USERFile, WAV_HEADER.SubChunk2Size, 4, &temp);			//SubChunk2 Size
	*(uint32_t*)WAV_HEADER.NumOfSamples = (USERFile.fsize - 60) * 505 / 256;
	f_write(&USERFile, WAV_HEADER.NumOfSamples, 4, &temp);			//NumOfSamples

	f_puts("data", &USERFile);										//SubChunk3 ID
	*(uint32_t*)WAV_HEADER.SubChunk3Size = USERFile.fsize - 60;
	f_write(&USERFile, WAV_HEADER.SubChunk3Size, 4, &temp);			//SubChunk3 Size

	f_close(&USERFile);
	return;
}
Capture.PNG
Capture.PNG (8.05 KiB) Viewed 65 times
And this is the result of this function.

What should I do to solve this problem?
And can I recode into another format? ex)mp3, PCM

Thank you

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

Re: VS1003 IMA ADPCM Recording

Post by pasi » Tue 2019-08-06 14:00

The file appears to be a valid IMA ADPCM file with very quiet content. It should play without issues, I tested with vs1053b and vs1003b, with the C model of the player, and mplayer.

Your player routine has probably some transfer issues. Check the SPI mode, SPI speed, chip select handling (only change when idle), and that you react correctly to DREQ.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

qpdkvn
User
Posts: 3
Joined: Tue 2019-08-06 10:53

Re: VS1003 IMA ADPCM Recording

Post by qpdkvn » Wed 2019-08-07 2:01

RecordTest.wav is a file that recorded my whistle. And I can play .mp3 file and .wav file on my chip well.

But when I play recorded IMA ADPCM file on my chip, It plays chopping sound. And that sound is not similar to my whistle.

I think it seems to be because of the file has 32-bit zero, and 32-bit data repeatedly like this.
Capture.png
Capture.png (23.25 KiB) Viewed 53 times
Can you hear the whistle sound? And am I missing something while playing music file?

Is it right the data repeat by 32-bit? And can I play this file on my desktop?

Thank you.

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

Re: VS1003 IMA ADPCM Recording

Post by pasi » Wed 2019-08-07 9:25

What's the frequency of the whistle?

No, the file doesn't show much audio at all. IMA ADPCM frames start with a linear sample and a state, and in the file all of those seem to be zero.

The data is consistent with zero signal, but it could also be a co-incidence. Was this recorded with line input or microphone input active?

Could you try with a fixed gain, i.e. for example AICTRL1 = 16384? (1024 equals 1x gain)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

qpdkvn
User
Posts: 3
Joined: Tue 2019-08-06 10:53

Re: VS1003 IMA ADPCM Recording

Post by qpdkvn » Thu 2019-08-08 11:00

Sorry that was my fault.
I read 32bits and wrote 64 bits.

I fixed my code and I can get this result.
RecordTest.wav
Contains my Ahhh voice and whistling sound
(38 KiB) Downloaded 1 time
I can play this file in desktop and it sounds similar to my whistle.
But playtime is only half and the voice in the file is not mine. -①
I tried auto gain and 16384, 65535... etc but that attempts can't solve my problem.

And somtimes I get strange data like this. -②
RecordFailure.wav
Strange data
(147 KiB) Downloaded 1 time
Most of the data contain 0, and others contain 255.

I think it's almost done. Is it header problem? or reading routine?
Capture.PNG
Capture.PNG (6.57 KiB) Viewed 43 times
This is the header,
Capture.PNG
Capture.PNG (13.24 KiB) Viewed 43 times
And this is the routine. record buffer size is 512bytes.


Thank you.

Post Reply