audio 文件的理解

一、问题:

       文件的数据是全f,全0写到声卡是什么,波形是什么(data 波形),(喇叭波形)

1、全f的audio文件:

1.1、代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        fd = open("ff.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        char sum[4]={0xff,0xff,0xff,0xff};

                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}

od -tcx ff.raw
0000000 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377
               ffffffff        ffffffff        ffffffff        ffffffff
*
55322000

1.2、audiacity导入

文件-》导入-》raw data

注意参数和代码匹配!

1.3、波形示意

1.4、audacity保存

  

1.5、播放查看iis的data信号

 2、全ffff0000的audio文件:

2.1、代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        fd = open("ffff0000.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        char sum[4]={0xff,0xff,0x00,0x00};
                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}

注意参数和代码匹配!

2.3、波形示意

  

2.5、播放查看iis的data信号

 3、全ff00-00ff的audio文件:

3.1、代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        fd = open("ffff0000.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        char sum[4]={0xff,0xff,0x00,0x00};
                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}

3.3、波形示意

  

3.5、播放查看iis的data信号

 3、全ff00-00ff的audio文件:



#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        fd = open("256-256.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        printf("sizeof(short)%d,\n",sizeof(short));
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        //char sum[4]={256,0xff,0x00,0x00};
                        short sum[2]={256,-256};
                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}



od -tcx 256-256.raw
0000000  \0 001  \0 377  \0 001  \0 377  \0 001  \0 377  \0 001  \0 377
               ff000100        ff000100        ff000100        ff000100
*
55322000

ff00 就是-256
100  就是256

 4、全0x7fff,-0x7fff的audio文件:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        fd = open("x.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        printf("sizeof(short)%d,\n",sizeof(short));
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        //char sum[4]={256,0xff,0x00,0x00};
                        short sum[2]={0x7fff,-0x7fff};
                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}


 od -tcx x.raw
0000000 377 177 001 200 377 177 001 200 377 177 001 200 377 177 001 200
               80017fff        80017fff        80017fff        80017fff
*
55322000 

5、全0x7f00,-0x7f00的audio文件:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        fd = open("7f00-7f00.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        printf("sizeof(short)%d,\n",sizeof(short));
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        //char sum[4]={256,0xff,0x00,0x00};
                        short sum[2]={0x7f00,-0x7f00};
                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}



od -tcx 7f00-7f00.raw
0000000  \0 177  \0 201  \0 177  \0 201  \0 177  \0 201  \0 177  \0 201
               81007f00        81007f00        81007f00        81007f00
*
55322000

背景:

16bit 转为24bit的音频,低位会加入8bit的空数据,

24bit的转为16bit的音频,低8bit直接去除

6、全0x7f00,-0x7f00,0x3f00,-0x3f00的audio文件:

int main(int argc,char **argv)
{
        int fd = -1;
        int index = 0;
        int ret = -1;
        int sample_rate = -1;
        short *sum = NULL;
        fd = open("7f00_3f00.raw",O_CREAT|O_RDWR,0777);
        if( fd < 0 )
        {
                perror("open");
                return -1;
        }
        printf("sizeof(short)%d,\n",sizeof(short));
        while(1)
        {
                for(sample_rate=0;sample_rate<48000;sample_rate++)
                {
                        //char sum[4]={256,0xff,0x00,0x00};
                                short sum_h[2]={0x7f00,-0x7f00};
                                short sum_l[2]={0x3f00,-0x3f00};
                        if(0 == sample_rate%2)
                                sum = sum_h;
                        else
                                sum = sum_l;
                        ret = write(fd,sum,4);
                        if( ret <0 )
                                perror("write");
                //      printf("%d,",sample_rate);
                }
                if(index > 60)//60s
                        break;
                printf("index is %d\n",index);
                index ++;
        }
        close(fd);
        return 0;
}


od -tcx 7f00_3f00.raw
0000000  \0 177  \0 201  \0   ?  \0 301  \0 177  \0 201  \0   ?  \0 301
               81007f00        c1003f00        81007f00        c1003f00

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值