动态网站制作指南
[  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C/C++教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ C/C++教程 ]的信息

本月文章推荐
.C与脚本的混合编程.
.在Win9x/NT下获取硬盘物理序列号.
.C语言函数中利用指针引用可变参数.
.解决在编译过程中需要链接静态库.
.关于如何在BCB中使用CodeGuard.
.基于VC++的OpenGL编程讲座之概述.
.Intel C++ 9.0编译器优化效果测试.
.TCPIP完整的一套基础介绍.
.C语言程序开发经典实例之四.
.C++辨析系列谈(三).
.C++ builder 的文件读写操作总结.
.C++指针直接调用类成员函数探讨.
.C++函数如何操作堆栈指针esp.
.用 c 写 CGI 程序简要指南.
.C语言入门之枚举与位运算(1).
.使用ASP.NET Atlas开发检测密码强.
.vb.net中windows服务的创建.
.关于程序撰写风格.
.在CB中进行DirectX编程.
.C/C++中枚举类型(enum)的入门教程.

将Wav格式压缩成Mp3

文章类别:C/C++教程 | 发表日期:2008-3-8 |



  Compressing Wav file to mp3

● 1. IntrodUCtion
First, I don't meant to give you informations about how to understand the mp3 algorithm. My goal is to eXPlain how to use an already existing encoder with BCB.

● 2. Choosing the mp3 encoder
There are tons of mp3 encoders. Some of them are free others are not. Some are fast but produce an awful result. Others are slow but with Excellent result and give a high audio quality. The ideal would be a free, reasonably fast encoder giving a high audio quality, all at the same time.
Enjoy! This pearl exists. But we have to look at it in the GNU world. There is a GNU project, called LAME, for Lame Ain't a Mp3 Encoder, under the GPL license. The official web site of the LAME project is http://www.mp3dev.org/mp3/
Moreover, as it is a GNU project, we have Access to the source and there is a version compiled for Win32 in a DLL.
Among all the other encoders, I want to quote two of them. The first, FRAUNHOFER, because it is a fast and excellent encoder : http://www.iis.fhg.de/ but it's not  free though.
The second because it's a very fast encoder but the audio result is awful. So don't use it except if you are looking for a fast encoder. It's the encoder from Xing Tech : http://www.xingtech.com/
Note : The Lame encoder has a limitation. The sample rate must be 32000, 44100 or 48000.?

● 3. Some informations about the WAV format
A wav file is just a collection of chunks. There is a format chunk wich contains all the informations about the samples. For instance, the bitrate, the number of channels, if it's stereo or mono... There is also a chunk containing the data. In other Words, this chunk contains all the samples. In front of the file, there are 12 characters indicating that the file is a wav file.
The two chunks given above must be present in the file.
There could be other chunk but we just ignore them. They are not needed for our purpose. If you want to know more about wav file, take a look at http://www.wotsit.org/ for a complete description.
The format chunk :

struct FormatChunk
{
    char            chunkID[4];
    long            chunkSize;

    short           wFormatTag;
    unsigned short  wChannels;
    unsigned long   dwSamplesPerSec;
    unsigned long   dwAvgBytesPerSec;
    unsigned short  wBlockAlign;
    unsigned short  wBitsPerSample;
    // Note: there may be additional fields here, depending upon wFormatTag.
};

Above, you can see the struct representing the format chunk. The chunkID is always "fmt " with an ending space (4 characters). It's the identification of the chunk. All other chunk have such an ID. The chunkSize parameter contains the number of bytes of the chunk, the ID and chunkSize excluded.
The format chunk must be the first chunk in the file.

The data chunk :
struct Chunk
{
    char chunkID[4];
    long chunkSize;
};
In the case of the data chunk, the chunkID contains "data". The chunkSize parameters contains the size of the raw data (samples). The data begins just after chunkSize.

