How to implement spectrum analyzer/ oscilloscope in window!


#1

Hi,

I would like to be able to plot the spectogram and time envelope (oscilloscope) of a signal in a JuceAudioPlugIn GUI. Can you please give me some advice on how implement it such that it doesn’t cost a lot of CPU power!

Best whishes
Thomas S.


#2

the biggest cpu drain will be drawing the graphics, as there could be a lot of stuff moving about. Just try to do the minimum amount of repainting that you can get away with…


#3

Could always use the OpenGL renderer if you are versed enough with it…


#4

Hi thanks for your advices. I would like to delve into the OpenGl approach and have had a look at the Juce Demo which demonstrates some OpenGl program (rotating cube). In this context I’m not sure how to open an OpenGl canvas in the current JuceAudioPlugIn window. Can anyone show me how this is done?

Hoping to hear from you
Thomas


#5

you just need to derive a new class from OpenGLComponent, and then add it to the plugin window like any other component.

You can then make openGL calls from the renderOpenGL method (which is virtual and you need to override).

that should be all there is to it :smiley:

(note: i haven’t actually tried this from the audio plugin, but it was very straight forward in a standard juce application, and i don’t see why it should be any different…)


#6

[quote=“daniel78”]you just need to derive a new class from OpenGLComponent, and then add it to the plugin window like any other component.

You can then make openGL calls from the renderOpenGL method (which is virtual and you need to override).

that should be all there is to it :smiley:

(note: i haven’t actually tried this from the audio plugin, but it was very straight forward in a standard juce application, and i don’t see why it should be any different…)[/quote]

Hi,

Thanks for your advice. Will look into it right away.

Thomas

BTW. Like you homepage and music too - nice work!


#7

[quote=“stoltzo”]

BTW. Like you homepage and music too - nice work![/quote]

Thanks :slight_smile:


#8

[quote=“daniel78”]you just need to derive a new class from OpenGLComponent, and then add it to the plugin window like any other component.

You can then make openGL calls from the renderOpenGL method (which is virtual and you need to override).

that should be all there is to it :smiley:

(note: i haven’t actually tried this from the audio plugin, but it was very straight forward in a standard juce application, and i don’t see why it should be any different…)[/quote]

Hi,

I compiled the Juce Demo to fool around with the OpenGl component but found that when running the demo the OpenGl demo was not accesible from the drop down menu.

I looked inside the code and found that this demo was conditioned as:

[i]#if JUCE_OPENGL
case 8:
demos[demoId] = createOpenGLDemo();
break;

which might be the reason that I can’t see it when running the demo. Then I uncommented the “if” and “endif” line to see if I was lucky but the compiler (VS C++ 2005) complains that “createOpenGLDemo” was not found. I would like to know the meaning of the JUCE_OPENGL flag that is conditioned upon and would also like to see the “createOpenGLDemo” code
so that I can figure out how things work!

I’m sorry my questions are so basic, but I’m a complete beginner and I’m trying to be as persistant as possible :slight_smile:

Thanks for reading me questions!

Thomas

p.s. BTW are you having problems loging on this forum…sometimes I takes me ages before I get in!


#9

[quote=“stoltzo”]
I looked inside the code and found that this demo was conditioned as:

[i]#if JUCE_OPENGL
case 8:
demos[demoId] = createOpenGLDemo();
break;

which might be the reason that I can’t see it when running the demo. [/quote]

Yup. The JUCE_OPENGL flag should be defined if opengl was found on your system.

I don;t remember having to do anything special to get OpenGL support on Windows, and I imagine the Mac is probably similar - on Linux though, usually some user intervention is needed to set the paths to the glut.h file and similar.


#10

[quote=“valley”][quote=“stoltzo”]
I looked inside the code and found that this demo was conditioned as:

[i]#if JUCE_OPENGL
case 8:
demos[demoId] = createOpenGLDemo();
break;

