初级会员
- 积分
- 179
- 金钱
- 179
- 注册时间
- 2015-1-24
- 在线时间
- 21 小时
|
5金钱
调试之类曲折呀,一开始是不行,换了一个1003,可以了,但是不能录音,又换了一个1053,可以放歌可以录音,只是录音文件放出来的速度很快。百思不得其解。请各位指点指点。
void vs10xx_record(void)
{
unsigned int data_count = 0;
uint16_t u16data = 0;
unsigned int file_size = 0;
unsigned int idx = 0;
uint8_t u8times = 0;
uint8_t u8switch = 0;
int ret;
struct file_wav head = {
.ChunkID = 0x46464952,
.ChunkSize = 0,
.Format = 0x45564157,
.SubChunk1ID = 0x20746d66, //"fmt "
.SubChunk1Size = 16, //大小为16字节
.AudioFormat = 0x01, // ADPCM
.NumOfChannels = 1, // 单声道
.SampleRate = 8000, //8000比特率
.ByteRate = 16000, // 8000 * 2
.BlockAlign = 2, //每一块为2字节
.BitsPerSample = 16, //十六位
.SubChunk3ID = 0x61746164, //"data"
.SubChunk3Size = 0
};
INFOF((FILE" record strat\n"));
file_size = sizeof(head);
fd =create (FILE, 777);
if (fd < 0) {
return;
}
ret = write(fd, &head, sizeof(struct file_wav));
if (ret == 0) {
close(fd);
return;
}
fsync(fd);
VS1003B_WriteCMD(SPI_BASS, 0);
VS1003B_WriteCMD(SPI_AICTRL0, 8000);
VS1003B_WriteCMD(SPI_AICTRL1, 4096); //4倍增益
VS1003B_WriteCMD(SPI_AICTRL2, 0);
VS1003B_WriteCMD(SPI_AICTRL3, 6);
VS1003B_WriteCMD(SPI_CLOCKF, 0x2000);
VS1003B_WriteCMD(SPI_MODE, 0x1804);
mdelay(5);
VS_Load_Patch((uint16_t *)wav_plugin, 40);
while (Mp3ReadRegister(SPI_HDAT1) >> 8);
while (1) {
data_count = Mp3ReadRegister(SPI_HDAT1);
if (data_count > 256 && data_count < 896) {
idx = 0;
while (idx < 512) {
u16data = Mp3ReadRegister(SPI_HDAT0);
data1[idx++] = u16data & 0xff;
data1[idx++] = u16data >> 8;
}
file_size += 512;
ret = write(fd, data1, idx);
if (ret <= 0) {
INFOF((" write error\n"));
close(fd);
break;
}
fsync(fd);
led_toggle(0);
}
if (gpio_get(VKEY1) == 0) {
while (gpio_get(VKEY1) == 0 ){
mdelay(200);
}
INFOF((FILE" record over\n"));
head.ChunkSize = file_size - 8; //算出大小,总文件大小-8
head.SubChunk3Size = file_size - sizeof(struct file_wav); //算出大小,总文件大小减去头部
lseek(fd, 0, SEEK_SET);
write(fd, &head, sizeof(head));
close(fd);
VS1003B_SoftReset();
INFOF(("file size: %d\n", head.ChunkSize + 8));
break;
}
}
}
void vs10xx_play(void)
{
int status;
int fd;
char testbuf[512] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99};
uint32_t file_size = 0;
int count = 0;
Mp3Reset();
Mp3SoftReset();//里面包含VS1003B_WriteCMD(SPI_CLOCKF, 0x9800);
VS1003B_SetVirtualSurroundOn();
VS1003B_WriteCMD(SPI_DECODE_TIME,0x0000); //复位解码器时间
VS1003B_WriteCMD(SPI_DECODE_TIME,0x0000);
VS_Load_Patch((uint16_t *)wav_plugin, 40); //加载配置
INFOF(("register SPI_CLOCKF: 0x%x\n", Mp3ReadRegister(SPI_CLOCKF)));
INFOF(("play strat\n"));
if ((fd = open(FILE, O_RDWR, 777)) < 0) {
INFOF(("open error: 0x%x\n", fd));
return;
}
while(1){
status = read( fd, testbuf, 512 );
// INFOF(("sizeof (buffer): %d\n", sizeof (buffer)));
if ( status > 0 )
{
count = 0;
Mp3DeselectControl();
Mp3SelectData();
while ( count < 512) /* SD?¨?áè?ò???sector£?ò???sector?a512×??ú */
{
if ( MP3_DREQ != 0 ) /* μè′yDREQ?a??£????óêy?Yê?è? */
{
VS1003B_WriteDAT( testbuf + count, 32);
count += 32;
}
}
Mp3DeselectData();
led_toggle(0);
if (gpio_get(VKEY2) == 0) {
while (gpio_get(VKEY2) == 0 ){
mdelay(200);
}
INFOF(("break\n"));
close(fd);
break;
}
}
else {
INFOF((FILE" play over\n"));
close(fd);
VS1003B_Fill2048Zero();
break;
}
}
}
这个是在多任务的操作系统实现的,任务级别是2,其实挺高级的任务了。
我自己排除了一些情况:
1、卡的读写速度不够,导致漏了数据。
我创建了一个10M的数组,直接将录音数据存放在数组中,播放时直接播放数组,还是一样的情况。
2、时钟频率不匹配的问题,
我试过录音时VS1003B_WriteCMD(SPI_CLOCKF, 0x2000);播放是设(SPI_CLOCKF, 0x9800);
试过录音时VS1003B_WriteCMD(SPI_CLOCKF, 0x9800);播放是设(SPI_CLOCKF, 0x9800);
试过录音时VS1003B_WriteCMD(SPI_CLOCKF, 0x9800);播放是设(SPI_CLOCKF, 0x2000);
试过录音时VS1003B_WriteCMD(SPI_CLOCKF, 0x9800);播放是设(SPI_CLOCKF, 0x2000);
都不行。
是还有什么地方我没有设置好吗?还是说我漏了什么东西?
|
|