In the case of the data chunk, the chunkID contains "data". The chunkSize parameters contains the size of the raw data (samples). The data begins just after chunkSize.
Dans le cas du bloc de données, chunkID contient "data". Le paramètre chunkSize contient la taille du bloc de données proprement dites. Celles-ci commencent juste après chunkSize.
So, when we read a wav file, all we have to do is :
- read the first 12 characters to check if it's a real wav file.
- read the format chunk in a struct similar to the formatChunk struct.
- skip the extra parameters in the format chunk, if any.
- find the data chunk, read the raw data and carry out with the encoding.
-skip all other chunks.
Donc, ce que nous devons faire est :
- lire les 12 premiers caractères pour déterminer si on est bien en présence d'un fichier wav.
- lire le bloc de format dans une structure similaire à la structure formatChunk.
- ignorer les caractères supplémentaires dans le bloc de format, s'il y en a.
- ignorer tous les blocs qui ne sont pas le bloc de données.
- trouver le bloc de données, lire ces données et lancer l'encodage.

● 4. Importing the DLL
The DLL used for the encoding  is called lame_enc.dll.
Unfortunately, this DLL was build with VC 6 from Microsoft. If we just create a lib file from the DLL and try to import the library in BCB, we'll get an 'Unresolved external error' at link time for each function we'll try to use. Due to the declaration type, BCB is expecting a function name with a leading underscore and the function names doesn't have such a leading underscore.

To resolve this issue, we must, first, create a def file from our DLL. Open a console windows and type :

IMPDEF lame_enc.def lame_enc.dll

Open the lame_enc.def file with an editor (Notepad for instance) and modify it like this. This will create aliases for the functions :
    LIBRARY     LAME_ENC.DLL
    EXPORTS
    _beCloseStream = beCloseStream
    _beDeinitStream = beDeinitStream
    _beEncodeChunk = beEncodeChunk
    _beInitStream = beInitStream
    _beVersion = beVersion
    _beWriteVBRHeader = beWriteVBRHeader
    beCloseStream                  @4
    beDeinitStream                 @3
    beEncodeChunk                  @2
    beInitStream                   @1
    beVersion                      @5
    beWriteVBRHeader               @6

Now, we can create the lib file from our def file. We'll import that lib file in our project. To create the lib file, type :
implib lame_enc.lib lame_enc.def

● 5. The code
First, you have to import the libary in your project. Next, include the header file of the DLL into your unit. In the DLL header file, you have to add extern "C" in front of all exported function.
Here is the header with the moifications (lame_enc.h) :
/*  bladedll.h
    +++++++++++++++++++++++++++
    +   Blade's Encoder DLL  &n

上一篇:将位图旋转90度 人气:141
下一篇:九九乘法表的几种不同形状 人气:276
点击此处浏览全部C/C++的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-5-16 乘风多用户PHP统计系统 v3.4
2008-5-16 轩溪下载系统 v3.78 build 0515
2008-5-16 普沙B2B 浙江省商贸网 v2.0
2008-5-16 asp抓蜘蛛的小程序 v1.0
2008-5-16 齐齐乐网私服发布站 仿haosf新版
2008-5-16 IssTech信息反馈系统 v1.0
2008-5-16 自由领域大头贴(js接口版) 修正版
2008-5-16 医院网站系统
2008-5-16 智拓-分类信息管理系统 v5.0
2008-5-7 Windows XP SP3 官方英文版
2008-5-7 Windows XP SP3 官方香港中文版
2008-5-7 Windows XP SP3 官方繁体中文版
2008-5-7 Windows XP SP3 官方简体中文版
2008-4-30 Multiple Unzip Wizard 1.02
2008-4-30 Multiple Unrar Wizard 1.0.0
2008-4-30 WinZip Install/Try/Uninstall a
2008-4-30 ZIP压缩文件修复器WzipFix 2.0
2008-4-30 Pentazip 6.01 Build 189 For Wi
  发表评论
姓 名: 验证码: [ 全部贴吧 ] [ 浏览评论 ]
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号