Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write MP3 files.
#1
Is there anyway to write MP3 files using the LAME encoder and QM?

http://www.codeproject.com/KB/audio-vid ... oding.aspx

Thanks,
jimmy Vig
#2
[everything moved to another post]
#3
Cool. Now I just have to spend the next 3 months researching how to use lame to write MP3 files. At least now I know QM can handle it.

Gint...if you have any other nips in the right direction here, I'd love to see them.

Thanks for the lame_def!

jimmy Vig
#4
I corrected the declarations.

Example in C++ is in Example.cpp. Need to convert to QM.
#5
You're talking about the Example.cpp in the LAME download, right?

I doubt I'll be able to whip up converting this to QM. It's full of all sorts of things I don't understand in C++ which leaves me blank on how it is even supposed to look in QM.

Thanks,
jimmy Vig
#6
Function LameWavToMp3
Code:
Copy      Help
;/
function $wavFile $mp3File

;Converts wav file to mp3.
;Error if fails.

;EXAMPLE
;LameWavToMp3 "$windows$\Media\notify.wav" "$desktop$\notify.mp3"


ref lame "lame_def"

File        pFileIn
File        pFileOut
BE_CONFIG    beConfig

int        dwSamples
int        dwMP3Buffer
int    hbeStream
int        e

ARRAY(byte)        MP3Buffer
ARRAY(word)        WAVBuffer
byte*        pMP3Buffer
word*        pWAVBuffer


// Try to open the WAV file, be sure to open it as a binary file!    
pFileIn.Open( wavFile, "rb" );

// Open MP3 file
pFileOut.Open(mp3File,"wb+");

// 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_R3MIX;        ;; 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            = 1;                    ;; SET ORIGINAL FLAG
beConfig.format.LHV1.bWriteVBRHeader    = 1;                    ;; Write INFO tag

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

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

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

// Check result
if(e != BE_ERR_SUCCESSFUL) end "Error opening encoding stream (%lu)" 0 e

// Allocate MP3 buffer
MP3Buffer.create(dwMP3Buffer);
pMP3Buffer=&MP3Buffer[0]

// Allocate WAV buffer
WAVBuffer.create(dwSamples);
pWAVBuffer=&WAVBuffer[0]

int dwRead
int dwWrite
int dwDone
int dwFileSize

// 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
int pr ppr(-1)
rep
,dwRead=fread(+pWAVBuffer,sizeof(word),dwSamples,pFileIn)
,if(dwRead<=0) break
,
,// Encode samples
,e = beEncodeChunk(hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite);

,// Check result
,if(e != BE_ERR_SUCCESSFUL)
,,beCloseStream(hbeStream);
,,end "beEncodeChunk() failed (%lu)" 0 e
,
,// write dwWrite bytes that are returned in tehe pMP3Buffer to disk
,if(fwrite(pMP3Buffer,1,dwWrite,pFileOut) != dwWrite)
,,beCloseStream(hbeStream);
,,end "Output file write error"

,dwDone += dwRead*sizeof(word);
,
,pr=100.0*dwDone/dwFileSize
,if(pr>ppr)
,,_s.format("%i%%", pr)
,,OnScreenDisplay _s 10 0 0 0 0 0 1|4|8 "osd_lame_mp3"
,,ppr=pr

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

// Are there any bytes returned from the DeInit call?
// If so, write them to disk
if( dwWrite ) fwrite( pMP3Buffer, 1, dwWrite, pFileOut )

// close the MP3 Stream
beCloseStream( hbeStream );

// Close output file
pFileOut.Close

// Write the INFO Tag
beWriteInfoTag( hbeStream, _s.expandpath(mp3File) );

