搜索
bottom↓
回复: 1

录音程序问题,望各位高手指点一下~万分感激~

[复制链接]

出0入0汤圆

发表于 2010-8-31 15:56:34 | 显示全部楼层 |阅读模式
VS1003录音程序问题:指示灯没熄灭。
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!)
   // Insert 448 zeroes here!
};
code  unsigned char RIFFHeader504[] = {
  'd' , 'a' , 't' , 'a' , // Chunk ID (data)
  0x70, 0x70, 0x70, 0x70  // Chunk payload size (calculate after rec!)
};
void delayms(unsigned int z)
{
        unsigned int t1,y;
        for(t1=z;t1>0;t1--)
                for(y=110;y>0;y--);
}
void main()
{
        unsigned char *p;
        unsigned int i;
        unsigned int j;
        unsigned char c = 0;
        unsigned int tmp;
        unsigned int r;
        unsigned long FileSec=0;
        unsigned long SEC_CAL=0;
//        key=1;
        delayms(10);
        VS_Write_Reg(0x03,0x66,0x96);
        VS_Write_Reg(0x0c,0x00,0x09);  
        VS_Write_Reg(0x0d,0x10,0x00);  
        VS_Write_Reg(0x00,0x18,0x04);
        delayms(50);
        VS_Write_Reg(0x03,0x66,0x96);
        delayms(50);

        for (i=0; i<56; i++)
        {  
                buffer = RIFFHeader0;
        }

        for (i=52; i<504; i++)
        {
                buffer = 0;
        }

        for (i=504; i<512; i++)
        {
                buffer = RIFFHeader504[i-504];
        }
        led=0; //熄灯
        if(f_open(&f1, "test.wav", FA_CREATE_ALWAYS | FA_WRITE))
        {

                while(1);
        }

        f_write(&f1, buffer,512, &r);

如果把熄灯那个语句放上一点就正常熄灯了,如下:
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!)
   // Insert 448 zeroes here!
};
code  unsigned char RIFFHeader504[] = {
  'd' , 'a' , 't' , 'a' , // Chunk ID (data)
  0x70, 0x70, 0x70, 0x70  // Chunk payload size (calculate after rec!)
};
void delayms(unsigned int z)
{
        unsigned int t1,y;
        for(t1=z;t1>0;t1--)
                for(y=110;y>0;y--);
}
void main()
{
        unsigned char *p;
        unsigned int i;
        unsigned int j;
        unsigned char c = 0;
        unsigned int tmp;
        unsigned int r;
        unsigned long FileSec=0;
        unsigned long SEC_CAL=0;
//        key=1;
        delayms(10);
        VS_Write_Reg(0x03,0x66,0x96);
        VS_Write_Reg(0x0c,0x00,0x09);  
        VS_Write_Reg(0x0d,0x10,0x00);  
        VS_Write_Reg(0x00,0x18,0x04);
        delayms(50);
        VS_Write_Reg(0x03,0x66,0x96);
        delayms(50);

        for (i=0; i<56; i++)
        {  
                buffer = RIFFHeader0;
        }

        for (i=52; i<504; i++)
        {
                buffer = 0;
        }
        led=0; //熄灯
        for (i=504; i<512; i++)
        {
                buffer = RIFFHeader504[i-504];
        }

        if(f_open(&f1, "test.wav", FA_CREATE_ALWAYS | FA_WRITE))
        {

                while(1);
        }

        f_write(&f1, buffer,512, &r);

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2010-8-31 15:58:03 | 显示全部楼层
以上程序为参考了本论坛的程序
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-24 04:38

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表