|
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
Tom42
Anmeldungsdatum: 09.02.2005 Beiträge: 21 Wohnort: Wolfsburg
|
Verfasst am: 16.10.2010, 01:42 Titel: FreeBasic MP3 Encoder Example |
|
|
Hallo FB Freunde
Hier ein Beispiel Code in FB um mit der Lame_ENC.dll Mp3 zu Encoden
zuerst das BI File
Code: |
' 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.
' *** Adapted to FreeBasic by Electrik (Author Unknown) ***
' *** Found this in http://freebasic.justforum.net/forum.htm (RU) ***
' *** New `Code Cleaning` by T.Breit 2010 ***
' *** Download the Full packed ftp:\\freebasic.dyndns.org ***
' *** Click CheckBox in IE8 for Anonymous Login ***
#Include "windows.bi"
#Inclib "lame_enc"
#Ifndef __BLADEDLL_BI__
#Define __BLADEDLL_BI__
#Pragma Once
'Encoding Formats - Encoding-Formate
#Define BE_CONFIG_MP3 0
#Define BE_CONFIG_LAME 256
'Type Definitions
Type As dword HBE_STREAM
Type As HBE_STREAM Ptr PHBE_STREAM
type As dword BE_ERR
'Error Codes - Fehlercodes
#Define BE_ERR_SUCCESSFUL &h00000000
#Define BE_ERR_INVALID_FORMAT &h00000001
#Define BE_ERR_INVALID_FORMAT_PARAMETERS &h00000002
#Define BE_ERR_NO_MORE_HANDLES &h00000003
#Define BE_ERR_INVALID_HANDLE &h00000004
#Define BE_ERR_BUFFER_TOO_SMALL &h00000005
'Other Constants - Andere Konstanten
#Define BE_MAX_HOMEPAGE 128
'Format Specific Variables - Format Variablen
#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
#define CURRENT_STRUCT_VERSION 1
#define CURRENT_STRUCT_SIZE sizeof(BE_CONFIG) ' is currently 331 bytes
Enum VBRMETHOD
VBR_METHOD_NONE = -1
VBR_METHOD_DEFAULT = 0
VBR_METHOD_OLD = 1
VBR_METHOD_NEW = 2
VBR_METHOD_MTRH = 3
VBR_METHOD_ABR = 4
End Enum
'Quality Presets - Qualität Einstellungen
Enum LAME_QUALITY_PRESET
LQP_NOPRESET =-1
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
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
End Enum
'BE_CONFIG_MP3
'Currently only BE_CONFIG_MP3 is supported
'Derzeit wird nur BE_CONFIG_MP3 unterstützt
Type MP3 Field = 1 ' BE_CONFIG_MP3
As dword dwSampleRate ' 48000, 44100 32000
As Byte byMode ' BE_MP3_MODE_STEREO, BE_MP3_MODE_DUALCHANNEL, BE_MP3_MODE_MONO
As word wBitrate ' 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256 and 320 allowed
As BOOL bPrivate
As BOOL bCRC
As BOOL bCopyright
As BOOL bOriginal
End Type
Type LHV1 Field = 1 'LAME Header
As dword dwStructVersion 'STRUCTURE INFORMATION
As dword dwStructSize
As dword dwSampleRate 'SAMPLERATE OF INPUT FILE
As dword dwReSampleRate 'DOWNSAMPLERATE, 0=ENCODER DECIDES
As LONG nMode 'BE_MP3_MODE_STEREO, BE_MP3_MODE_DUALCHANNEL, BE_MP3_MODE_MONO
As dword dwBitrate 'CBR bitrate, VBR min bitrate
As dword dwMaxBitrate 'CBR ignored, VBR Max bitrate
As LONG nPreset 'Quality preset, use one of the settings of the LAME_QUALITY_PRESET enum
As dword dwMpegVersion 'FUTURE USE, MPEG-1 OR MPEG-2
As dword dwPsyModel 'FUTURE USE, SET TO 0
As dword dwEmphasis 'FUTURE USE, SET TO 0
As BOOL SbPrivate 'Set Private Bit (TRUE/FALSE)
As BOOL IbCRC 'Insert CRC (TRUE/FALSE)
As BOOL SbCopyright 'Set Copyright Bit (TRUE/FALSE)
As BOOL bOriginal 'Set Original Bit (TRUE/FALSE)
As BOOL bWriteVBRHeader 'WRITE XING VBR HEADER (TRUE/FALSE)
As BOOL bEnableVBR 'USE VBR ENCODING (TRUE/FALSE)
As INTEGER nVBRQuality 'VBR QUALITY 0..9
As dword dwVbrAbr_bps 'Use ABR in stead of nVBRQuality
As VBRMETHOD nVbrMethod
As BOOL bNoRes 'Disable Bit resorvoir (TRUE/FALSE)
As BOOL bStrictIso 'Use strict ISO encoding rules (TRUE/FALSE)
As WORD nQuality 'HIGH BYTE should be NOT LOW byte, otherwhise quality=5
As BYTE btReserved(255-4*Sizeof(dword) - SizeOf( WORD )-1)
'FUTURE USE, SET TO 0, align strucutre to 331 bytes
End Type
Type AAC Field = 1
As dword dwSampleRate
As BYTE byMode
As WORD wBitrate
As BYTE byEncodingMethod
End Type
Union FORMAT Field = 1
As MP3 mp3
As LHV1 lhv1
As AAC aac
End Union
Type BE_CONFIG Field = 1
As dword dwConfig
As FORMAT format
End Type
Type As BE_CONFIG Ptr PBE_CONFIG
Type BE_VERSION
As BYTE byDLLMajorVersion
As BYTE byDLLMinorVersion
As BYTE byMajorVersion
As BYTE byMinorVersion
As BYTE byDay
As BYTE byMonth
As WORD wYear
As ZString * BE_MAX_HOMEPAGE + 1 zHomepage
As BYTE byAlphaLevel
As BYTE byBetaLevel
As BYTE byMMXEnabled
As BYTE btReserved(125-1)
End Type
Type As BE_VERSION Ptr PBE_VERSION
Extern "c"
Declare Function beInitStream Alias "beInitStream" _
(Byval pbeConfig As PBE_CONFIG, Byval dwSamples As PDWORD, _
Byval dwBufferSize As PDWORD, Byval phbeStream As PHBE_STREAM) As BE_ERR
Declare Function beEncodeChunk Alias "beEncodeChunk" _
(Byval hbeStream As HBE_STREAM, Byval nSamples As DWORD, _
Byval pSamples As PSHORT, Byval pOutput As PBYTE, _
Byval pdwOutput As PDWORD )As BE_ERR
Declare Function beEncodeChunkFloatS16NI Alias "beEncodeChunkFloatS16NI" _
(Byval hbeStream As HBE_STREAM, Byval nSamples As DWORD, _
Byval buffer_l As PFLOAT, Byval buffer_r As PFLOAT, _
Byval pOutput As PBYTE, Byval pdwOutput As PDWORD) As BE_ERR
declare function beDeinitStream alias "beDeinitStream" _
(byval hbeStream as HBE_STREAM, byval pOutput as PBYTE, _
byval pdwOutput as PDWORD) as BE_ERR
declare function beCloseStream alias "beCloseStream" _
(byval hbeStream as HBE_STREAM) as BE_ERR
declare function beVersion alias "beVersion" _
(byval pbeVersion as PBE_VERSION) as PCVOID
declare function beWriteVBRHeader alias "beWriteVBRHeader" _
(byval lpszFileName as LPCSTR) as BE_ERR
declare function beFlushNoGap alias "beFlushNoGap" _
(byval hbeStream as HBE_STREAM, byval pOutput as PBYTE, _
byval pdwOutput as PDWORD) as BE_ERR
declare function beWriteInfoTag alias "beWriteInfoTag" _
(byval hbeStream as HBE_STREAM, byval lpszFileName as LPCSTR) as BE_ERR
End Extern
#EndIf
|
und nun den FB Code
FBME.bas
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.
' *** Adapted to FreeBasic by Electrik (Author Unknown) ***
' *** Found this in http://freebasic.justforum.net/forum.htm (RU) ***
' *** New `Code Cleaning` by T.Breit 2010 ***
' *** Download the Full packed ftp:\\freebasic.dyndns.org ***
' *** Click CheckBox in IE8 for Anonymous Login ***
#include "windows.bi"
#Include "file.bi"
#include "crt.bi"
#include "LameENC\Lame_enc.bi"
#define argc __fb_argc__
#define argv __fb_argv__
dim as BE_VERSION Version
Dim as BE_CONFIG beConfig
Dim as zstring * 255 strFileIn
Dim as zstring * 255 strFileOut
Dim as DWORD dwSamples
Dim as dword dwMP3Buffer
Dim as HBE_STREAM hbeStream
Dim as BE_ERR beErr
Dim as PBYTE pMP3Buffer
Dim as PSHORT pWAVBuffer
Dim as integer fileIn
Dim as integer fileOut
'Check Number of Arguments
if argc <> 2 then
printf(!"FreeBasic MP3 Encoder Example 2010 \n")
printf(!"Usage: %s <filename.wav>\n",*argv[0])
printf(!"Example: %s sound.wav\n",*argv[0])
End -1
end if
'Setup the file names
strFileIn = *argv[1]
strFileOut = *argv[1] & ".mp3"
beVersion(@version)
printf _
(!"LameEnc Dll Version %u.%02u (%u/%u/%u)\n" _
!"LameEnc Engine %u.%02u\n" _
!"LameEnc homepage at %s\n\n", _
Version.byDLLMajorVersion, Version.byDLLMinorVersion, _
Version.byDay, Version.byMonth, Version.wYear, _
Version.byMajorVersion, Version.byMinorVersion, _
Version.zHomepage)
if not fileExists(strFileIn) then
printf("Error opening %s, file not exists", argv[1])
End -1
end if
fileIn = FreeFile
open strFileIn for binary as #fileIn
fileOut = FreeFile
open strFileOut for binary as #fileOut
' be_Config
beConfig.dwConfig = BE_CONFIG_LAME
beConfig.format.LHV1.dwStructVersion = 1
beConfig.format.LHV1.dwStructSize = sizeof(BE_CONFIG)
beConfig.format.LHV1.dwSampleRate = 44100
beConfig.format.LHV1.dwReSampleRate = 0
beConfig.format.LHV1.nMode = BE_MP3_MODE_JSTEREO
beConfig.format.LHV1.dwBitrate = 128
beConfig.format.LHV1.nPreset = LQP_VERYHIGH_QUALITY
beConfig.format.LHV1.dwMpegVersion = MPEG1
beConfig.format.LHV1.dwPsyModel = 0
beConfig.format.LHV1.dwEmphasis = 0
beConfig.format.LHV1.bOriginal = TRUE
beConfig.format.LHV1.bWriteVBRHeader = TRUE
beConfig.format.LHV1.bNoRes = TRUE
beErr = beInitStream(@beConfig, @dwSamples, @dwMP3Buffer, @hbeStream)
If beErr <> BE_ERR_SUCCESSFUL then
printf("Error opening encoding stream (%lu)", beErr)
End -1
end if
pMP3Buffer = new byte [dwMP3Buffer] ' mp3
pWAVBuffer = new short[dwSamples] ' wav
if pMP3Buffer = 0 then
printf("not enough memory for mp3Buffer")
end -1
end if
if pWAVBuffer = 0 then
printf("not enough memory for wavBuffer")
end -1
end if
Dim as DWORD dwRead
Dim as DWORD dwWrite 'mp3
Dim as DWORD dwDone
Dim as DWORD dwFileSize 'wav
dwFileSize = lof(fileIn)
seek #fileIn,45
dwRead = 1
while dwRead <> 0
get #fileIn,,*pWAVBuffer,dwSamples,dwRead
if dwRead = 0 then continue while
beErr = beEncodeChunk(hbeStream, dwRead/sizeof(SHORT), pWAVBuffer, pMP3Buffer, @dwWrite)
if beErr <> BE_ERR_SUCCESSFUL then
beCloseStream(hbeStream)
printf("beEncodeChunk() failed (%lu)", beErr)
end -1
end if
If put( #fileOut,,*pMP3Buffer,dwWrite) <> 0 then
printf("Output file write error")
end -1
end if
dwDone += dwRead
printf(!"Encoding : %0.2f%% \r", 100 * cast(SINGLE,dwDone)/cast(SINGLE,dwFileSize))
Wend
beErr = beDeinitStream(hbeStream, pMP3Buffer, @dwWrite)
if beErr <> BE_ERR_SUCCESSFUL then
beCloseStream(hbeStream)
printf("beExitStream failed (%lu)", beErr)
end -1
end if
if dwWrite then
if put( #fileOut,,*pMP3Buffer,dwWrite) <> 0 then
'printf("Output file write error")
end -1
end if
end if
beCloseStream( hbeStream )
delete[] pWAVBuffer
delete[] pMP3Buffer
close
'beWriteInfoTag( hbeStream, strFileOut )
printf(!"\nDone !\n")
End 0
|
Viel spass und gruss
Tom |
|
Nach oben |
|
|
Tom42
Anmeldungsdatum: 09.02.2005 Beiträge: 21 Wohnort: Wolfsburg
|
Verfasst am: 16.10.2010, 16:34 Titel: FreeBasic MP3 Encoder Example |
|
|
Hi @ All
da hier einige Versucht haben auf meinen FTP-Server
zugang zu bekommen hier noch mal der Link
ftp:\\freebasic.dyndns.org
User : Anonymous
Passwort :ieuser@microsoft.com
denn hacken setzten in der im IE reich aber auch.
Zu finden ist das Packet unter LIBs
Gruss
Tom |
|
Nach oben |
|
|
Tom42
Anmeldungsdatum: 09.02.2005 Beiträge: 21 Wohnort: Wolfsburg
|
Verfasst am: 18.10.2010, 11:23 Titel: FreeBasic MP3 Encoder Example |
|
|
Hi,
ein paar Fix in FreeBasic MP3 Encoder Example
FBME 0.02A
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.
' *** Adapted to FreeBasic by Electrik (Author Unknown) ***
' *** Found this in http://freebasic.justforum.net/forum.htm (RU) ***
' *** New `Code Cleaning` by T.Breit 2010 ***
' *** Download the Full packed ftp:\\freebasic.dyndns.org ***
' *** ftpuser for Login no Passwort ***
' *** LIBs/FBME-LameEnc MP3 Example.rar ***
' Version 0.02 Alpha
#include "windows.bi"
#Include "file.bi"
#include "crt.bi"
#include "LameENC\Lame_enc.bi"
#define argc __fb_argc__
#define argv __fb_argv__
dim as BE_VERSION Version
Dim as BE_CONFIG beConfig
Dim as zstring * 255 strFileIn
Dim as zstring * 255 strFileOut
Dim as DWORD dwSamples
Dim as dword dwMP3Buffer
Dim as HBE_STREAM hbeStream
Dim as BE_ERR beErr
Dim as PBYTE pMP3Buffer
Dim as PSHORT pWAVBuffer
Dim as integer fileIn
Dim as integer fileOut
DECLARE SUB MainText()
DECLARE SUB UsageText(Info As string)
'Check Number of Arguments
if argc <> 2 then
MainText ()
UsageText(*argv[0])
End -1
end if
'Setup the file names
strFileIn = *argv[1]
strFileOut = Left(*argv[1],Len(*argv[1])-4) & ".mp3"
beVersion(@version)
MainText
printf(!"LameEnc Dll Version %u.%02u (%u/%u/%u)"!" Engine %u.%02u\n"_
!"Homepage at %s\n\n", _
Version.byDLLMajorVersion, Version.byDLLMinorVersion, _
Version.byDay, Version.byMonth, Version.wYear, _
Version.byMajorVersion, Version.byMinorVersion, _
Version.zHomepage)
if not fileExists(strFileIn) then
printf(!"Error opening %s, file not exists", argv[1])
End -1
end if
fileIn = FreeFile
open strFileIn for binary as #fileIn
fileOut = FreeFile
open strFileOut for binary as #fileOut
' be_Config
beConfig.dwConfig = BE_CONFIG_LAME
beConfig.format.LHV1.dwStructVersion = 1
beConfig.format.LHV1.dwStructSize = sizeof(BE_CONFIG)
beConfig.format.LHV1.dwSampleRate = 44100
beConfig.format.LHV1.dwReSampleRate = 0
beConfig.format.LHV1.nMode = BE_MP3_MODE_JSTEREO
beConfig.format.LHV1.dwBitrate = 128
beConfig.format.LHV1.nPreset = LQP_VERYHIGH_QUALITY
beConfig.format.LHV1.dwMpegVersion = MPEG1
beConfig.format.LHV1.dwPsyModel = 0
beConfig.format.LHV1.dwEmphasis = 0
beConfig.format.LHV1.bOriginal = TRUE
beConfig.format.LHV1.bWriteVBRHeader = TRUE
beConfig.format.LHV1.bNoRes = TRUE
beErr = beInitStream(@beConfig, @dwSamples, @dwMP3Buffer, @hbeStream)
If beErr <> BE_ERR_SUCCESSFUL then
printf(!"Error opening encoding stream (%lu)", beErr)
End -1
end if
pMP3Buffer = new byte [dwMP3Buffer] ' mp3
pWAVBuffer = new short[dwSamples] ' wav
if pMP3Buffer = 0 then
printf(!"not enough memory for mp3Buffer")
end -1
end if
if pWAVBuffer = 0 then
printf(!"not enough memory for wavBuffer")
end -1
end if
Dim as DWORD dwRead
Dim as DWORD dwWrite 'mp3
Dim as DWORD dwDone
Dim as DWORD dwFileSize 'wav
dwFileSize = lof(fileIn)
seek #fileIn,45
dwRead = 1
while dwRead <> 0
Get #fileIn,,*pWAVBuffer,dwSamples,dwRead
if dwRead = 0 then continue while
beErr = beEncodeChunk(hbeStream, dwRead/sizeof(SHORT), pWAVBuffer, pMP3Buffer, @dwWrite)
if beErr <> BE_ERR_SUCCESSFUL then
beCloseStream(hbeStream)
printf(!"beEncodeChunk() failed (%lu)", beErr)
end -1
end if
If put( #fileOut,,*pMP3Buffer,dwWrite) <> 0 Then
printf(!"Output file write error")
end -1
end if
dwDone += dwRead
printf(!"Encoding %s -> %0.2f%% \r",UCase(strFileOut), 100 * cast(SINGLE,dwDone)/cast(SINGLE,dwFileSize))
Wend
beErr = beDeinitStream(hbeStream, pMP3Buffer, @dwWrite)
if beErr <> BE_ERR_SUCCESSFUL then
beCloseStream(hbeStream)
printf(!"beExitStream failed (%lu)", beErr)
end -1
end if
if dwWrite then
if put( #fileOut,,*pMP3Buffer,dwWrite) <> 0 then
printf(!"Output file write error\n")
end -1
end if
end if
beCloseStream( hbeStream )
delete[] pWAVBuffer
delete[] pMP3Buffer
close
'beWriteInfoTag( hbeStream, strFileOut )
printf(!"\nDone !\n")
End 0
Sub MainText ()
printf(!"FreeBasic MP3 Encoder Example for the LameEnc.DLL 2010 (c) by Thomas Breit \n")
End Sub
Sub UsageText (Info As String)
printf(!"Usage: %s <Filename.wav>\n",UCase(Info))
printf(!"Example: %s Sound.wav\n",UCase(Info))
End Sub
|
Oder Download unter ftp:\\freebasic.dyndns.org
Username -> ftpuser
Gruss
Thomas |
|
Nach oben |
|
|
Westbeam
Anmeldungsdatum: 22.12.2009 Beiträge: 760
|
Verfasst am: 18.10.2010, 13:15 Titel: |
|
|
Hey
Danke dafür. Genauso etwas habe ich gesucht für mein Projekt. Ich werde mir mal deinen Code anschauen |
|
Nach oben |
|
|
Tom42
Anmeldungsdatum: 09.02.2005 Beiträge: 21 Wohnort: Wolfsburg
|
Verfasst am: 16.11.2010, 02:22 Titel: FBME 0.04 A |
|
|
Hallo,
hier noch mal die derzeit aktuelle Version.
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.
Const As String FBMEVersion ="FBME Version 0.05A %s"
' *** Adapted to FreeBasic by Electrik (Author Unknown) ***
' *** Found this in http://freebasic.justforum.net/forum.htm (RU) ***
' *** New `Code Cleaning` by T.Breit 2010 ***
' *** Download the Full packed ftp:\\freebasic.dyndns.org ***
' *** ftpuser for Login no Passwort ***
' *** LIBs/FBME-LameEnc MP3 Example.rar ***
'
#include "windows.bi"
#Include "win\shellapi.bi"
#Include "BiTools\FindFile.bi"
#Include "file.bi"
#include "crt.bi"
#include "LameENC\Lame_enc.bi"
#define argc __FB_ARGC__
#define argv __FB_ARGV__
Const As String CDRip = "cdda2wav.exe"
Dim As String Wav = Mid (*argv[1],Len(*argv[1])-3,Len(*argv[1]))
Dim as BE_VERSION Version
Dim as BE_CONFIG beConfig
Dim as zstring * 255 strFileIn
Dim as zstring * 255 strFileOut
Dim as DWORD dwSamples
Dim as dword dwMP3Buffer
Dim as HBE_STREAM hbeStream
Dim as BE_ERR beErr
Dim as PBYTE pMP3Buffer
Dim as PSHORT pWAVBuffer
Dim as integer fileIn
Dim as integer fileOut
Dim As Integer choice,Opt
Dim as DWORD dwRead
Dim as DWORD dwWrite 'mp3
Dim as DWORD dwDone
Dim as DWORD dwFileSize 'wav
'
Dim As String cstr,prgPath
'
Declare SUB MainText()
DECLARE SUB UsageText(Info As string)
Declare Sub Help ()
' Lame CONFIG
'****************************************************************
beConfig.dwConfig = BE_CONFIG_LAME
beConfig.format.LHV1.dwStructVersion = 1
beConfig.format.LHV1.dwStructSize = sizeof(BE_CONFIG)
beConfig.format.LHV1.dwSampleRate = 44100
beConfig.format.LHV1.dwReSampleRate = 0
beConfig.format.LHV1.nMode = BE_MP3_MODE_JSTEREO
beConfig.format.LHV1.dwBitrate = 192
beConfig.format.LHV1.nPreset = LQP_NOPRESET
beConfig.format.LHV1.dwMpegVersion = MPEG1
beConfig.format.LHV1.dwPsyModel = 0
beConfig.format.LHV1.dwEmphasis = 0
beConfig.format.LHV1.bOriginal = TRUE
beConfig.format.LHV1.nVbrMethod = LQP_VERYHIGH_QUALITY
beConfig.format.LHV1.nVBRQuality = 0
'beConfig.format.LHV1.dwVbrAbr_bps = 320000
beConfig.format.LHV1.IbCRC = TRUE
beConfig.format.LHV1.bWriteVBRHeader = TRUE
beConfig.format.LHV1.bNoRes = TRUE
'*****************************************************************
' prgPath=GetExePath(cstr)
'Check Number of Arguments
If argc <> 2 Then
MainText ()
UsageText(*argv[0])
cstr=*argv[0]
'Print Left(*argv[argc],Len(*argv[argc])-4)
End -1
End If
'Check Arguments
If *argv[1]="--h" Or *argv[1]="--help" Then
MainText ()
Help ()
UsageText(*argv[0])
End -1
End If
If *argv[1]="--v" Or *argv[1]="--version" Then
MainText()
printf(FBMEVersion),__DATE__
End -1
EndIf
If Wav = ".wav" Then
MainText()
strFileIn = *argv[1]
strFileOut = Left(*argv[1],Len(*argv[1])-4) & ".mp3"
beVersion(@version)
' MainText
printf(!"LameEnc Dll Version %u.%02u (%u/%u/%u)"!" Engine %u.%02u\n"_
!"Homepage at %s\n\n", _
Version.byDLLMajorVersion, Version.byDLLMinorVersion, _
Version.byDay, Version.byMonth, Version.wYear, _
Version.byMajorVersion, Version.byMinorVersion, _
Version.zHomepage)
If not fileExists(strFileIn) then
printf(!"Error opening %s, file not exists", argv[1])
End -1
End If
fileIn = FreeFile
open strFileIn for binary as #fileIn
fileOut = FreeFile
open strFileOut for binary as #fileOut
' be_Config
beErr = beInitStream(@beConfig, @dwSamples, @dwMP3Buffer, @hbeStream)
If beErr <> BE_ERR_SUCCESSFUL then
printf(!"Error opening encoding stream (%lu)", beErr)
End -1
End If
pMP3Buffer = new byte [dwMP3Buffer] ' mp3
pWAVBuffer = new short[dwSamples] ' wav
If pMP3Buffer = 0 Then
printf(!"not enough memory for mp3Buffer")
End -1
End If
If pWAVBuffer = 0 Then
printf(!"not enough memory for wavBuffer")
End -1
End if
'Cut
dwFileSize = lof(fileIn)
Seek #fileIn,45
dwRead = 1
While dwRead <> 0
Get #fileIn,,*pWAVBuffer,dwSamples,dwRead
If dwRead = 0 Then Continue While
beErr = beEncodeChunk(hbeStream, dwRead/sizeof(SHORT), pWAVBuffer, pMP3Buffer, @dwWrite)
If beErr <> BE_ERR_SUCCESSFUL Then
beCloseStream(hbeStream)
printf(!"beEncodeChunk() failed (%lu)", beErr)
End -1
End if
If put( #fileOut,,*pMP3Buffer,dwWrite) <> 0 Then
printf(!"Output file write error")
end -1
End if
dwDone += dwRead
printf(!"Encoding %s -> %0.2f%% \r",UCase(strFileOut), 100 * cast(SINGLE,dwDone)/cast(SINGLE,dwFileSize))
Wend
beErr = beDeinitStream(hbeStream, pMP3Buffer, @dwWrite)
If beErr <> BE_ERR_SUCCESSFUL Then
beCloseStream(hbeStream)
printf(!"beExitStream failed (%lu)", beErr)
End -1
End If
If dwWrite Then
If Put( #fileOut,,*pMP3Buffer,dwWrite) <> 0 Then
printf(!"Output file write error\n")
End -1
End If
End If
beCloseStream( hbeStream )
Delete[] pWAVBuffer
Delete[] pMP3Buffer
'beWriteInfoTag( hbeStream, strFileOut )
Close
printf(!"\nDone !\n")
End If
'Print Wav
End 0
' Subs Main Usage Help
Sub MainText ()
printf(!"FreeBasic MP3 Encoder Example for the LameEnc.DLL 2010 (c) by Thomas Breit \n")
End Sub
Sub UsageText (Info As String)
printf(!"Usage: %s <Optionen> <Filename.wav>\n",UCase(Info))
'printf(!"Example: %s Sound.wav\n",UCase(Info))
printf(!"Type %s --Help for more Info!\n",UCase(Info))
End Sub
Sub Help()
printf(!"Optionen\n\n"_
!"--h =Help\n"_
!"--version =Version Info \n\n"_
!"FileName =Wav File to Encode\n")
'!"-b= = Bitrate[32,40,48,56,64,80,96,112,128,160,192,224,256,320]\n")
End -1
End Sub
|
|
|
Nach oben |
|
|
Tom42
Anmeldungsdatum: 09.02.2005 Beiträge: 21 Wohnort: Wolfsburg
|
Verfasst am: 01.05.2011, 14:15 Titel: FreeBasic MP3 Encoder Example |
|
|
Hi Freebasic Coder,
Der link zum DL von FBME wurde umgestellt.
Der neue Link ist jetzt hier ftp://13dl31.kdggateway.de/Projecte/FBME/
Hatte ein Fehler gemacht und leider ein neues Thema aufgemacht
ist hier besser aufgehoben !
Viel Spass wer daran Intresse hat.
cu. Thomas
PS: Wenn einer dies Runterläd wäre ich üeber eine Info per SITE MSG erfreut |
|
Nach oben |
|
|
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|