mp3c语言压缩代码(字符串压缩算法 c语言)
admin 发布:2022-12-19 07:48 138
本篇文章给大家谈谈mp3c语言压缩代码,以及字符串压缩算法 c语言对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
c语言mp3代码
不太好实现,建议用VC++.
调用Windows API函数。
mciSendString或者PaySound。
C语言压缩
#includestdio.h
int main()
{ int i,j;
char s[105];
scanf("%s",s);
for(j=0,i=1;s[i];i++)
{while(s[i]==s[i-1])i++;
printf("%d ",i-j);
j=i;
}
printf("%d\n",i-j);
return 0;
}
求助:关于C语言压缩MP3算法!
具体怎样将记录了模拟音频信号的文件转换为mp3格式文件,我也不知道具体,原理还是可以告诉你!
但是,无论什么文件,都可以使用huffman编码来压缩,
huffman编码是一种无损的编码,就是可以还原样的编码
给你一个我大一看的一huffman编码程序,可以编码也可以解码
比楼上的强一点,找qq:504449327要,就说要huffman编码的程序
这个是我同学的哈夫曼编码程序
另外还有解码的程序,要的话再商量
#include stdio.h
#include string.h
#include stdlib.h
#define TRUE 1
#define ERROR 0
#define OK 1
#define FALSE 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define Status int
#define MAXLENGTH 128
typedef struct HTnode
{
long weight;
int parent;
int lchild;
int rchild;
}HTNode, *HuffmanTree;
typedef struct CTnode
{
long weight;
char *coded_string;
}CharacterTable;
typedef char * *HuffmanCode;
FILE *fp=NULL;
void Analyse (CharacterTable * *character_table, long * *w, char * *chara, int n)//分析所有不同的字符的权值
{
long *tmpw;
char ch, *tmpchara;
int i;
(*character_table)=(CharacterTable *)malloc(128*sizeof(CharacterTable));//定义存放字母的数组
for(i=0; i128; i++)
{
(*character_table)[i].weight=0; //初始化
(*character_table)[i].coded_string=NULL;
}
ch=fgetc(fp);
while(!feof(fp))//诺到文件末尾,函数值为真
{
//m=ch;
if(ch128 ch=0)
(*character_table)[ch].weight++;//获得各个字母在文件中出现的次数
ch=fgetc(fp);
}
for(i=0, n=0; i128; i++)
if((*character_table)[i].weight)
n++; //统计有多少不同的字符数
(*w)=(long *)malloc(n*sizeof(long));//deliver the character and the weight to main
(*chara)=(char *)malloc(n*sizeof(char));
tmpw=(*w);
tmpchara=(*chara);
for(i=0; i128; i++)
if((*character_table)[i].weight)
{//将权值放入*w数组中
*(*w)=(*character_table)[i].weight;
*(*chara)=i;//这里i是字符
(*w)++;
(*chara)++;
}
(*w)=tmpw;
(*chara)=tmpchara;//指针返回数组头
}
void Select (HuffmanTree *HT, int i, int *Min1, int *Min2)
{
int j, n, tmp1=-1, tmp2=-2;
for(n=0; ni; n++)
{
if(!(*HT)[n].parent)
{
if(tmp1 == -1)
{
tmp1=n;
continue;
}
if(tmp2 == -2)
{
tmp2=n;
if((*HT)[tmp1].weight (*HT)[tmp2].weight)
{
j=tmp1;
tmp1=tmp2;
tmp2=j;
}
continue;
}
if((*HT)[n].weight (*HT)[tmp2].weight) //scan and change
if((*HT)[n].weight (*HT)[tmp1].weight)
tmp1=n;
else
tmp2=n;
}
}
*Min1=tmp1;
*Min2=tmp2; //tmp[Min2].weight = tmp[Min1].weight
}
Status Huffman(HuffmanTree *HT, HuffmanCode *HC,long *w, int n)
{
int m, i, Min1, Min2, p1, p2, start, *M1, *M2;
char *cd;
HuffmanTree *HTp;
if(n1) return ERROR;
m=2*n-1;
(*HT)=(HTNode *)malloc(m*sizeof(HTNode)); //intialise Hc in main
HTp=HT;
for(i=0; in; i++, w++)
{
(*HTp)[i].weight=*w;
(*HTp)[i].parent=0;
(*HTp)[i].lchild=0;
(*HTp)[i].rchild=0;
}
for(; im; i++)
{
(*HTp)[i].weight=0;
(*HTp)[i].parent=0;
(*HTp)[i].lchild=0;
(*HTp)[i].rchild=0;
}
M1=Min1;
M2=Min2;
for(i=n; im; i++)
{
Select(HT, i, M1, M2);
(*HTp)[Min1].parent=i;
(*HTp)[Min2].parent=i;
(*HTp)[i].lchild=Min1; //左孩子要小一些
(*HTp)[i].rchild=Min2;
(*HTp)[i].weight=(*HTp)[Min1].weight + (*HTp)[Min2].weight;
}
//coded the weight below
(*HC)=(HuffmanCode)malloc(n*sizeof(char *));
cd=(char *)malloc(n*sizeof(char));
cd[n-1]='\0';
for(i=0; in; i++)
{
start=n-1;
for(p1=i, p2=(*HTp)[p1].parent; p2!=0; p1=p2, p2=(*HTp)[p1].parent)
{
if( (*HTp)[p2].lchild ==p1) //编码, 左孩子为0, 右孩子为1
cd[--start]='0';
else
cd[--start]='1';
}
(*HC)[i]=(char *)malloc((n-start)*sizeof(char));
strcpy((*HC)[i],cd
本篇文章给大家谈谈mp3c语言压缩代码,以及字符串压缩算法 c语言对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
);} //over
return OK;
}
void Weinumber_to_stringnumber(char * *stringnumber, long *w, int leaves)
{//将权值以字符数组形式存放在上米的数组中
char tmp[30];
long i, j, k;
int start;
for(i=0; ileaves; i++)
{
start=29;
tmp[start--]='\0';
for(k=w[i], j=k%10; k!=0; k=k/10, j=k%10)
tmp[start--]=j+'0';
stringnumber[i]=(char *)malloc((29-start)*sizeof(char));
strcpy(stringnumber[i], tmp[start+1]);
}
}
void Save_huffman_weight_dictionary(long *w, char *character, int leaves, HuffmanCode *HC)
{
char * *stringnumber;
int i;
FILE *fp1;
fp1=fopen("weight.txt", "w");
stringnumber=(char * *)malloc(leaves * sizeof(char *));
Weinumber_to_stringnumber(stringnumber, w, leaves);
for(i=0; ileaves; i++)
{
fputc(' ', fp1); // for unhuffman add '
fputc(character[i], fp1);
fputc('\t', fp1);
fputs(stringnumber[i], fp1);
fputc('\t', fp1);
fputc('\'', fp1);
fputs((*HC)[i], fp1);
fputc('\'', fp1);
fputc('\n', fp1);
}
fclose(fp1);
}
void Huffman_file_convert(HuffmanCode *HC, CharacterTable *character_table) //fp had opened
{
int i;
char ch;
FILE *fp2=fopen("coded.txt","w");
for( i=0; i128; i++)
if(character_table[i].weight)
{
character_table[i].coded_string=*(*HC);
(*HC)++;
}
ch=fgetc(fp);
while(!feof(fp))
{
if( (ch=0 ch128) (character_table[ch].weight) )//it is very importan to add (ch=0 ch128)
fputs(character_table[ch].coded_string,fp2);
ch=fgetc(fp);
}
fclose(fp2);
}
void fileopen1() //通过指针fp传递信息
{
char filename[100];
do{
printf("\n\n\t请输入要编码的文件:");
scanf("%s", filename);
if ((fp=fopen(filename,"r"))==NULL)
printf("\n\t不能打开此文件! 请重新输入!\n");
}while(!fp);
}
void main()
{
HuffmanTree Ht, *ht;//three level pointer
HuffmanCode Hc, *hc;
CharacterTable *CT, * *character_table;
long *weight, * *w;
char * character, * *chara;
int leave; //the all leaves number
ht=Ht;
hc=Hc;
w=weight;
chara=character;
character_table=CT;
fileopen1();
Analyse(character_table, w, chara, leave);
fseek(fp, 0, 0);//将文件指针还原
Huffman(ht, hc, weight, leave);//构建哈弗曼树!
Save_huffman_weight_dictionary(weight, character, leave, hc);
Huffman_file_convert(hc, CT);
fclose(fp);
}
如何用C语言实现数据压缩
首先选择一个压缩算法
然后按照算法实现压缩代码,调用接口就可以
常见的 可以使用哈夫曼编码压缩,或者使用开源的压缩代码,比如lzo, gzip, lzma等等。
C语言实现文件压缩
typedef int (WINAPI ICEPUB_COMPRESSFILE)(char *strFilename, char *strZipFilename);
ICEPUB_COMPRESSFILE *icePub_compressFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_compressFile = (ICEPUB_COMPRESSFILE *)GetProcAddress(hDLLDrv, "icePub_compressFile");
}
if(icePub_compressFile)
icePub_compressFile("a.exe","a.Z");
if(hDLLDrv)
FreeLibrary(hDLLDrv);
typedef int (WINAPI ICEPUB_UNCOMPRESSFILE)(char *strZipFilename,char *strFilename);
ICEPUB_UNCOMPRESSFILE *icePub_uncompressFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_uncompressFile = (ICEPUB_UNCOMPRESSFILE *)GetProcAddress(hDLLDrv, "icePub_uncompressFile");
}
if(icePub_uncompressFile)
icePub_uncompressFile("a.Z","a.exe");
if(hDLLDrv)
FreeLibrary(hDLLDrv);
要一个解析MP3的代码要C语言的 要自己写的不要网上的
#include stdio.h
#include string.h#define FILE_PATH "C:\\甩葱歌.mp3"
void main()
{
int i; //用于循环计数
struct MUSIC_TITAL_INFO
{
char ID3v1TAG[3]; //TAG
char MUSIC_NAME[30]; //存储标题信息
char Artist[30]; //存储歌手信息
char Album[30]; //存储专辑信息
char YEAR[4]; //存储年代信息
char Comments[28]; //存储备注信息,28个字节(有时为30字节)
char Genre; //存储音乐风格信息,保留位,1个字节
char Reserved; //保留位,1个字节(有时没有意思
char Track; //音轨(曲号)保留位,1个字节(有时没有)
}st1;
FILE *fp;
fp = fopen(FILE_PATH,"r");
if (fp == NULL) {
printf("can not open file!");
return;
}
fseek(fp,-128L,SEEK_END);
fread(st1,1,128,fp); //结构体中的变量全是char
// printf("%s-%s-%s-%s-%s-%s-%c-%c-%c.\n",\
// st1.ID3v1TAG,st1.MUSIC_NAME,st1.Artist,st1.Album,st1.YEAR,st1.Comments,\
// st1.Genre,st1.Reserved,st1.Track);
//打印TAG
printf("TAG:");
for(i= 0; i3; i++)
{
printf("%c",st1.ID3v1TAG[i]);
}
printf("\n");
//打印标题
printf("标题:");
for(i= 0; i30; i++)
{
printf("%c",st1.MUSIC_NAME[i]);
}
printf("\n");
//打印歌手信息
printf("歌手信息:");
for(i= 0; i30; i++)
{
printf("%c",st1.Artist[i]);
}
printf("\n");
//打印专辑信息
printf("专辑信息:");
for(i= 0; i30; i++)
{
printf("%c",st1.Album[i]);
}
printf("\n"); //打印年代信息
printf("年代信息:");
for(i= 0; i4; i++)
{
printf("%c",st1.YEAR[i]);
}
printf("\n"); //备注
printf("备注:");
for(i= 0; i28; i++)
{
printf("%c",st1.Comments[i]);
}
printf("\n"); //音乐风格信息
printf("音乐风格信息:");
printf("%c",st1.Genre);
printf("\n"); //保留位
printf("保留位:");
printf("%c",st1.Reserved);
printf("\n");
//音轨
printf("音轨:");
printf("%c",st1.Track);
printf("\n");
fclose(fp);
}
关于mp3c语言压缩代码和字符串压缩算法 c语言的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-12网页设计需要学什么,网页设计学什么语言
- 05-09网页代码,网页代码快捷键
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06代码源软件库(程序代码库)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接