Author Topic: Host SDK: Thread Safety  (Read 9137 times)

raffitea

  • Newbie
  • *
  • Posts: 1
    • View Profile
Host SDK: Thread Safety
« on: January 22, 2012, 14:56:14 »
Dear developers of Vamp and QM,

I am a developer of Mixxx (mixxx.org) the leading Open Source DJ software for Mac, Linux and Windows.
We have currently released Mixxx 1.10. To support beat tracking and better BPM detection in 1.11  Vamp and the QM
plugin set have already been successfully integrated in our development branch. The results are excellent and
I would like to take the chance to say thank you.

I think Vamp and QM may be improved further. We have faced the following two problems during development:

Vamp SDK and thread-safety

Thread safety is an important requirement for Mixxx. We have three threads accessing the PluginLoader class.
A brief look at the PluginLoader source code showed that PluginLoader::getInstance() is not thread-safe. Moreover, 
PluginLoader::loadPlugin returns a " new Vamp::PluginHostAdapter "( PluginLoader.cpp:407 ). At this point, I think that we are a bit unsafe. Indeed, I do not know what can happen, since the threads appear to share the same PluginLoader instance and a thread may call it, while the second has not yet obtained it.

So our big question is: Could you guys please release a thread-safe version of the Vamp Host -SDK?

QM beat track and 4/4 signatures

I know this post refers to host development but I would like to give feed back about beat tracking. All QM beat trackers are flexible in a sense that they are not limited to music having a 4/4 signature. However, most dance music today is written in a 4/4 signature. I personally have analysed the raw beat positions of the QM beat tracker with hundreds of songs. It was found out that the resulting beat grid was not always correct which negatively affects the BPM. QM frequently gets confused when the rhythm pattern changes within a track. Luckily, we have "invented" a method to to correct the raw beat positions. It would be great to have a native QM beat tracker for 4/4 signatures. If you are interested I can describe "invented" method and point to the implementation.

Again thank you very much. The Mixxx team is happy to have better BPM and beat detection in future!

 









cannam

  • Administrator
  • Sr. Member
  • *****
  • Posts: 273
    • View Profile
Re: Host SDK: Thread Safety
« Reply #1 on: February 08, 2012, 13:15:12 »
Hello there -- thanks for the comment.

Thread safety is an important requirement for Mixxx. We have three threads accessing the PluginLoader class.
A brief look at the PluginLoader source code showed that PluginLoader::getInstance() is not thread-safe. Moreover, 
PluginLoader::loadPlugin returns a " new Vamp::PluginHostAdapter "( PluginLoader.cpp:407 ). At this point, I think that we are a bit unsafe.

You're quite right that PluginLoader is not at all thread-safe and that it would be nice if it was.

At this stage, though, I think it's unlikely that this will change in a future release. That's because (a) it would introduce a further platform dependency for thread synchronisation and (b) it would change the semantics of the library without changing the API which is itself a hazardous thing to do.

So I'm afraid you will have to synchronise your plugin load code (i.e. the code that calls PluginLoader) instead, and accept the fact that the library doesn't do it for you.

One thing I certainly should do, though, is document this!

Just for completeness -- it should be OK to load plugins in multiple threads (so long as the PluginLoader calls are synchronised and the plugins themselves are well-written!) but you should only use a single plugin instance from within a single thread (don't access the same plugin from multiple threads) and you should always delete a plugin from the same thread you loaded it from. There should be no problem loading the same plugin multiple times in different threads if necessary, PluginLoader does not share instances.

It's also perhaps worth adding that you don't have to use PluginLoader. In fact, it didn't exist in the very earliest version of the SDK: that just said you should load the shared library and look up the descriptor function, as is usual with (for example) LADSPA plugins. That method still works too.

QM beat track and 4/4 signatures

I know this post refers to host development but I would like to give feed back about beat tracking. All QM beat trackers are flexible in a sense that they are not limited to music having a 4/4 signature. However, most dance music today is written in a 4/4 signature. I personally have analysed the raw beat positions of the QM beat tracker with hundreds of songs. It was found out that the resulting beat grid was not always correct which negatively affects the BPM. QM frequently gets confused when the rhythm pattern changes within a track. Luckily, we have "invented" a method to to correct the raw beat positions. It would be great to have a native QM beat tracker for 4/4 signatures. If you are interested I can describe "invented" method and point to the implementation.

On a personal level I would certainly be interested, and I can point the beat tracking researchers behind the QM plugins at this forum too.


Chris