Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Starting a visualisation component (Read 1727 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Starting a visualisation component

I would like to extract spectral information of the playing track, and to send it out of foobar.
It seems that it is not necessary to run a FFT, as this information is already present in visualisation_stream.
Another user wanted to do a very similar thing in 2011 (https://hydrogenaud.io/index.php?topic=90134.0), and this is the code that was proposed to him (and which I tried) :
Code: [Select]
service_ptr_t<visualisation_stream_v3> stream;
{
  static_api_ptr_t<visualisation_manager> m;
  m->create_stream(stream, visualisation_manager::KStreamFlagNewFFT);
}

I guess the SDK has changed since, because I wasn't able to make this code run (static_api_ptr_t<visualisation_manager> m; gives an unhandled exception in SDK/utility.cpp) and the SDK/vis.h header gives another way of creating a stream (but the get() method is not present in the code ?):
Code: [Select]
//! Entrypoint service for visualisation processing; use this to create visualisation_stream objects that can be used to retrieve properties of currently played audio. \n
//! Implemented by core; do not reimplement.\n
//! Use visualisation_manager::get() to obtain an instance, e.g. visualisation_manager::get()->create_stream(mystream,0);
class NOVTABLE visualisation_manager : public service_base {
FB2K_MAKE_SERVICE_COREAPI(visualisation_manager);
public:
//! Creates a visualisation_stream object. See visualisation_stream for more info.
//! @param p_out Receives newly created visualisation_stream instance.
//! @param p_flags Combination of one or more KStreamFlag* values. Currently only KStreamFlagNewFFT is defined.
//! It's recommended that you set p_flags to KStreamFlagNewFFT to get the new FFT behavior (better quality and result normalization), the old behavior for null flags is preserved for compatibility with old components that rely on it.
virtual void create_stream(service_ptr_t<visualisation_stream> & p_out,unsigned p_flags) = 0;

enum {
//! New FFT behavior for spectrum-generating methods, available in 0.9.5.2 and newer: output normalized to 0..1, Gauss window used instead of rectangluar (better quality / less aliasing).
//! It's recommended to always set this flag. The old behavior is preserved for backwards compatibility.
KStreamFlagNewFFT = 1 << 0,
};


//! Wrapper around non-template create_stream(); retrieves one of newer visualisation_stream_* interfaces rather than base visualisation_stream interface. Throws exception_service_extension_not_found() when running too old foobar2000 version for the requested interface.
template<typename t_streamptr>
void create_stream(t_streamptr & out, unsigned flags) {
visualisation_stream::ptr temp; create_stream(temp, flags);
if (!temp->service_query_t(out)) throw exception_service_extension_not_found();
}
};

So I would like to know what is the correct way of getting a visualisation_stream, or if I'm doing something wrong

Re: Starting a visualisation component

Reply #1
I know less than nothing about it but I know of a recent project that is open source on github...

https://github.com/djdron/projectm/blob/foobar2000/src/projectM-foobar2000/projectM_foobar2000.cpp

You could also try searching github for more instances of code using visualisation_manager. Of course many results will be copies of the SDK so you might have to trawl a few pages of results...

Re: Starting a visualisation component

Reply #2
I create one like

Code: [Select]
  visualisation_stream::ptr vis_stream = NULL;
  visualisation_manager::get()->create_stream(vis_stream, 0);

This was compiling for me the other day with Visual Studio 2019 and all the Windows SDK up to date

Re: Starting a visualisation component

Reply #3
Thank you, I managed to find a github repository (https://github.com/Jonascone/foo_lifx) where there is a simple extraction of the audio spectrum.
The code wasn't working because I didn't insert it in an object registered as a service (I'm totally new to foobar SDK).
Regards