which might be the reason that I can’t see it when running the demo. [/quote]

Yup. The JUCE_OPENGL flag should be defined if opengl was found on your system.
[/quote]

I don’t think this is automatic - don’t you have to uncomment #define JUCE_OPENGL 1 in juce_config.h ?

thinking about it, you might also need to add these .lib files as additional dependencies in your project settings: opengl32.lib glu32.lib glaux.lib

And you’ll need to include:

if you want to actually draw anything :wink:


#11

[quote=“daniel78”][quote=“valley”][quote=“stoltzo”]
I looked inside the code and found that this demo was conditioned as:

[i]#if JUCE_OPENGL
case 8:
demos[demoId] = createOpenGLDemo();
break;

which might be the reason that I can’t see it when running the demo. [/quote]

Yup. The JUCE_OPENGL flag should be defined if opengl was found on your system.
[/quote]

I don’t think this is automatic - don’t you have to uncomment #define JUCE_OPENGL 1 in juce_config.h ?

thinking about it, you might also need to add these .lib files as additional dependencies in your project settings: opengl32.lib glu32.lib glaux.lib

And you’ll need to include:

if you want to actually draw anything ;)[/quote]

The JuceDemo already includes the two h-files and I’m not sure to touch the JUCE_OPENGL as I believe that JUCE takes care of it itself… :frowning:


#12

well juce can’t take care of itself really; it will only do the opengl stuff if that macro is defined when it is being compiled. the only way it will be defined is if your environment defines it for the compiler (set up in your project or general environment settings) or if it is defined in the source code. defining/undefining that macro is the switch to enable/disable the opengl stuff. i think one of the releases a while back defaulted to having the quicktime stuff switched in, so you had to undefine the quicktime macro to compile it if you hadn’t the qtsdk installed.

don’t have any fears about defining/undefining that macro if you need to change the state. you’re not going to break anything, that’s the way that it’s switched in and out of the code. if you DO manage to break it by doing something silly, you can always restore it back to how it was.


#13

[quote=“haydxn”]well juce can’t take care of itself really; it will only do the opengl stuff if that macro is defined when it is being compiled. the only way it will be defined is if your environment defines it for the compiler (set up in your project or general environment settings) or if it is defined in the source code. defining/undefining that macro is the switch to enable/disable the opengl stuff. i think one of the releases a while back defaulted to having the quicktime stuff switched in, so you had to undefine the quicktime macro to compile it if you hadn’t the qtsdk installed.

don’t have any fears about defining/undefining that macro if you need to change the state. you’re not going to break anything, that’s the way that it’s switched in and out of the code. if you DO manage to break it by doing something silly, you can always restore it back to how it was.[/quote]

I’m sorry to ask all these questions but I’m still stock with setting up the OpenGl Component.

In the jucedemo_headers.h file in the JuceDemo I added “#define JUCE_OPENGL 1” at the top and got the following errors:

OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: virtual __thiscall juce::OpenGLComponent::~OpenGLComponent(void)” (??1OpenGLComponent@juce@@UAE@XZ) referenced in function __unwindfunclet$??0DemoOpenGLCanvas@@QAE@XZ$0
OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: __thiscall juce::OpenGLComponent::OpenGLComponent(class juce::OpenGLComponent *)” (??0OpenGLComponent@juce@@QAE@PAV01@@Z) referenced in function “public: __thiscall DemoOpenGLCanvas::DemoOpenGLCanvas(void)” (??0DemoOpenGLCanvas@@QAE@XZ)
OpenGLDemo.obj : error LNK2001: unresolved external symbol “public: virtual void __thiscall juce::OpenGLComponent::paint(class juce::Graphics &)” (?paint@OpenGLComponent@juce@@UAEXAAVGraphics@2@@Z)
OpenGLDemo.obj : error LNK2001: unresolved external symbol “private: virtual void __thiscall juce::OpenGLComponent::internalRepaint(int,int,int,int)” (?internalRepaint@OpenGLComponent@juce@@EAEXHHHH@Z)
OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: bool __thiscall juce::OpenGLComponent::makeCurrentContextActive(void)” (?makeCurrentContextActive@OpenGLComponent@juce@@QAE_NXZ) referenced in function “public: virtual void __thiscall DemoOpenGLCanvas::resized(void)” (?resized@DemoOpenGLCanvas@@UAEXXZ)

Does that say you anything?

Thanks
Thomas


#14

Yeah, have a look in juce_Config.h and feel free to turn things on and off - that’s what it’s for. All the macros have comments explaining what they’re for.

By default I always disable most of the things in there when I release the build, because that way it’ll compile on everyone’s machine, and people can turn things on if they need them.


#15

you don’t need to add it to this file. have a look in juce_config.h - you’ll find the line #define JUCE_OPENGL 1 but its commented out - you should just need to uncomment it.


#16

[quote=“daniel78”][quote=“stoltzo”]
In the jucedemo_headers.h file in the JuceDemo I added “#define JUCE_OPENGL 1” at the top and got the following errors:
[/quote]

you don’t need to add it to this file. have a look in juce_config.h - you’ll find the line #define JUCE_OPENGL 1 but its commented out - you should just need to uncomment it.[/quote]

I tried to follow your advice and that seemed to help…a little.

I could then compile the JuceDemo project but when I chose OpenGl Demo in the dropdown menu the program suddenly stops and prompts:

First-chance exception at 0x005ce52c in jucedemo.exe: 0xC0000005: Access violation reading location 0x00000010.
jucedemo.exe has triggered a breakpoint
The thread ‘Win32 Thread’ (0x6210) has exited with code 0 (0x0).
The program ‘[32000] jucedemo.exe: Native’ has exited with code 0 (0x0).

Just wanted to let you know!

Thomas


#17

run it in debug mode, and see what the breakpoint is; it’s stopping somewhere and if you’re debugging it you can see the line that caused it to die


#18

Hi and thanks for your patience!

It breaks inside the JuceApplication.cpp file at:

//==============================================================================
void JUCEApplication::unhandledException (const std::exception* e,
const String& sourceFile,
const int lineNumber)
{
jassertfalse <- break here
}

The ‘call stack’ window displays:
> jucedemo.exe!juce::JUCEApplication::unhandledException(const std::exception * e=0x00000000, const juce::String & sourceFile={…}, const int lineNumber=120) Line 122 C++
jucedemo.exe!juce::JUCEApplication::sendUnhandledException(const std::exception * const e=0x00000000, const char * const sourceFile=0x007953e8, const int lineNumber=120) Line 130 + 0x3a bytes C++
jucedemo.exe!juce::MessageManager::deliverMessage(void * message=0x0318a780) Line 120 + 0x37 bytes C++
jucedemo.exe!juce::juce_dispatchNextMessageOnSystemQueue(bool returnIfNoPendingMessages=false) Line 114 C++
jucedemo.exe!juce::MessageManager::dispatchNextMessage(bool returnImmediatelyIfNoMessages=false) Line 154 + 0x9 bytes C++
jucedemo.exe!juce::MessageManager::runDispatchLoop() Line 205 + 0xa bytes C++
jucedemo.exe!juce::JUCEApplication::enterMainApplicationLoop(juce::String * const commandLine=0x00e654e8, juce::JUCEApplication * const app=0x00e654a0) Line 193 C++
jucedemo.exe!juce::JUCEApplication::main(const char * const commandLine=0x00151f3e, juce::JUCEApplication * const newApp=0x00e654a0) Line 264 + 0x4a bytes C++
jucedemo.exe!WinMain(int __formal=4194304, int __formal=4194304, const char * commandLine=0x00151f3e, int __formal=4194304) Line 85 + 0x9d bytes C++
jucedemo.exe!__tmainCRTStartup() Line 315 + 0x35 bytes C
jucedemo.exe!WinMainCRTStartup() Line 187 C
kernel32.dll!7c816d4f()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
kernel32.dll!7c8399f3()
jucedemo.exe!SourceCodeWindow::SourceCodeWindow() Line 36 + 0x39 bytes C++
jucedemo.exe!juce::juce_loadPNGImageFromStream(juce::InputStream & in={…}) Line 126 + 0x2c bytes C++
ffdd4c7b()

