Invoking Java as a visualization - Dancing Vocaloids
#1
As I sit here listening to a Vocaloid (Hatsune Miku) singing through XBMC...

I wonder, would it be easy to invoke a Java Application as a visualization plugin?

I've got a Vocaloid avatar dancing on my phone as a background and it would be so nice if it was a visualization for XBMC.


I am about to start "playing" with MikuMikuStudio, the output of this could be a plugin for XBMC if I knew how to make a visualization. It uses OpenGL if that helps or is a problem?

It'd be especially nice if you played a specific song, you have the motion data for that song, the Vocaloid danced the correct dance for the song, and the correct avatar(s) dancing and singing etc.

Even down to beat detection and somehow making the system determine the best motion data for the tune. I don't know where it could lead. Just dreams for now.


Reading the descriptions so far, it sounds similar to a screensaver? Or is that a type of visualization?
Reply
#2
that's a visualisation yes. the difference between a visualiser and a screensaver is the fact that the visualiser is fed audio data.

currently we only have a C api for visualisations. you'd have to hook into this and proxy to your java app. probably doable but just ditching java would make your life much easier...
Reply
#3
So where do I start? (Sorry for long delay in replying)

I'm trying to find some documentation, but can't find any obvious documentation on how to write a visualisation.

I can't detach the Java, it's the library providing much of the the rendering and physics engine, I'm just going to be providing the logic between the two.

Do visualisations have access to metadata from the currently playing song? It would be very useful to it to know what song is playing.
Reply
#4
Well. I've looked at the source code, created a new visualization plugin based on the WaveForm one.

Having trouble with a few things now, namely getting XBMC to play with JNI, well the libjni.so. I'm not great with the build process inside Linux. I don't know how to get xbmc to pull in the JNI shared library so I just keep getting "undefined symbol" errors.

I'm fairly confident that it'll work when I can get C++ talking to the Java process. The OpenGL library (MikuMikuStudio & the jMonkeyEngine it's founded on) is fairly easy to play with. I may need to write a custom OpenGL context handler, but apart from that, it should be ok. The only possible problem I see... It'll be OpenGL only.
Reply
#5
why do you need jni in xbmc? you should not need to link jni in xbmc. you need to link your visualization to jni. xbmc is none the wiser that you're mocking about with jni in your .so... that (should be) is all hidden behind the interfaces.

show me your buildsys, i'll fix it up.
Reply
#6
I think the main issue is I'm working from the source code. The second problem, the last time I did C++ development, I was using an IDE which hid any makefiles in GUIs.

I'm just removing all but the VIS_DIRS modification from the main xbmc Makefile, so I can build it in the source tree. Then modifying the Makefile in the visualisation I've created to pull in the jni include directories there instead.

So, the last problem I've got is making the visualisation link to the jni.so

My makefile I've got so far, after some playing around...

Code:
ARCH=x86_64-linux
CXXFLAGS=-fPIC
OBJS=Main.o

SLIB = ~/development/xbmc/xbmc-12.0~git20130103.0959-rc3/addons/visualization.testVis/test.vis
LDFLAGS += -ljvm -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm -Wl,-R,/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm
CXXFLAGS += -I/usr/lib/jvm/java-7-openjdk-amd64/include

$(SLIB): $(OBJS)
    $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $(SLIB) $(OBJS)
    

include ~/development/xbmc/xbmc-12.0~git20130103.0959-rc3/Makefile.include

I've checked I'm pulling in the correct so, libjvm.so in that directory does contain "JNI_CreateJavaVM" and when the Visualisation starts up, I'm getting ".../xbmc/xbmc.bin: symbol lookup error: .../xbmc/addons/visualization.testVis/test.vis: undefined symbol: JNI_CreateJavaVM".

The "-Wl,-R,/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm" I added later, I've changed "LD_LIBRARY_PATH" before running xbmc, in an attempt to get it to pull in the library. So now I'm stuck.

Like I said, I'm not too great with Makefiles and how Linux works with dynamic dependencies. I don't know if I have to load the jvm library, or the linker is supposed to do that for me. If these are dynamically linked libraries, like dll's in Windows

So any help will be greatly appreciated.
Reply
#7
ldd test.vis is it actually linked to jvm?
Reply
#8
No it's not listed in the output from ldd
Reply
#9
k. then your LDFLAGS are not taking effect. first thing i see is that you should reorder -L and -l. secondly, you don't need to set a runtime path for shared libs.

i strongly recommend that you look into https://github.com/cptspiff/visualization.spectrum

you have to perform an 'make install' of xbmc to put the bindings on your system. you can then compile completely decoupled from xbmc. and as it's cmake based, it's much easier to work with for somebody inexperienced.

in your app's cmakelist, do

find_package(java REQUIRED) (if needed)
find_package(JNI REQUIRED)

then add Java_LIBRARIES and JNI_LIBRARIES to the list of deplibs (DEPLIBS in my CMakeLists.txt)

as a bonus, this being cmake, you can generate a project for whatever IDE you prefer.
Reply
#10
With the forums down I've been playing and been unable to see your reply.

I managed to make it work by modifying the existing make file.

I changed LDFLAGS to

Code:
LDFLAGS += -Wl,--no-as-needed -Wl,-R,/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm

and ldd returned, amongst others, the libjvm.so in the list.

(I've changed it to the server version, as I was having segfaults with the other, this has solved it.)

I will change it to the cmake version if that is recommended. Been playing around with the code, seeing how well JNI interfaces (had problems with that for a while), how to get metadata, now I have something working.

Don't be surprised if I start asking more questions though,


There's cmake for starters.

I think I'm going to have to wrap the "VIS_PROPS" device (that's an opengl context?) in a custom renderer for the Java OpenGL code (^_^) ... which is nice.


Thank you for you help so far.
Reply

Logout Mark Read Team Forum Stats Members Help
Invoking Java as a visualization - Dancing Vocaloids0