Jump to content

problem with "lame_enc.dll" convert audio file


Recommended Posts

I wrote a script to convert an audio file to .mp3 and I have to use "lame_enc.dll". May the converted file out wrong? someone just tell me why!


my script

#include <WinAPI.au3>

Global $h_LameEncDLL = _Open_LameEnc(@ScriptDir & "\lame_enc.dll")
If @error Then Exit

OnAutoItExitRegister("_Close_LameEnc")

Global Const $tag_BE_CONFIG = _ ;   {
        "DWORD  dwConfig;" & _ ;            // BE_CONFIG_LAME
        "DWORD  dwStructVersion;" & _ ;    // LAME header version 1
        "DWORD  dwStructSize;" & _ ;       // Size of this structure (332 in autoit, should be 331)
        "DWORD  dwSampleRate;" & _ ;        // SAMPLERATE OF INPUT FILE
        "DWORD  dwReSampleRate;" & _ ;  // DOWNSAMPLERATE, 0=ENCODER DECIDES
        "LONG   nMode;" & _ ;               // BE_MP3_MODE_STEREO, BE_MP3_MODE_DUALCHANNEL, BE_MP3_MODE_MONO
        "DWORD  dwBitrate;" & _ ;           // CBR bitrate, VBR min bitrate
        "DWORD  dwMaxBitrate;" & _ ;        // CBR ignored, VBR Max bitrate
        "LONG   nPreset;" & _ ;         // Quality preset, use one of the settings of the LAME_QUALITY_PRESET enum
        "DWORD  dwMpegVersion;" & _ ;       // FUTURE USE, MPEG-1 OR MPEG-2
        "DWORD  dwPsyModel;" & _ ;          // FUTURE USE, SET TO 0
        "DWORD  dwEmphasis;" & _ ;          // FUTURE USE, SET TO 0
        "BOOL   bPrivate;" & _ ;            // Set Private Bit (TRUE/FALSE)
        "BOOL   bCRC;" & _ ;                // Insert CRC (TRUE/FALSE)
        "BOOL   bCopyright;" & _ ;          // Set Copyright Bit (TRUE/FALSE)
        "BOOL   bOriginal;" & _ ;           // Set Original Bit (TRUE/FALSE)
        "BOOL   bWriteVBRHeader;" & _ ; // WRITE XING VBR HEADER (TRUE/FALSE)
        "BOOL   bEnableVBR;" & _ ;          // USE VBR ENCODING (TRUE/FALSE)
        "INT    nVBRQuality;" & _ ;     // VBR QUALITY 0..9
        "DWORD  dwVbrAbr_bps;" & _ ;        // Use ABR in stead of nVBRQuality
        "UINT   nVbrMethod;" & _ ;
        "BOOL   bNoRes; " & _ ;         // Disable Bit resorvoir (TRUE/FALSE)
        "BOOL   bStrictIso;" & _ ;          // Use strict ISO encoding rules (TRUE/FALSE)
        "WORD   nQuality;" & _ ;            // Quality Setting, HIGH BYTE should be NOT LOW byte, otherwhise quality=5
        "BYTE   btReserved[" & 255 - 4 * 4 - 2 & "]"

Global Const $BE_CONFIG_LAME = 256

#cs
    #define     BE_MP3_MODE_STEREO      0
    #define     BE_MP3_MODE_JSTEREO     1
    #define     BE_MP3_MODE_DUALCHANNEL 2
    #define     BE_MP3_MODE_MONO        3
#ce
#cs
    LQP_NOPRESET            =-1,

    // QUALITY PRESETS
    LQP_NORMAL_QUALITY      = 0,
    LQP_LOW_QUALITY         = 1,
    LQP_HIGH_QUALITY        = 2,
    LQP_VOICE_QUALITY       = 3,
    LQP_R3MIX               = 4,
    LQP_VERYHIGH_QUALITY    = 5,
    LQP_STANDARD            = 6,
    LQP_FAST_STANDARD       = 7,
    LQP_EXTREME             = 8,
    LQP_FAST_EXTREME        = 9,
    LQP_INSANE              = 10,
    LQP_ABR                 = 11,
    LQP_CBR                 = 12,
    LQP_MEDIUM              = 13,
    LQP_FAST_MEDIUM         = 14,

    // NEW PRESET VALUES
    LQP_PHONE   =1000,
    LQP_SW      =2000,
    LQP_AM      =3000,
    LQP_FM      =4000,
    LQP_VOICE   =5000,
    LQP_RADIO   =6000,
    LQP_TAPE    =7000,
    LQP_HIFI    =8000,
    LQP_CD      =9000,
    LQP_STUDIO  =10000
#ce

Local $sFileOpenDialog = FileOpenDialog("select a .Wav file.", @WorkingDir, "wav files (*.*)", 7)
If @error Then Exit 1

_audio_Converttomp3($sFileOpenDialog, $sFileOpenDialog & ".mp3")

Func _audio_Converttomp3($sFileTocovertPath, $sSavefilepath, $mp3Rate = 128)

    Local $tCfg = DllStructCreate($tag_BE_CONFIG)
    DllStructSetData($tCfg, "dwConfig", 256) ;// BE_CONFIG_LAME
    DllStructSetData($tCfg, "dwStructVersion", 1) ;// Struct version (LVH1)
    DllStructSetData($tCfg, "dwStructSize", DllStructGetSize($tCfg)); // Struct Size
    DllStructSetData($tCfg, "dwSampleRate", 22100);         // INPUT FREQUENCY
    DllStructSetData($tCfg, "nMode", 3) ;BE_MP3_MODE_JSTEREO;   // OUTPUT IN JOINT STEREO
    DllStructSetData($tCfg, "dwBitrate", $mp3Rate);                   // MINIMUM BIT RATE
    DllStructSetData($tCfg, "nPreset", 12) ;LQP_CBR;        // QUALITY PRESET SETTING
    DllStructSetData($tCfg, "dwMpegVersion", 1);MPEG1;    // MPEG VERSION (I or II)
    DllStructSetData($tCfg, "bOriginal", 1);                    // SET ORIGINAL FLAG
    DllStructSetData($tCfg, "bWriteVBRHeader", 1) ;       // Write mp3 header, even on ABR or CBR mp3.

    Local $dwFileSize = FileGetSize($sFileTocovertPath), $clen

    Local $hReadin = _WinAPI_CreateFile($sFileTocovertPath, 2, 2)
    Local $hWriteOut = _WinAPI_CreateFile($sSavefilepath, 1, 4)

    ;Seek back to start of WAV file,
    ;but skip the first 44 bytes, since that's the WAV header
    _WinAPI_SetFilePointer($hReadin, 44, 0)
    _WinAPI_SetFilePointer($hWriteOut, 0, 2)

    Local $hStream, $iSamples, $iMP3Buffer

    _beInitStream(DllStructGetPtr($tCfg), $iSamples, $iMP3Buffer, $hStream)

    ; Lame encoder expects signed 16bit 2 bytes so use a SHORT data type
    Local $tWavBuf = DllStructCreate("SHORT[" & $iSamples & "]")

    ; Create MP3 buffer to receive the encoded mp3 data
    Local $tMP3Buf = DllStructCreate("BYTE[" & $iMP3Buffer & "]")

    Local $iOutput, $Nread, $NWrite, $mrlen = DllStructGetSize($tWavBuf);, $mrlen=$iSamples*2

    While True
        _WinAPI_ReadFile($hReadin, DllStructGetPtr($tWavBuf), $mrlen, $Nread)
        If $Nread = 0 Then ExitLoop
        ;Encode
        _beEncodeChunk($hStream, $Nread / 2, DllStructGetPtr($tWavBuf), DllStructGetPtr($tMP3Buf), $iOutput)
        ;write $iOutput bytes that are returned in tehe $tMP3Buf to disk
        _WinAPI_WriteFile($hWriteOut, DllStructGetPtr($tMP3Buf), $iOutput, $NWrite)
        $clen += $Nread
        ToolTip(StringFormat("Done: %0.2f%%     \r", 100 * ($clen / $dwFileSize)))
    WEnd

    _beDeinitStream($hStream, DllStructGetPtr($tMP3Buf), $iOutput)

    If $iOutput > 0 Then _WinAPI_WriteFile($hWriteOut, DllStructGetPtr($tMP3Buf), $iOutput, $NWrite)

    _WinAPI_CloseHandle($hReadin)
    _WinAPI_CloseHandle($hWriteOut)

    _beCloseStream($hStream)
    _beWriteVBRHeader("BELL.WAV")
EndFunc   ;==>_audio_Converttomp3

Func _Open_LameEnc($sLameEncDll = "lame_enc.dll")
    Local $h_LameEncDLL_Open = DllOpen($sLameEncDll)
    If @error Then Return SetError(@error)
    Return $h_LameEncDLL_Open
EndFunc   ;==>_Open_LameEnc
Func _beInitStream($pBeConfig, ByRef $iSamples, ByRef $iBufferSize, ByRef $hStream)
    Local $aReturn, $aResult[3]
    $aReturn = DllCall($h_LameEncDLL, "ulong:cdecl", "beInitStream", "ptr", $pBeConfig, "dword*", 0, "dword*", 0, "ptr*", 0)
    If @error Then Return SetError(-1, @error, @error = 0)
    $iSamples = $aReturn[2]
    $iBufferSize = $aReturn[3]
    $hStream = $aReturn[4]
    Return SetError($aReturn[0], 0, $aResult[0] = 0)
EndFunc   ;==>_beInitStream
Func _beEncodeChunk($hStream, $iSamples, $pWAVBuffer, $pMP3Buffer, ByRef $iOutput)
    Local $aReturn
    $aReturn = DllCall($h_LameEncDLL, "ulong:cdecl", "beEncodeChunk", "ptr", $hStream, "dword", $iSamples, "ptr", $pWAVBuffer, "ptr", $pMP3Buffer, "int*", 0)
    If @error Then Return SetError(-1, @error, @error = 0)
    $iOutput = $aReturn[5]
    Return SetError($aReturn[0], 0, $aReturn[0] = 0)
EndFunc   ;==>_beEncodeChunk
Func _beDeinitStream($hStream, $pMP3Buffer, ByRef $iOutput)
    Local $aReturn
    $aReturn = DllCall($h_LameEncDLL, "ulong:cdecl", "beDeinitStream", "ptr", $hStream, "ptr", $pMP3Buffer, "dword*", 0)
    If @error Then Return SetError(-1, 0, @error = 0)
    $iOutput = $aReturn[3]
    Return SetError($aReturn[0], $aReturn[3], $aReturn[0] = 0)
EndFunc   ;==>_beDeinitStream

Func _beVersion()
    Local $aReturn
    $aReturn = DllCall($h_LameEncDLL, "ulong:cdecl", "beVersion", "int*", 0)
    If @error Then Return SetError(-1, 0, @error = 0)
    Return $aReturn[0]
EndFunc   ;==>_beVersion

Func _beCloseStream($hStream)
    Local $aReturn
    $aReturn = DllCall($h_LameEncDLL, "ulong:cdecl", "beCloseStream", "ptr", $hStream)
    If @error Then Return SetError(-1, 0, @error = 0)
    Return SetError($aReturn[0], 0, $aReturn[0] = 0)
EndFunc   ;==>_beCloseStream

Func _beWriteVBRHeader($sMp3File)
    Local $aReturn
    $aReturn = DllCall($h_LameEncDLL, "ulong:cdecl", "beWriteVBRHeader", "str", $sMp3File)
    If @error Then Return SetError(-1, 0, @error = 0)
    Return SetError($aReturn[0], 0, $aReturn[0] = 0)
EndFunc   ;==>_beWriteVBRHeader

Func _Close_LameEnc()
    DllClose($h_LameEncDLL)
    $h_LameEncDLL = -1
EndFunc   ;==>_Close_LameEnc

sorry for my bad english :sweating:

 

thank you.

 

lame_enc.dll

12-1234.wav

Edited by Celtic88
Link to comment
Share on other sites

original c++ code

/*
 *  LAME DLL Sample Code.
 *
 *  Copyright (c) 2000 A.L. Faber
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 */


#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "BladeMP3EncDLL.h"

BEINITSTREAM        beInitStream=NULL;
BEENCODECHUNK       beEncodeChunk=NULL;
BEDEINITSTREAM      beDeinitStream=NULL;
BECLOSESTREAM       beCloseStream=NULL;
BEVERSION           beVersion=NULL;
BEWRITEVBRHEADER    beWriteVBRHeader=NULL;


// Main program
int main(int argc, char *argv[])
{   
    HINSTANCE   hDLL            =NULL;
    FILE*       pFileIn         =NULL;
    FILE*       pFileOut        =NULL;
    BE_VERSION  Version         ={0,};
    BE_CONFIG   beConfig        ={0,};

    CHAR        strFileIn[255]  ={'0',};
    CHAR        strFileOut[255] ={'0',};

    DWORD       dwSamples       =0;
    DWORD       dwMP3Buffer     =0;
    HBE_STREAM  hbeStream       =0;
    BE_ERR      err             =0;

    PBYTE       pMP3Buffer      =NULL;
    PSHORT      pWAVBuffer      =NULL;

    // check number of arguments
    if(argc != 2)
    {
        fprintf(stderr,"Usage: %s <filename.wav>\n", argv[0]);
        fprintf(stderr,"Descr: Short demo to show how to use the lame_enc.dll library file\n");
        fprintf(stderr,"Note : WAV file is assumed to to have the following parameters\n");
        fprintf(stderr,"     : 44100 Hz, stereo, 16 Bits per sample\n");
        return -1;
    }

    // Setup the file names
    strcpy(strFileIn ,argv[1]);
    strcpy(strFileOut,argv[1]);

    // Add mp3 extention
    strcat(strFileOut,".mp3");

    // Load lame_enc.dll library (Make sure though that you set the 
    // project/settings/debug Working Directory correctly, otherwhise the DLL can't be loaded

#ifdef _MSC_VER
    hDLL = LoadLibrary(".\\Debug\\lame_enc.dll");

  #ifdef _DEBUG
    hDLL = LoadLibrary(".\\Debug\\lame_enc.dll");
  #else
    hDLL = LoadLibrary(".\\Release\\lame_enc.dll");

    if ( NULL == hDLL )
    {
        hDLL = LoadLibrary(".\\Release_NASM\\lame_enc.dll");
    }
  #endif /* _DEBUG */
#else
        /*
          Don't worry about dll location.
          MSVC is the only compiler that creates
          .\Release\ or .\Debug\ directories.
        */
    hDLL = LoadLibrary("lame_enc.dll");
#endif /* _MSC_VER */

    if( NULL == hDLL )
    {
        fprintf(stderr,"Error loading lame_enc.DLL");
        return -1;
    }

    // Get Interface functions from the DLL
    beInitStream    = (BEINITSTREAM) GetProcAddress(hDLL, TEXT_BEINITSTREAM);
    beEncodeChunk   = (BEENCODECHUNK) GetProcAddress(hDLL, TEXT_BEENCODECHUNK);
    beDeinitStream  = (BEDEINITSTREAM) GetProcAddress(hDLL, TEXT_BEDEINITSTREAM);
    beCloseStream   = (BECLOSESTREAM) GetProcAddress(hDLL, TEXT_BECLOSESTREAM);
    beVersion       = (BEVERSION) GetProcAddress(hDLL, TEXT_BEVERSION);
    beWriteVBRHeader= (BEWRITEVBRHEADER) GetProcAddress(hDLL,TEXT_BEWRITEVBRHEADER);

    // Check if all interfaces are present
    if(!beInitStream || !beEncodeChunk || !beDeinitStream || !beCloseStream || !beVersion || !beWriteVBRHeader)
    {
        printf("Unable to get LAME interfaces");
        return -1;
    }

    // Get the version number
    beVersion( &Version );

    printf(
            "lame_enc.dll version %u.%02u (%u/%u/%u)\n"
            "lame_enc Engine %u.%02u\n"
            "lame_enc homepage at %s\n\n",  
            Version.byDLLMajorVersion, Version.byDLLMinorVersion,
            Version.byDay, Version.byMonth, Version.wYear,
            Version.byMajorVersion, Version.byMinorVersion,
            Version.zHomepage);

    // Try to open the WAV file, be sure to open it as a binary file!   
    pFileIn = fopen( strFileIn, "rb" );

    // Check file open result
    if(pFileIn == NULL)
    {
        fprintf(stderr,"Error opening %s", argv[1]);
        return -1;
    }

    // Open MP3 file
    pFileOut= fopen(strFileOut,"wb+");

    // Check file open result
    if(pFileOut == NULL)
    {
        fprintf(stderr,"Error creating file %s", strFileOut);
        return -1;
    }

    memset(&beConfig,0,sizeof(beConfig));                   // clear all fields

    // use the LAME config structure
    beConfig.dwConfig = BE_CONFIG_LAME;

    // this are the default settings for testcase.wav
    beConfig.format.LHV1.dwStructVersion    = 1;
    beConfig.format.LHV1.dwStructSize       = sizeof(beConfig);     
    beConfig.format.LHV1.dwSampleRate       = 44100;                // INPUT FREQUENCY
    beConfig.format.LHV1.dwReSampleRate     = 0;                    // DON"T RESAMPLE
    beConfig.format.LHV1.nMode              = BE_MP3_MODE_JSTEREO;  // OUTPUT IN STREO
    beConfig.format.LHV1.dwBitrate          = 128;                  // MINIMUM BIT RATE
    beConfig.format.LHV1.nPreset            = LQP_HIGH_QUALITY;     // QUALITY PRESET SETTING
    beConfig.format.LHV1.dwMpegVersion      = MPEG1;                // MPEG VERSION (I or II)
    beConfig.format.LHV1.dwPsyModel         = 0;                    // USE DEFAULT PSYCHOACOUSTIC MODEL 
    beConfig.format.LHV1.dwEmphasis         = 0;                    // NO EMPHASIS TURNED ON
    beConfig.format.LHV1.bOriginal          = TRUE;                 // SET ORIGINAL FLAG

//  beConfig.format.LHV1.dwMaxBitrate       = 320;                  // MAXIMUM BIT RATE
//  beConfig.format.LHV1.bCRC               = TRUE;                 // INSERT CRC
//  beConfig.format.LHV1.bCopyright         = TRUE;                 // SET COPYRIGHT FLAG   
//  beConfig.format.LHV1.bPrivate           = TRUE;                 // SET PRIVATE FLAG
//  beConfig.format.LHV1.bWriteVBRHeader    = TRUE;                 // YES, WRITE THE XING VBR HEADER
//  beConfig.format.LHV1.bEnableVBR         = TRUE;                 // USE VBR
//  beConfig.format.LHV1.nVBRQuality        = 5;                    // SET VBR QUALITY
    beConfig.format.LHV1.bNoRes             = TRUE;                 // No Bit resorvoir

// Preset Test
//  beConfig.format.LHV1.nPreset            = LQP_PHONE;

    // Init the MP3 Stream
    err = beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);

    // Check result
    if(err != BE_ERR_SUCCESSFUL)
    {
        fprintf(stderr,"Error opening encoding stream (%lu)", err);
        return -1;
    }


    // Allocate MP3 buffer
    pMP3Buffer = new BYTE[dwMP3Buffer];

    // Allocate WAV buffer
    pWAVBuffer = new SHORT[dwSamples];

    // Check if Buffer are allocated properly
    if(!pMP3Buffer || !pWAVBuffer)
    {
        printf("Out of memory");
        return -1;
    }

    DWORD dwRead=0;
    DWORD dwWrite=0;
    DWORD dwDone=0;
    DWORD dwFileSize=0;

    // Seek to end of file
    fseek(pFileIn,0,SEEK_END);

    // Get the file size
    dwFileSize=ftell(pFileIn);

    // Seek back to start of WAV file,
    // but skip the first 44 bytes, since that's the WAV header
    fseek(pFileIn,44,SEEK_SET);


    // Convert All PCM samples
    while ( (dwRead=fread(pWAVBuffer,sizeof(SHORT),dwSamples,pFileIn)) >0 )
    {
        // Encode samples
        err = beEncodeChunk(hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite);

        // Check result
        if(err != BE_ERR_SUCCESSFUL)
        {
            beCloseStream(hbeStream);
            fprintf(stderr,"beEncodeChunk() failed (%lu)", err);
            return -1;
        }
        
        // write dwWrite bytes that are returned in tehe pMP3Buffer to disk
        if(fwrite(pMP3Buffer,1,dwWrite,pFileOut) != dwWrite)
        {
            fprintf(stderr,"Output file write error");
            return -1;
        }

        dwDone += dwRead*sizeof(SHORT);

        printf("Done: %0.2f%%     \r", 100 * (float)dwDone/(float)(dwFileSize));
    }

    // Deinit the stream
    err = beDeinitStream(hbeStream, pMP3Buffer, &dwWrite);

    // Check result
    if(err != BE_ERR_SUCCESSFUL)
    {

        beCloseStream(hbeStream);
        fprintf(stderr,"beExitStream failed (%lu)", err);
        return -1;
    }

    // Are there any bytes returned from the DeInit call?
    // If so, write them to disk
    if(dwWrite)
    {
        if( fwrite( pMP3Buffer, 1, dwWrite, pFileOut ) != dwWrite )
        {
            fprintf(stderr,"Output file write error");
            return -1;
        }
    }

    // close the MP3 Stream
    beCloseStream( hbeStream );

    // Delete WAV buffer
    delete [] pWAVBuffer;

    // Delete MP3 Buffer
    delete [] pMP3Buffer;

    // Close input file
    fclose( pFileIn );

    // Close output file
    fclose( pFileOut );

    // Write the VBR Tag
    beWriteVBRHeader( strFileOut );

    // Were done, return OK result
    return 0;
}