Hope this can help a little!

Thx
Thomas


#19

[quote=“stoltzo”][quote=“haydxn”]well juce can’t take care of itself really; it will only do the opengl stuff if that macro is defined when it is being compiled. the only way it will be defined is if your environment defines it for the compiler (set up in your project or general environment settings) or if it is defined in the source code. defining/undefining that macro is the switch to enable/disable the opengl stuff. i think one of the releases a while back defaulted to having the quicktime stuff switched in, so you had to undefine the quicktime macro to compile it if you hadn’t the qtsdk installed.

don’t have any fears about defining/undefining that macro if you need to change the state. you’re not going to break anything, that’s the way that it’s switched in and out of the code. if you DO manage to break it by doing something silly, you can always restore it back to how it was.[/quote]

I’m sorry to ask all these questions but I’m still stock with setting up the OpenGl Component.

In the jucedemo_headers.h file in the JuceDemo I added “#define JUCE_OPENGL 1” at the top and got the following errors:

OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: virtual __thiscall juce::OpenGLComponent::~OpenGLComponent(void)” (??1OpenGLComponent@juce@@UAE@XZ) referenced in function __unwindfunclet$??0DemoOpenGLCanvas@@QAE@XZ$0
OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: __thiscall juce::OpenGLComponent::OpenGLComponent(class juce::OpenGLComponent *)” (??0OpenGLComponent@juce@@QAE@PAV01@@Z) referenced in function “public: __thiscall DemoOpenGLCanvas::DemoOpenGLCanvas(void)” (??0DemoOpenGLCanvas@@QAE@XZ)
OpenGLDemo.obj : error LNK2001: unresolved external symbol “public: virtual void __thiscall juce::OpenGLComponent::paint(class juce::Graphics &)” (?paint@OpenGLComponent@juce@@UAEXAAVGraphics@2@@Z)
OpenGLDemo.obj : error LNK2001: unresolved external symbol “private: virtual void __thiscall juce::OpenGLComponent::internalRepaint(int,int,int,int)” (?internalRepaint@OpenGLComponent@juce@@EAEXHHHH@Z)
OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: bool __thiscall juce::OpenGLComponent::makeCurrentContextActive(void)” (?makeCurrentContextActive@OpenGLComponent@juce@@QAE_NXZ) referenced in function “public: virtual void __thiscall DemoOpenGLCanvas::resized(void)” (?resized@DemoOpenGLCanvas@@UAEXXZ)

Does that say you anything?

Thanks
Thomas[/quote]

You have to actually recompile juce itself for the changes to do anything…


#20

[quote=“jules”][quote=“stoltzo”][quote=“haydxn”]well juce can’t take care of itself really; it will only do the opengl stuff if that macro is defined when it is being compiled. the only way it will be defined is if your environment defines it for the compiler (set up in your project or general environment settings) or if it is defined in the source code. defining/undefining that macro is the switch to enable/disable the opengl stuff. i think one of the releases a while back defaulted to having the quicktime stuff switched in, so you had to undefine the quicktime macro to compile it if you hadn’t the qtsdk installed.

don’t have any fears about defining/undefining that macro if you need to change the state. you’re not going to break anything, that’s the way that it’s switched in and out of the code. if you DO manage to break it by doing something silly, you can always restore it back to how it was.[/quote]

I’m sorry to ask all these questions but I’m still stock with setting up the OpenGl Component.

In the jucedemo_headers.h file in the JuceDemo I added “#define JUCE_OPENGL 1” at the top and got the following errors:

OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: virtual __thiscall juce::OpenGLComponent::~OpenGLComponent(void)” (??1OpenGLComponent@juce@@UAE@XZ) referenced in function __unwindfunclet$??0DemoOpenGLCanvas@@QAE@XZ$0
OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: __thiscall juce::OpenGLComponent::OpenGLComponent(class juce::OpenGLComponent *)” (??0OpenGLComponent@juce@@QAE@PAV01@@Z) referenced in function “public: __thiscall DemoOpenGLCanvas::DemoOpenGLCanvas(void)” (??0DemoOpenGLCanvas@@QAE@XZ)
OpenGLDemo.obj : error LNK2001: unresolved external symbol “public: virtual void __thiscall juce::OpenGLComponent::paint(class juce::Graphics &)” (?paint@OpenGLComponent@juce@@UAEXAAVGraphics@2@@Z)
OpenGLDemo.obj : error LNK2001: unresolved external symbol “private: virtual void __thiscall juce::OpenGLComponent::internalRepaint(int,int,int,int)” (?internalRepaint@OpenGLComponent@juce@@EAEXHHHH@Z)
OpenGLDemo.obj : error LNK2019: unresolved external symbol “public: bool __thiscall juce::OpenGLComponent::makeCurrentContextActive(void)” (?makeCurrentContextActive@OpenGLComponent@juce@@QAE_NXZ) referenced in function “public: virtual void __thiscall DemoOpenGLCanvas::resized(void)” (?resized@DemoOpenGLCanvas@@UAEXXZ)

Does that say you anything?

Thanks
Thomas[/quote]

You have to actually recompile juce itself for the changes to do anything…[/quote]

So I did - ended up with the following errors in the ‘call stack’ window:
[i]

jucedemo.exe!juce::JUCEApplication::unhandledException(const std::exception * e=0x00000000, const juce::String & sourceFile={…}, const int lineNumber=120) Line 122 C++
jucedemo.exe!juce::JUCEApplication::sendUnhandledException(const std::exception * const e=0x00000000, const char * const sourceFile=0x007953e8, const int lineNumber=120) Line 130 + 0x3a bytes C++
jucedemo.exe!juce::MessageManager::deliverMessage(void * message=0x00e63138) Line 120 + 0x37 bytes C++
jucedemo.exe!juce::juce_dispatchNextMessageOnSystemQueue(bool returnIfNoPendingMessages=false) Line 114 C++
jucedemo.exe!juce::MessageManager::dispatchNextMessage(bool returnImmediatelyIfNoMessages=false) Line 154 + 0x9 bytes C++
jucedemo.exe!juce::MessageManager::runDispatchLoop() Line 205 + 0xa bytes C++
jucedemo.exe!juce::JUCEApplication::enterMainApplicationLoop(juce::String * const commandLine=0x00e654e8, juce::JUCEApplication * const app=0x00e654a0) Line 193 C++
jucedemo.exe!juce::JUCEApplication::main(const char * const commandLine=0x00151f3e, juce::JUCEApplication * const newApp=0x00e654a0) Line 264 + 0x4a bytes C++
jucedemo.exe!WinMain(int __formal=4194304, int __formal=4194304, const char * commandLine=0x00151f3e, int __formal=4194304) Line 85 + 0x9d bytes C++
jucedemo.exe!__tmainCRTStartup() Line 315 + 0x35 bytes C
jucedemo.exe!WinMainCRTStartup() Line 187 C
kernel32.dll!7c816d4f()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
kernel32.dll!7c8399f3()
jucedemo.exe!SourceCodeWindow::SourceCodeWindow() Line 36 + 0x39 bytes C++
jucedemo.exe!juce::juce_loadPNGImageFromStream(juce::InputStream & in={…}) Line 126 + 0x2c bytes C++
ffdd4c7b()
[/i]

Thx
Thomas