Processing through sample buffer with vlcj

This forum is about all development around libVLC.
blackworx
New Cone
New Cone
Posts: 3
Joined: 30 Jun 2014 13:15

Processing through sample buffer with vlcj

Postby blackworx » 30 Jun 2014 13:28

Hi,

i am working on a modern jukebox like application.
When it came to playing audio i was excited that there is a java wrapper for libvlc, since i am using GWT as base for the application.
However, now the application has some state, where beatmatching is a relevant topic.

After reading very much literature and working through lots of examples of BPM Detection, i finaly build some BPM Detection api, which is the base for further work.
I have tested it with the java wave file reader, and it works pretty well.
Well, now i have got the problem, that my BPM Detection needs to be filled with samples for processing, not only supporting wave.

So now my problem, how do i get all samples of a song with vlcj?
Is there any bufferarray? The samples should be idealy in floats, though other type is ok.

Could someone send me some example, because i have no idea where to find some documation about this.
Also my c++ knowledge is not very good, though i understand it somehow :D.

The best solution would be an Array of Floats with all samples in there, the song contains.
Also some kind of shift buffer would be great, but how would i command it to shift to the next i.e. 1024 samples?

I hope someone can help me with this. I am realy frustrated about this, after reading lots of documentation of libvlc and not finding anything at all.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Processing through sample buffer with vlcj

Postby sherington » 30 Jun 2014 14:17

You can use vlcj for things like this - you need to look at the so-called "direct" media player components, there's an implementation that provides access to the audio samples via the native callback.

You need to be aware that you can't process those samples and then have VLC play them - you have to use some other API to play them. I've had this working with JavaSound as one of these examples shows:

https://github.com/caprica/vlcj/tree/ma ... irectaudio

blackworx
New Cone
New Cone
Posts: 3
Joined: 30 Jun 2014 13:15

Re: Processing through sample buffer with vlcj

Postby blackworx » 30 Jun 2014 14:44

First of all, thank you for your fast reply.

To the answer:
This is i guess exactly what i have been looking for.

Actually i am using vlcj for playing audio in my app.
I already found this directAudioComponent in the javaDoc and thought, it would be perfect for me,
but didn't see this example...

So anyways, i have to try it out tonight.
As i understood, the play() method is called if there are new Samples?
For example it should work if i try something like this?

Code: Select all

... public static void main(String[] args) throws Exception { JBPMDetect bpm = new JBPMDetect(samplerate, channels); ... JavaSoundDirectAudioPlayerComponent component = new JavaSoundDirectAudioPlayerComponent (bpm, format, rate, channels); ... } ... private class JavaSoundDirectAudioPlayerComponent extends DirectAudioPlayerComponent { private final JBPMDetect bpm; ... public JavaSoundDirectAudioPlayerComponent (JBPMDetect bpm, ...) { ... this.bpm = bpm; ... } @Override public void play (...Pointer samples...) { this.bpm.inputSamples(samples.getFloatArray(...)); } @Override public void finished (...) { System.out.println("" + this.bpm.getBPM()); // Returns Float value } ...
I will post some Reply tonight, after trying out :)

Thank you!

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Processing through sample buffer with vlcj

Postby sherington » 30 Jun 2014 15:30

Yes, but I would just reiterate if you actually want to hear something then in your play() method, after you have processed the samples with your algorithm, you actually need to send those processed samples to an API (like JavaSound).

blackworx
New Cone
New Cone
Posts: 3
Joined: 30 Jun 2014 13:15

Re: Processing through sample buffer with vlcj

Postby blackworx » 30 Jun 2014 16:24

The playback is done by an other vlcj class (i think it was MediaPlayer or something like this...).
Will the play(...) method be called in timesync?
If so, how could i manipulate the class, to get the samples without timesync?
Because i need to calculate the bpm before the actual playback so a can beatmatch the next song (maybe 10 seconds time for this, to process at least half of the song, for good bpm detection).

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Processing through sample buffer with vlcj

Postby sherington » 30 Jun 2014 17:32

It's basically a Java wrapper around "amem", so it works how amem works... which I don't really know to be honest.

There is no other way, at least not with vlcj, to do what you want.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 7 guests