caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.13k stars 260 forks source link

Set display visualizer on jpanel #214

Closed ahsanunnaseh closed 10 years ago

ahsanunnaseh commented 10 years ago

Hi guys,

Sorry i continue this topic "Closed #213". i ran class visualization successfully and i can see display of visualizer on my screen. Now, my problem.1). i want to set the display of visualizer on Jpanel, how can i do it? 2.) how i can get value of byte input visualizer?

Thanks a lot

caprica commented 10 years ago

When I execute the vlcj test case referred to in #213, with the change to the media player factory arguments also mentioned in that issue, I see the spectrum analyzer visualizer correctly appear inside in a JPanel inside a JFrame.

For part #2, I have no idea what you mean.

If you mean you want the raw audio samples, you need to use the audio format callbacks.

ahsanunnaseh commented 10 years ago

Thanks for your respon.

  1. Yes, you are right. spectrum analyzer visualizer correctly appear inside in JPanel and Jrame. but i mean, how we can display visualizer inside our JPanel that was created by ourself. not from vlc.
  2. Yes...i mean raw audio samples, can you give example to me, how to get it (raw audio samples)?
caprica commented 10 years ago

The visualiser in that test case IS appearing inside a JPanel created in a Java application, and not by vlc.

Maybe what you're really asking is: how do I implement my own audio visualisation in Java using vlcj?

If that is what you are asking, then you need to completely forget the vlcj visualisation test case that we've been discussing.

So I would suggest you look at the DirectAudioMediaPlayerComponent - it provides direct access to the native buffer containing the decoded audio samples. You can then run your algorithm on that and paint your own JComponent implementation.

I can not give you any example other than the source code already in vlcj.

ahsanunnaseh commented 10 years ago

Ok....thanks. I'm sorry for my question, i mean that like your perception. how do I implement my own audio visualisation in Java using vlcj? can you help me...please... i'm still newbi

thanks a lot

caprica commented 10 years ago

I helped you already - go look at the Javadoc for the DirectAudioMediaPlayerComponent and you will see a template method that provides you the native sample buffer. Or find the Javadoc for the audio format callbacks. Then have a look at the vlcj examples that use those components. That will get you the native samples.

Then execute your DSP algorithm against those samples to generate your visualisation, then paint it using Java2D (or JOGL or something if you are feeling ambitious).

ahsanunnaseh commented 10 years ago

Hi...Mr Mark Lee Thanks for your clue and advice, I have implemented DirectAudioMediaPlayerComponent and gotten sample buffer from audio. So, that value was i use to make visualizer. from that value i want to build pitchshift menu for my application. How can i do it? or How can i set output sample buffer on my sound??

caprica commented 10 years ago

You have to play your pitch-shifted samples through some sort of API, libvlc will not play them.

You can use any API you want, it can be a native API, or it can be a Java API.

For example you could use the JavaSound API. There's a vlcj example that uses JavaSound, have a look in the test sources.

ahsanunnaseh commented 10 years ago

Thanks for your respon,

I have been run test of JavaSound in test sources Succesfully, but i,m confuse to implement with my pitchshift class. i have java class with constructor like this :

public PitchShift(double pitchshift, int fftFrameSize, int osamp, double sampleRate)

Explanation: pitchshift : i use to set value of pitch shift, the factor by which to scale the pitch (0.5 - 2.0) ==> I get from JSlider Value fftFrameSize : the resolution of the FFT used with 2048 and 4096. osamp : the amount of overlap between successive frames. sampleRate : the sample rate of the source material (usually 44100 or 48000).

and i used this methode to make my visualizer, i took value of byte [] data (samples.getByteArray(0, bufferSize) )to draw my visualizer in JPanel.

now, i want to implement pitcshift class with constructor above. what is parameter in this methode below which can i modify to be inputed in my constructor or class? i have tried modify samples.getByteArray(0, bufferSize) but didnt succes yet.

public void play(DirectAudioPlayer mediaPlayer, Pointer samples, int sampleCount, long pts) { int bufferSize = sampleCount * BLOCK_SIZE; byte [] data = samples.getByteArray(0, bufferSize); dataLine.write(data, 0, bufferSize);

}

and after i process that value with my pitchshift class, how i can set to that methode?

caprica commented 10 years ago

This is really outside the scope of vlcj.

All I can say is that:

A) you have an input buffer with sample data from libvlc. B) You have an output buffer with sample data that you send to JavaSound.

How you get from A to B is really a task for you to work out.