Liblame encode won't initialize

aloof

Member
Licensed User
Longtime User
For some reason i cant work out why i keep getting the error

java.lang.RuntimeException: Object should first be initialized (liblameEncoder).


this is my code here
Sub buttonEnc_Click


libenc.SetFiles(Dir2 & "/" & Filename2,File.DirRootExternal & "mp3test.mp3")

libenc.SetQuality(libenc.LAME_PRESET_STANDARD)

libenc.Initialize(libenc)
libenc.Encode

End Sub

Ive tried initializing it earlier, same deal

:signOops::sign0013::sign0163::sign0104:

Thanks
 

warwound

Expert
Licensed User
Longtime User
The SetFiles method returns a Boolean value to indicate whether it has executed successfully.
If it fails to execute then the encoder will not be initialized - i think that could be where the problem lies.

B4X:
Sub buttonEnc_Click

libenc.Initialize("libenc") ' needs a String EventName

if libenc.SetFiles(Dir2 & "/" & Filename2,File.DirRootExternal & "mp3test.mp3") then
   libenc.SetQuality(libenc.LAME_PRESET_STANDARD)
   libenc.Encode
else
   '   here handle the error, check the unfiltered log for FileNotFoundException and IOException
end if

End Sub

Are you sure that the path separator "/" is need for the input file?
Try:

B4X:
Log(Dir2 & "/" & Filename2)
Log(File.DirRootExternal & "mp3test.mp3")

Do the paths look valid?

Martin.
 
Upvote 0

aloof

Member
Licensed User
Longtime User
Thanks alot Warwound

ive never used the log feature before thanks for showing me how, once i did that i saw that the mp3 file was saving as sdcardmp3test.mp3

so i added a "/" here

File.DirRootExternal & "/" &"mp3test.mp3"

Thanks now its working:sign0098:
 
Upvote 0

trebun

Member
Licensed User
Longtime User
Hi there,

I'm getting the following error:

B4X:
LameEncoder (libLameEncoder) Not initialized

Grrr. The sample project works fine...

I do:

Globals:
B4X:
Dim LameEncoder As liblameEncoder

Activity_Create:
B4X:
LameEncoder.Initialize("LameEncoder")

makeMP3_Click:
B4X:
Log(File.DirRootExternal & "/" & "test.wav")
Log(File.DirRootExternal & "/" & "test.mp3")

If LameEncoder.SetFiles(File.DirRootExternal & "/" & "test.wav", File.DirRootExternal & "/" & "test.mp3") Then

   ProgressDialogShow2("Encoding...", False)
   LameEncoder.Encode
Else
   Msgbox("Grrrr","Lame")
End If

SetFiles @ Log:
B4X:
/storage/sdcard0/test.wav
/storage/sdcard0/test.mp3

Of course the "test.wav" exists.

Any Ideas?

Regards,
trebun
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
I think you'll have to post the entire Activity code so i can take a look.

When do you get that error - when you call SetFiles or when you call Encode?
If the SetFiles method fails then either a FileNotFoundException or an IOException should be logged - uncheck the log panel Filter checkbox and look for an exception.

If there's no logged exceptions to help debug the problem then please post the entire Activity code.

Martin.
 
Upvote 0

trebun

Member
Licensed User
Longtime User
I think you'll have to post the entire Activity code so i can take a look.

When do you get that error - when you call SetFiles or when you call Encode?
If the SetFiles method fails then either a FileNotFoundException or an IOException should be logged - uncheck the log panel Filter checkbox and look for an exception.

If there's no logged exceptions to help debug the problem then please post the entire Activity code.

Martin.

Hey Martin,

thank you for your quick answer - I follow an another idea, but I will check your comment.

It was an error on "SetFiles" - I will check the log and give some feedback (maybe for another user they have the same problem at the beginning).

Regards,
trebun
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi

I've been pointed to this library by Erel for use in an audio capture app I need to develop for work. We haven't bought B4A yet as I'm still doing some research on whether B4A will work for us. I've already read through the Audio Capture post and that bit is looking good. However, we will require the wav file to be converted to mp3, which is what this library does, hence my interest in this. However, the initialising error which has been reported, is that a hardware issue or a library issue? If this can be clarified then I can certainly put my recommendation forward on going ahead with the purchase of B4A.

Thank you
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi Martin,

I'm afraid that I am also getting the error;

B4X:
An error occurred while calling LameEncoder.SetFiles

I definitely have the source wav which I generated using the AudioRecorder library. Any ideas?

Thanks

PS: I'm testing your example script.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
The only thing that i can think of is that you're trying to use external memory to save the encoded MP3 on a device running KitKat?

Martin.
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi Martin,

I am running Kit Kat however, the file is actually on my internal sdcard partition. If I run the file exist check everything is fine. Just out of curiosity, is the setup just to include the liblame library only or is there another stage I've missed?

Thanks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
To run the example all i did was copy the liblame.jar and liblame.xml files to my b4a additional libraries folder - no other additional files are required.

I created a 30 second 44100Hz stereo .wav file using Audacity, a saw tooth waveform with some noise.
Named it file_to_encode.wav and added it to the example project's Files folder.

Now i tested the example project on my Moto G (KitKit).
No 'object not initialized' error, file_to_encode.wav was successfully encoded to .mp3 and then decoded back to a new .wav file.
The Moto G has no external memory card slot, it has only it's 'built in' 16GB external memory.

Next i tested the example project on my old ZTE Blade (Gingerbread).
The results were the same but the Blade took an age to encode and decode with it's 600Mhz single core CPU!
The Blade has an external 4GB memory card installed.

You can download the .wav file i used for testing here: http://b4a.martinpearman.co.uk/temp/file_to_encode.wav, can you test with my .wav file?
Can you also post again with details of the device(s) you're testing with, what device(s) and what version(s) of android?

Martin.
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi Martin

Found the problem - it's the wav source file. The AudioRecorder lib I used doesn't produce a valid wav file, even though it claims to. Your test file was produce in Audacity is a genuine wav format which is why it worked. The issue I now have is which of the B4A libs produce a proper wav file. Any ideas?

Anyway, thank you for your help with this. At least I know your lib is working.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
The library has it's weaknesses, you can read about them here.
  • Stereo 44100Hz 16 bit .wav files work best for encoding.
  • .mp3 files previously encoded using this library work best for decoding.
  • Results with any other types of .wav and .mp3 files are unpredictable.

I see another mp3 encoder/decoder library here: http://www.b4x.com/android/forum/th...nd-decoder-play-an-mp3-with-audiotrack.34315/, maybe that'll work better with the .wav files you have?

Martin.
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi Martin,

Just wanted to let you know that I got everything working. As I suspected it was the wav file. I found another example of wav capture which added the required header info and then it worked perfectly. I would like to say "Thanks" for your help and library.
 
Upvote 0
Top