📄 将wav格式压缩成mp3-c-c++-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,b style=colorblack;background-color#ff66ff为-b7万用户提供服务.htm
字号:
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 <B
style="COLOR: black; BACKGROUND-COLOR: #99ff99">wav</B> file. <BR>The two
chunks given above must be present in the file. <BR>There could be other chunk
but we just ignore them. They are not needed for our purpose. If you want to
know more about <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">wav</B>
file, take a look at http://www.wotsit.org/ for a complete description.
<BR>The format chunk :<BR><BR>struct
FormatChunk<BR>{<BR> char chunkID[4];<BR> long chunkSize;<BR> short wFormatTag;<BR> unsigned
short wChannels;<BR> unsigned
long dwSamplesPerSec;<BR> unsigned
long dwAvgBytesPerSec;<BR> unsigned
short wBlockAlign;<BR> unsigned
short wBitsPerSample;<BR> // Note: there may
be additional fields here, depending upon wFormatTag.<BR>};<BR><BR>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. <BR>The format chunk must
be the first chunk in the file. <BR><BR>The data chunk :<BR>struct
Chunk<BR>{<BR> char
chunkID[4];<BR> long chunkSize;<BR>};<BR>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.<BR><BR>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.<BR>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.<BR>So, when we
read a <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">wav</B> file, all we
have to do is : <BR>- read the first 12 characters to check if it’s a real <B
style="COLOR: black; BACKGROUND-COLOR: #99ff99">wav</B> file. <BR>- read the
format chunk in a struct similar to the formatChunk struct. <BR>- skip the
extra parameters in the format chunk, if any. <BR>- find the data chunk, read
the raw data and carry out with the encoding. <BR>-skip all other
chunks.<BR>Donc, ce que nous devons faire est : <BR>- lire les 12 premiers
caractères pour déterminer si on est bien en présence d’un fichier <B
style="COLOR: black; BACKGROUND-COLOR: #99ff99">wav</B>. <BR>- lire le bloc de
format dans une structure similaire à la structure formatChunk. <BR>- ignorer
les caractères supplémentaires dans le bloc de format, s’il y en a. <BR>-
ignorer tous les blocs qui ne sont pas le bloc de données. <BR>- trouver le
bloc de données, lire ces données et lancer l’encodage.<BR><BR>● 4. Importing
the DLL<BR>The DLL used for the encoding is called lame_enc.dll.
<BR>Unfortunately, this DLL was build with <B
style="COLOR: black; BACKGROUND-COLOR: #ffff66">VC</B> 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. <BR>To resolve this issue, we must, first, create a def file from
our DLL. Open a console windows and type :<BR><BR>IMPDEF lame_enc.def
lame_enc.dll <BR><BR>Open the lame_enc.def file with an editor (Notepad for
instance) and modify it like this. This will create aliases for the functions
:<BR> LIBRARY LAME_ENC.DLL
<BR> EXPORTS <BR> _beCloseStream
= beCloseStream <BR> _beDeinitStream = beDeinitStream
<BR> _beEncodeChunk = beEncodeChunk
<BR> _beInitStream = beInitStream
<BR> _beVersion = beVersion
<BR> _beWriteVBRHeader = beWriteVBRHeader
<BR> beCloseStream @4
<BR> beDeinitStream @3
<BR> beEncodeChunk @2
<BR> beInitStream @1
<BR> beVersion @5
<BR> beWriteVBRHeader @6
<BR><BR>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 :<BR>implib lame_enc.lib
lame_enc.def <BR><BR>● 5. The code<BR>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.
<BR>Here is the header with the moifications (lame_enc.h)
:<BR>/* bladedll.h<BR> +++++++++++++++++++++++++++<BR> + Blade’s
Encoder
DLL +<BR> +++++++++++++++++++++++++++<BR><BR> ------------------------------------------------------<BR> -
Version 1.00 (7 November 1998) - Jukka Poikolainen
-<BR> ------------------------------------------------------<BR>*/<BR>#ifndef
___BLADEDLL_H_INCLUDED___<BR>#define ___BLADEDLL_H_INCLUDED___<BR><BR>#pragma
pack(push)<BR>#pragma pack(1)<BR><BR>/* encoding formats */<BR><BR>#define
BE_CONFIG_MP3 0<BR>#define BE_CONFIG_LAME 256<BR><BR>/* type definitions
*/<BR><BR>typedef unsigned
long HBE_STREAM;<BR>typedef HBE_STREAM *PHBE_STREAM;<BR>typedef unsigned
long BE_ERR;<BR><BR>/* error codes
*/<BR><BR>#define
BE_ERR_SUCCESSFUL 0x00000000<BR>#define
BE_ERR_INVALID_FORMAT 0x00000001<BR>#define
BE_ERR_INVALID_FORMAT_PARAMETERS 0x00000002<BR>#define
BE_ERR_NO_MORE_HANDLES 0x00000003<BR>#define
BE_ERR_INVALID_HANDLE 0x00000004<BR>#define
BE_ERR_BUFFER_TOO_SMALL 0x00000005<BR><BR>/*
other constants */<BR><BR>#define BE_MAX_HOMEPAGE 256<BR><BR>/* format
specific variables */<BR><BR>#define
BE_MP3_MODE_STEREO 0<BR>#define
BE_MP3_MODE_JSTEREO 1<BR>#define
BE_MP3_MODE_DUALCHANNEL 2<BR>#define
BE_MP3_MODE_MONO 3<BR><BR>#define
MPEG1 1<BR>#define MPEG2 0<BR><BR>#ifdef _BLADEDLL<BR>#undef
FLOAT<BR> #include
<视窗系统.h><BR>#endif<BR><BR>enum MPEG_QUALITY<BR>{<BR> NORMAL_QUALITY
=
0,<BR> LOW_QUALITY,<BR> HIGH_QUALITY,<BR> VOICE_QUALITY<BR>};<BR><BR>typedef
struct<BR>{<BR> DWORD dwConfig; //
BE_CONFIG_XXXXX<BR> //
Currently only BE_CONFIG_MP3 is
supported<BR> union<BR> {<BR> struct<BR> {<BR> DWORD dwSampleRate; //
48000, 44100 and 32000
allowed<BR> BYTE byMode; //
BE_MP3_MODE_STEREO,
BE_MP3_MODE_DUALCHANNEL<BR> //
BE_MP3_MODE_MONO<BR> WORD wBitrate; //
32, 40, 48, 56, 64, 80, 96, 112,
128,<BR> //
160, 192, 224, 256 and 320
allowed<BR> BOOL bPrivate;<BR> BOOL bCRC;<BR> BOOL bCopyright;<BR> BOOL bOriginal;<BR> }<B
style="COLOR: white; BACKGROUND-COLOR: #880000">mp3</B>; //
BE_CONFIG_MP3<BR> struct<BR> {<BR> //
STRUCTURE
INFORMATION<BR> DWORD dwStructVersion;<BR> DWORD dwStructSize;<BR> //
BASIC ENCODER
SETTINGS<BR> DWORD dwSampleRate; //
ALLOWED SAMPLERATE VALUES
DEPENDS<BR> //
ON
dwMPEGVersion<BR> DWORD dwReSampleRate;
// DOWNSAMPLERATE, 0=ENCODER
DECIDES<BR> INT nMode; //
BE_MP3_MODE_STEREO,
BE_MP3_MODE_DUALCHANNEL<BR> //
BE_MP3_MODE_MONO<BR> DWORD dwBitrate; //
CBR bitrate, VBR min
bitrate<BR> DWORD dwMaxBitrate; //
CBR ignored, VBR Max
bitrate<BR> MPEG_QUALITY nQuality; //
Quality setting
(NORMAL,HIGH,LOW,VOICE)<BR> DWORD dwMpegVersion; //
MPEG-1 OR
MPEG-2<BR> DWORD dwPsyModel; //
FUTURE USE, SET TO
0<BR> DWORD dwEmphasis; //
FUTURE USE, SET TO
0<BR><BR> //
BIT STREAM
SETTINGS<BR> BOOL bPrivate; //
Set Private Bit
(TRUE/FALSE)<BR> BOOL bCRC; //
Insert CRC
(TRUE/FALSE)<BR> BOOL bCopyright; //
Set Copyright Bit
(TRUE/FALSE)<BR> BOOL bOriginal; //
Set Original Bit
(TRUE/FALSE)<BR> <BR> //
VBR
STUFF<BR> BOOL bWriteVBRHeader;
// WRITE XING VBR HEADER
(TRUE/FALSE)<BR> BOOL bEnableVBR; //
USE VBR ENCODING
(TRUE/FALSE)<BR> INT nVBRQuality; //
VBR QUALITY
0..9<BR> BYTE btReserved[255];
// FUTURE USE, SET TO
0<BR> }LHV1; //
LAME header version
1<BR><BR> struct<BR> {<BR> DWORD dwSampleRate;<BR> BYTE byMode;<BR> WORD wBitrate;<BR> BYTE byEncodingMethod;<BR> }aac;<BR> }format; <BR>}BE_CONFIG;<BR><BR><BR>struct
BE_VERSION<BR>{<BR> // BladeEnc DLL Version
number<BR> BYTE byDLLMajorVersion;<BR> BYTE byDLLMinorVersion;<BR> //
BladeEnc Engine Version
Number<BR> BYTE byMajorVersion;<BR> BYTE byMinorVersion;<BR> //
DLL Release
date<BR> BYTE byDay;<BR> BYTE byMonth;<BR> WORD wYear;<BR> //
BladeEnc Homepage
URL<BR> CHAR zHomepage[BE_MAX_HOMEPAGE +
1];<BR>};<BR><BR>#ifndef _BLADEDLL<BR><BR>typedef
BE_ERR (*BEINITSTREAM) (BE_CONFIG*, PDWORD,
PDWORD, PHBE_STREAM);<BR>typedef
BE_ERR (*BEENCODECHUNK) (HBE_STREAM, DWORD,
PSHORT, PBYTE, PDWORD);<BR>typedef
BE_ERR (*BEDEINITSTREAM) (HBE_STREAM, PBYTE,
PDWORD);<BR>typedef
BE_ERR (*BECLOSESTREAM) (HBE_STREAM);<BR>typedef
VOID (*BEVERSION) (BE_VERSION*);<BR><BR>#define
TEXT_BEINITSTREAM "beInitStream"<BR>#define
TEXT_BEENCODECHUNK "beEncodeChunk"<BR>#define TEXT_BEDEINITSTREAM
"beDeinitStream"<BR>#define
TEXT_BECLOSESTREAM "beCloseStream"<BR>#define
TEXT_BEVERSION "beVersion"<BR><BR>/*
<BR>BE_ERR beInitStream(BE_CONFIG *beConfig, PDWORD dwSamples, PDWORD
dwBufferSize, <BR> PHBE_STREAM phbeStream);<BR>BE_ERR
beEncodeChunk(HBE_STREAM hbeStream, DWORD nSamples, PSHORT pSamples, PBYTE
pOutput,<BR> PDWORD pdwOutput);<BR>BE_ERR
beDeinitStream(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD
pdwOutput);<BR>BE_ERR beCloseStream(HBE_STREAM hbeStream);<BR>VOID
beVersion(BE_VERSION *beVersion);<BR>*/<BR><BR>#else<BR><BR>extern "C"
__declspec(dllexport) BE_ERR beInitStream(BE_CONFIG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -