Android usage sample
Closed this issue · 12 comments
Please not that this is not a bug, this is question on how to use it in android.
Is there any basic usage sample in Android on how to shape sound with an instrument ?
I tried this but it's failing with this error
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'org.toilelibre.libe.soundtransform.model.converted.sound.Channel org.toilelibre.libe.soundtransform.model.library.pack.note.Note.getAttack(float, int, float)' on a null object reference
final File input1 = new File ("/sdcard/input.wav");
final File output = new File ("/sdcard/output.wav");
start ().withAPack ("default", Thread.currentThread ().getContextClassLoader ().getResourceAsStream ("defaultpack.json")).withFile(input1).convertIntoSound ().findLoudestFrequencies ()
.shapeIntoSound ("default", "simple_piano", cdFormatInfo).exportToFile (output);
Hello.
Thank you for this issue.
It looks like there is a missing chapter about the lib on Android. I willl add it asap.
Anyway you can't use the classloader on Android. It must be a R.raw ressource.
Very important question indeed.
Thanks libetl, and thanks for the great work you're doing here.
So I tried this, still doesn't work, I also tried copying the file to the app raw resources and that didn't help either.
start ().withAPack ("default", getAssets().open("defaultpack.json")).withFile(input1).convertIntoSound ().findLoudestFrequencies ()
.shapeIntoSound ("default", "simple_piano", cdFormatInfo).exportToFile (output);
and this is not supported
getResources().openRawResourceFd
The last thing I tried is to copy the json content into a string and use it, that doesn't seem to help either.
Look at this.
I am currently at work, I will work on the doc this evening.
Thank you libetl.
I tried the following, it does nothing, it keeps on loading with no output, please not that I'm able to play the input with this start().withFile(input1).playIt();
final File input1 = new File ("/sdcard/input.wav");
final File output = new File ("/sdcard/output.wav");
start ().withAPack ("default", context, org.toilelibre.libe.soundtransform.R.raw.class, org.toilelibre.libe.soundtransform.R.raw.defaultpack)
.withFile(input1).convertIntoSound ().findLoudestFrequencies ()
.shapeIntoSound ("default", "simple_piano", new FormatInfo (2, (float) 44100.0)).exportToFile (output);`
And it doesn't throw any error, I see in the adb logs that it's working, I see the gc is running on it and it just goes forever.
Oh, I did not see your comment until now. I am sorry.
Tell me how big is your input ? You can see what is happening by setting your observers (which can do Log.d in Android for example)
inside the SingIn poc, you can see a status bar where I log some clues about what is happening.
I used the sample input in your library and I trimmed it to 2 seconds only with ffmpeg, it took ~5 mins to complete the output was just a tone, something like "beep", for less than a second.
Lol, that's good news anyway. Now you are able to pimp your conversion by selecting your prefered PeakFindSoundTransform and by preparing the sound before the conversion (WindowTransform, ReduceNoise, changeFormat and so on...)
BTW, you should not read a file like that :
final File input1 = new File ("/sdcard/input.wav");
final File output = new File ("/sdcard/output.wav");
It will not work most of the time with the most recent Android devices.
sure, that's just for testing 😄