IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
LAME_ENC.DLL programming, lame_enc crashes but vorbis works?
milosoftware
post Dec 15 2003, 08:23
Post #1





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



Been attempting to build LAME_ENC.DLL support into CD Wave. After re-factoring the whole output logistics to support other-than-WAV files, I couldn't get it to work.

I peeked around, noticing the OGG Vorbis codec offers a very similar interface, and that worked on the first attempt. If you want proof, download the (very) beta http://www.cdwave.com/cdwav192.exe (vorbis.dll is included in the package).

The lame_enc.dll will crash with an access violation error when calling the encode chunk function. I translated most of the stuff from C(++) to Delphi.
On one occasion, it really did encode the file, but crashed close to the end. The MP3 was playable though, and sounded just fine. I never managed to reproduce this.

Forgot to bring a few code snippets, but are there any LAME programmers who know what to look for? Is there some undocumented 'feature' in the DLL interface that makes it crash....

I tried with the rarewares distribution, using v 1.90.3, 1.92.something and the 1.93 alpha version, but they all behaved identically.


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post
Gabriel
post Dec 15 2003, 08:41
Post #2


LAME developer


Group: Developer
Posts: 2950
Joined: 1-October 01
From: Nanterre, France
Member No.: 138



There was a fix in 3.94 regarding delphi. The problem was that the declaration of calling convention in the .pas file was wrong. Perhaps this is your case?
Go to the top of the page
+Quote Post
milosoftware
post Dec 15 2003, 09:07
Post #3





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



If the declaration (stdcall?) is wrong, yeah, but most of the functions appear to work just fine. I'll try with the latest 1.94 DLL...

What usually happens is that after calling 'encodeChunk', it returns 0 (success) and sets (or leaves) dwWrite (number of output bytes) to zero.
But in the mean time, some of my local variables have been destroyed, leading to the AV crash. Sometimes the crash takes place inside the DLL.

I also tried 'fixing' for buffer overruns by allocating 4x the memory that LAME wanted, and supplying a pointer in the middle of that memory, so that it could read/write way outside that buffer. Didn't help, the problem seems to be with the stack.


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post
Gabriel
post Dec 15 2003, 09:36
Post #4


LAME developer


Group: Developer
Posts: 2950
Joined: 1-October 01
From: Nanterre, France
Member No.: 138



The declaration should be cdecl, not stdcall.

It is perfectly normal for Lame to sometimes return 0 output bytes. It just means that it needs more data before returning any compressed data.

But your local variables beeing destroyed is not normal.
Go to the top of the page
+Quote Post
milosoftware
post Dec 15 2003, 11:44
Post #5





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



QUOTE (Gabriel @ Dec 15 2003, 12:36 AM)
The declaration should be cdecl, not stdcall.

It is perfectly normal for Lame to sometimes return 0 output bytes. It just means that it needs more data before returning any compressed data.

But your local variables beeing destroyed is not normal.

Hmm, cdecl (guess that makes it use the C calling model) would not cleanup the stack afterwards, which would explain the stack corruption i saw (not corruption, just not moving the SP back to where it was upon call). I'm surprised that it got as far as it did (I built an OO shell around it)...

Have to check (am at work now) if that's the case...

I'd expect the vorbis.dll to use something similar, have to check that one out...

The dwWrite being zero is no problem, but it's just one of the symptoms just before the thing goes down...

M.


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post
Sebastian Mares
post Dec 15 2003, 12:41
Post #6





Group: Members
Posts: 3629
Joined: 14-May 03
From: Bad Herrenalb
Member No.: 6613



Gabriel, do you know if it is possible to use the LAME DLL with Visual Basic? I searched the net but couldn't find anything. The only example for VB used another wrapper DLL written in C, but it supported only setting the bit rate.


--------------------
http://listening-tests.hydrogenaudio.org/sebastian/
Go to the top of the page
+Quote Post
Gabriel
post Dec 15 2003, 13:21
Post #7


LAME developer


Group: Developer
Posts: 2950
Joined: 1-October 01
From: Nanterre, France
Member No.: 138



Of course you can use the Lame dll from VB. VB is able to call C functions from dll. Using Lame with VB should not be different than using any other C dll.
Go to the top of the page
+Quote Post
milosoftware
post Dec 16 2003, 07:58
Post #8





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



QUOTE (Gabriel @ Dec 15 2003, 12:36 AM)
The declaration should be cdecl, not stdcall.

Well, that did the trick. (ESP register not restored correctly on function return...)

Got it working correctly now. Now for setting some good defaults...

I guess the mapping of the normal/extreme/insane presets to the BE_CONFIG struct are a well kept secret? I tried to figure things out by looking at the source (presets.c) but couldn't make much of that...

Think i'll set some low end for portable players (64kbps, or would that be a bad idea), medium for home/car use (128), good for home (VBR around 160) and "archive" something like 256kbps VBR.

Currently, it's only doing 128kbps (in "high" or "very high" quality mode)...

http://www.cdwave.com/cdwav192.exe

Mike


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post
Gabriel
post Dec 16 2003, 08:43
Post #9


LAME developer


Group: Developer
Posts: 2950
Joined: 1-October 01
From: Nanterre, France
Member No.: 138



QUOTE
I guess the mapping of the normal/extreme/insane presets to the BE_CONFIG struct are a well kept secret?


Not really. Have a look at LAME_QUALITY_PRESET in blademp3encdll.h, you will find the values you are searching for.

Btw, with 3.94 it should be easier as there will be no need anymore to set preset values.
Go to the top of the page
+Quote Post
milosoftware
post Dec 16 2003, 09:26
Post #10





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



Gabriel, did anyone ever tell you you're an angel?
biggrin.gif

This is gonna be a busy Xmas holiday...

Now if only there was a shorten (shn) DLL, I could make some etree.org users very happy. Ah well, I can always include an 'external program' compressor.. 'nuf to do for the holidays.


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post
dev0
post Dec 16 2003, 09:39
Post #11





Group: Developer
Posts: 1679
Joined: 23-December 01
From: Germany
Member No.: 731



etree users would also appretiate FLAC support (using libFLAC). Thanks for your work on this simple but great tool.

dev0
Go to the top of the page
+Quote Post
milosoftware
post Dec 16 2003, 10:51
Post #12





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



QUOTE (dev0 @ Dec 16 2003, 12:39 AM)
etree users would also appretiate FLAC support (using libFLAC).

libFLAC's on my disk since yesterday... No promises rolleyes.gif but I usually have quite some time on my side during the Xmas holidayz...


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post
milosoftware
post Dec 21 2003, 16:26
Post #13





Group: Members
Posts: 55
Joined: 9-December 03
Member No.: 10308



e-Tree users rejoice then - CD Wave 1.92 (beta) can now write FLAC files directly. (Using libFLAC.dll)

Now I guess what I need to do next is to write 5 pages of acknowledgements and stuff for all the libraries and source code I used to get this going...


--------------------
MiLo Software - http://www.milosoftware.com - http://www.cdwave.com
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 19th April 2014 - 10:30