BladeMP3EncDLL.h

/*
 * Blade Type of DLL Interface for Lame encoder
 *
 * Copyright (c) 1999-2002 A.L. Faber
 * Based on bladedll.h version 1.0 written by Jukka Poikolainen
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 */

#ifndef ___BLADEDLL_H_INCLUDED___
#define ___BLADEDLL_H_INCLUDED___

#ifdef __GNUC__
#define ATTRIBUTE_PACKED    __attribute__((packed))
#else
#define ATTRIBUTE_PACKED
#pragma pack(push)
#pragma pack(1)
#endif

#ifdef  __cplusplus
extern "C" {
#endif

/* encoding formats */

#define     BE_CONFIG_MP3           0                                       
#define     BE_CONFIG_LAME          256     

/* type definitions */

typedef     unsigned long           HBE_STREAM;
typedef     HBE_STREAM              *PHBE_STREAM;
typedef     unsigned long           BE_ERR;

/* error codes */

#define     BE_ERR_SUCCESSFUL                   0x00000000
#define     BE_ERR_INVALID_FORMAT               0x00000001
#define     BE_ERR_INVALID_FORMAT_PARAMETERS    0x00000002
#define     BE_ERR_NO_MORE_HANDLES              0x00000003
#define     BE_ERR_INVALID_HANDLE               0x00000004
#define     BE_ERR_BUFFER_TOO_SMALL             0x00000005

/* other constants */

#define     BE_MAX_HOMEPAGE         128

/* format specific variables */

#define     BE_MP3_MODE_STEREO      0
#define     BE_MP3_MODE_JSTEREO     1
#define     BE_MP3_MODE_DUALCHANNEL 2
#define     BE_MP3_MODE_MONO        3



#define     MPEG1   1
#define     MPEG2   0

#ifdef _BLADEDLL
#undef FLOAT
    #include <Windows.h>
#endif

#define CURRENT_STRUCT_VERSION 1
#define CURRENT_STRUCT_SIZE sizeof(BE_CONFIG)   // is currently 331 bytes


typedef enum
{
    VBR_METHOD_NONE         = -1,
    VBR_METHOD_DEFAULT      =  0,
    VBR_METHOD_OLD          =  1,
    VBR_METHOD_NEW          =  2,
    VBR_METHOD_MTRH         =  3,
    VBR_METHOD_ABR          =  4
} VBRMETHOD;

typedef enum 
{
    LQP_NOPRESET            =-1,

    // QUALITY PRESETS
    LQP_NORMAL_QUALITY      = 0,
    LQP_LOW_QUALITY         = 1,
    LQP_HIGH_QUALITY        = 2,
    LQP_VOICE_QUALITY       = 3,
    LQP_R3MIX               = 4,
    LQP_VERYHIGH_QUALITY    = 5,
    LQP_STANDARD            = 6,
    LQP_FAST_STANDARD       = 7,
    LQP_EXTREME             = 8,
    LQP_FAST_EXTREME        = 9,
    LQP_INSANE              = 10,
    LQP_ABR                 = 11,
    LQP_CBR                 = 12,
    LQP_MEDIUM              = 13,
    LQP_FAST_MEDIUM         = 14,

    // NEW PRESET VALUES
    LQP_PHONE   =1000,
    LQP_SW      =2000,
    LQP_AM      =3000,
    LQP_FM      =4000,
    LQP_VOICE   =5000,
    LQP_RADIO   =6000,
    LQP_TAPE    =7000,
    LQP_HIFI    =8000,
    LQP_CD      =9000,
    LQP_STUDIO  =10000

} LAME_QUALITY_PRESET;



typedef struct  {
    DWORD   dwConfig;           // BE_CONFIG_XXXXX
                                // Currently only BE_CONFIG_MP3 is supported
    union   {

        struct  {

            DWORD   dwSampleRate;       // 48000, 44100 and 32000 allowed
            BYTE    byMode;         // BE_MP3_MODE_STEREO, BE_MP3_MODE_DUALCHANNEL, BE_MP3_MODE_MONO
            WORD    wBitrate;       // 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256 and 320 allowed
            BOOL    bPrivate;       
            BOOL    bCRC;
            BOOL    bCopyright;
            BOOL    bOriginal;

            } mp3;                  // BE_CONFIG_MP3

            struct
            {
            // STRUCTURE INFORMATION
            DWORD           dwStructVersion;    
            DWORD           dwStructSize;

            // BASIC ENCODER SETTINGS
            DWORD           dwSampleRate;       // SAMPLERATE OF INPUT FILE
            DWORD           dwReSampleRate;     // DOWNSAMPLERATE, 0=ENCODER DECIDES  
            LONG            nMode;              // BE_MP3_MODE_STEREO, BE_MP3_MODE_DUALCHANNEL, BE_MP3_MODE_MONO
            DWORD           dwBitrate;          // CBR bitrate, VBR min bitrate
            DWORD           dwMaxBitrate;       // CBR ignored, VBR Max bitrate
            LONG            nPreset;            // Quality preset, use one of the settings of the LAME_QUALITY_PRESET enum
            DWORD           dwMpegVersion;      // FUTURE USE, MPEG-1 OR MPEG-2
            DWORD           dwPsyModel;         // FUTURE USE, SET TO 0
            DWORD           dwEmphasis;         // FUTURE USE, SET TO 0

            // BIT STREAM SETTINGS
            BOOL            bPrivate;           // Set Private Bit (TRUE/FALSE)
            BOOL            bCRC;               // Insert CRC (TRUE/FALSE)
            BOOL            bCopyright;         // Set Copyright Bit (TRUE/FALSE)
            BOOL            bOriginal;          // Set Original Bit (TRUE/FALSE)
            
            // VBR STUFF
            BOOL            bWriteVBRHeader;    // WRITE XING VBR HEADER (TRUE/FALSE)
            BOOL            bEnableVBR;         // USE VBR ENCODING (TRUE/FALSE)
            INT             nVBRQuality;        // VBR QUALITY 0..9
            DWORD           dwVbrAbr_bps;       // Use ABR in stead of nVBRQuality
            VBRMETHOD       nVbrMethod;
            BOOL            bNoRes;             // Disable Bit resorvoir (TRUE/FALSE)

            // MISC SETTINGS
            BOOL            bStrictIso;         // Use strict ISO encoding rules (TRUE/FALSE)
            WORD            nQuality;           // Quality Setting, HIGH BYTE should be NOT LOW byte, otherwhise quality=5

            // FUTURE USE, SET TO 0, align strucutre to 331 bytes
            BYTE            btReserved[255-4*sizeof(DWORD) - sizeof( WORD )];

            } LHV1;                 // LAME header version 1

        struct  {

            DWORD   dwSampleRate;
            BYTE    byMode;
            WORD    wBitrate;
            BYTE    byEncodingMethod;

        } aac;

    } format;
        
} BE_CONFIG, *PBE_CONFIG ATTRIBUTE_PACKED;


typedef struct  {

    // BladeEnc DLL Version number

    BYTE    byDLLMajorVersion;
    BYTE    byDLLMinorVersion;

    // BladeEnc Engine Version Number

    BYTE    byMajorVersion;
    BYTE    byMinorVersion;

    // DLL Release date

    BYTE    byDay;
    BYTE    byMonth;
    WORD    wYear;

    // BladeEnc Homepage URL

    CHAR    zHomepage[BE_MAX_HOMEPAGE + 1]; 

    BYTE    byAlphaLevel;
    BYTE    byBetaLevel;
    BYTE    byMMXEnabled;

    BYTE    btReserved[125];


} BE_VERSION, *PBE_VERSION ATTRIBUTE_PACKED;

#ifndef _BLADEDLL

typedef BE_ERR  (*BEINITSTREAM)         (PBE_CONFIG, PDWORD, PDWORD, PHBE_STREAM);
typedef BE_ERR  (*BEENCODECHUNK)        (HBE_STREAM, DWORD, PSHORT, PBYTE, PDWORD);

// added for floating point audio  -- DSPguru, jd
typedef BE_ERR  (*BEENCODECHUNKFLOATS16NI)  (HBE_STREAM, DWORD, PFLOAT, PFLOAT, PBYTE, PDWORD);
typedef BE_ERR  (*BEDEINITSTREAM)           (HBE_STREAM, PBYTE, PDWORD);
typedef BE_ERR  (*BECLOSESTREAM)            (HBE_STREAM);
typedef VOID    (*BEVERSION)                (PBE_VERSION);
typedef BE_ERR  (*BEWRITEVBRHEADER)         (LPCSTR);
typedef BE_ERR  (*BEWRITEINFOTAG)           (HBE_STREAM, LPCSTR );

#define TEXT_BEINITSTREAM               "beInitStream"
#define TEXT_BEENCODECHUNK              "beEncodeChunk"
#define TEXT_BEENCODECHUNKFLOATS16NI    "beEncodeChunkFloatS16NI"
#define TEXT_BEDEINITSTREAM             "beDeinitStream"
#define TEXT_BECLOSESTREAM              "beCloseStream"
#define TEXT_BEVERSION                  "beVersion"
#define TEXT_BEWRITEVBRHEADER           "beWriteVBRHeader"
#define TEXT_BEFLUSHNOGAP               "beFlushNoGap"
#define TEXT_BEWRITEINFOTAG             "beWriteInfoTag"


#else

__declspec(dllexport) BE_ERR    beInitStream(PBE_CONFIG pbeConfig, PDWORD dwSamples, PDWORD dwBufferSize, PHBE_STREAM phbeStream);
__declspec(dllexport) BE_ERR    beEncodeChunk(HBE_STREAM hbeStream, DWORD nSamples, PSHORT pSamples, PBYTE pOutput, PDWORD pdwOutput);

// added for floating point audio  -- DSPguru, jd
__declspec(dllexport) BE_ERR    beEncodeChunkFloatS16NI(HBE_STREAM hbeStream, DWORD nSamples, PFLOAT buffer_l, PFLOAT buffer_r, PBYTE pOutput, PDWORD pdwOutput);
__declspec(dllexport) BE_ERR    beDeinitStream(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD pdwOutput);
__declspec(dllexport) BE_ERR    beCloseStream(HBE_STREAM hbeStream);
__declspec(dllexport) VOID      beVersion(PBE_VERSION pbeVersion);
__declspec(dllexport) BE_ERR    beWriteVBRHeader(LPCSTR lpszFileName);
__declspec(dllexport) BE_ERR    beFlushNoGap(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD pdwOutput);
__declspec(dllexport) BE_ERR    beWriteInfoTag( HBE_STREAM hbeStream, LPCSTR lpszFileName );

#endif

#ifndef __GNUC__
#pragma pack(pop)
#endif

#ifdef  __cplusplus
}
#endif