Macro lame_def
Code:
Copy      Help
def ATTRIBUTE_PACKED
type BE_CONFIG dwConfig __BE_CONFIG1'format
def BE_CONFIG_LAME 256
def BE_CONFIG_MP3 0
type BE_ERR = #
def BE_ERR_BUFFER_TOO_SMALL 0x00000005
def BE_ERR_INVALID_FORMAT 0x00000001
def BE_ERR_INVALID_FORMAT_PARAMETERS 0x00000002
def BE_ERR_INVALID_HANDLE 0x00000004
def BE_ERR_NO_MORE_HANDLES 0x00000003
def BE_ERR_SUCCESSFUL 0x00000000
def BE_MAX_HOMEPAGE 128
def BE_MP3_MODE_DUALCHANNEL 2
def BE_MP3_MODE_JSTEREO 1
def BE_MP3_MODE_MONO 3
def BE_MP3_MODE_STEREO 0
type BE_VERSION !byDLLMajorVersion !byDLLMinorVersion !byMajorVersion !byMinorVersion !byDay !byMonth @wYear !zHomepage[129] !byAlphaLevel !byBetaLevel !byMMXEnabled !btReserved[125]
def CURRENT_STRUCT_SIZE sizeof(BE_CONFIG)
def CURRENT_STRUCT_VERSION 1
type HBE_STREAM = #
type LAME_QUALITY_PRESET = #
def LQP_ABR 11
def LQP_AM 3000
def LQP_CBR 12
def LQP_CD 9000
def LQP_EXTREME 8
def LQP_FAST_EXTREME 9
def LQP_FAST_MEDIUM 14
def LQP_FAST_STANDARD 7
def LQP_FM 4000
def LQP_HIFI 8000
def LQP_HIGH_QUALITY 2
def LQP_INSANE 10
def LQP_LOW_QUALITY 1
def LQP_MEDIUM 13
def LQP_NOPRESET 0xFFFFFFFF
def LQP_NORMAL_QUALITY 0
def LQP_PHONE 1000
def LQP_R3MIX 4
def LQP_RADIO 6000
def LQP_STANDARD 6
def LQP_STUDIO 10000
def LQP_SW 2000
def LQP_TAPE 7000
def LQP_VERYHIGH_QUALITY 5
def LQP_VOICE 5000
def LQP_VOICE_QUALITY 3
def MPEG1 1
def MPEG2 0
type PBE_CONFIG = BE_CONFIG*
type PBE_VERSION = BE_VERSION*
type PHBE_STREAM = #*
type VBRMETHOD = #
def VBR_METHOD_ABR 4
def VBR_METHOD_DEFAULT 0
def VBR_METHOD_MTRH 3
def VBR_METHOD_NEW 2
def VBR_METHOD_NONE 0xFFFFFFFF
def VBR_METHOD_OLD 1
def _BLADEDLL
type __BE_CONFIG1 ____BE_CONFIG11'mp3 []____BE_CONFIG12'LHV1 []____BE_CONFIG13'aac
def ___BLADEDLL_H_INCLUDED___
type ____BE_CONFIG11 dwSampleRate !byMode [+1]@wBitrate bPrivate bCRC bCopyright bOriginal
type ____BE_CONFIG12 dwStructVersion dwStructSize dwSampleRate dwReSampleRate nMode dwBitrate dwMaxBitrate nPreset dwMpegVersion dwPsyModel dwEmphasis bPrivate bCRC bCopyright bOriginal bWriteVBRHeader bEnableVBR nVBRQuality dwVbrAbr_bps nVbrMethod bNoRes bStrictIso @nQuality !btReserved[237]
type ____BE_CONFIG13 dwSampleRate !byMode [+1]@wBitrate !byEncodingMethod
dll lame_enc #beCloseStream hbeStream
dll lame_enc #beDeinitStream hbeStream !*pOutput *pdwOutput
dll lame_enc #beEncodeChunk hbeStream nSamples @*pSamples !*pOutput *pdwOutput
dll lame_enc #beEncodeChunkFloatS16NI hbeStream nSamples FLOAT*buffer_l FLOAT*buffer_r !*pOutput *pdwOutput
dll lame_enc #beFlushNoGap hbeStream !*pOutput *pdwOutput
dll lame_enc #beInitStream BE_CONFIG*pbeConfig *dwSamples *dwBufferSize *phbeStream
dll lame_enc beVersion BE_VERSION*pbeVersion
dll lame_enc #beWriteInfoTag hbeStream $lpszFileName
dll lame_enc #beWriteVBRHeader $lpszFileName
#7
Pretty cool.

Now I just need to get it to write mp3 files using audio from the line input on the computer.

Thanks for all your help.
jimmy Vig


Forum Jump:


Users browsing this thread: 1 Guest(s)