#endif

 

Edited by Celtic88
Link to comment
Share on other sites

In your documentation 

// Close input file
    fclose( pFileIn );

    // Close output file
    fclose( pFileOut );

    // Write the VBR Tag
    beWriteVBRHeader( strFileOut );

MP3 file should be closed before you use the "_beWriteVBRHeader" function.

and you write the header on the wav file instead of the mp3 output file !

It should be

_WinAPI_CloseHandle($rf)
_WinAPI_CloseHandle($hWriteOut)
_beWriteVBRHeader("m.mp3")

But there must be another mistake because it doesn't resolve the problem...:sweating:

 

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

So I'm not MPV I can't answer. :(

Link to comment
Share on other sites

@wakillon

thank for your replay ;

allo MPV, is there a solution?

Same error again !

_beCloseStream($hStream)
    _beWriteVBRHeader("BELL.WAV")
EndFunc   ;==>_audio_Converttomp3

Replace _beWriteVBRHeader("BELL.WAV") by _beWriteVBRHeader ( $sSavefilepath )

Edit : lame_enc.dll doesn't seems to support 8 Bits Wav Files as your "12-1234.wav" or "Bell.wav" files.

but with a 16 Bits Wav file, it works well  ! ;)

 

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Same error again !

_beCloseStream($hStream)
    _beWriteVBRHeader("BELL.WAV")
EndFunc   ;==>_audio_Converttomp3

Replace _beWriteVBRHeader("BELL.WAV") by _beWriteVBRHeader ( $sSavefilepath )

Edit : lame_enc.dll doesn't seems to support 8 Bits Wav Files as your "12-1234.wav" or "Bell.wav" files.

but with a 16 Bits Wav file, it works well  ! ;)

 

@Danyfirex

thank you bro :)

Link to comment
Share on other sites

For get bits you can do it using AutoIt ways.

Local $sFile="12-1234.wav"
Local $tData=DllStructCreate("byte Data[" & FileGetSize($sFile) & "]")
$tData.Data=FileRead($sFile)
Local $tInfo=DllStructCreate("byte Data[34];word Bits",DllStructGetPtr($tData))
MsgBox(0,"",$tInfo.Bits)

Saludos

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...