How to use the method drawChannel()?

Hi everyone,

I’m a beginner in C++ programming and I’m trying to create a small application able to analyze an audio file such as a .wav or a .mp3, and draw the relative waveform on a PNG file. I’m working with linux on eclipse C++ .

What I’m trying to do is to use the AudioThumbnail class:

AudioThumbnail (const int sourceSamplesPerThumbnailSample, AudioFormatManager &formatManagerToUse, AudioThumbnailCache &cacheToUse) Creates an audio thumbnail.

From that class i wanna use the functionality to draw the channels:

drawChannel (Graphics &g, int x, int y, int w, int h, double startTimeSeconds, double endTimeSeconds, int channelNum, const float verticalZoomFactor) Renders the waveform shape for a channel

there i start to get a little bit in troubles because I don’t understand the documentation very good, it’s everything clear more or less but the first parameter I need is a Graphic objet, isn’t it?
The I find that:

Graphics (Image &imageToDrawOnto)
  1. So there I need to create an Image object: but the problem is that I don’t find the way to declare the first parameter of it…

Image (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage) Creates an in-memory image with a specified size and format.

I tried with something like “PixelFormatRGB”, “juce::PixelRGB”, “PixelformatRGB 3”…I tried everyway but from compiling this always goes to an error, telling me that the first parameter is wrongly declared.

  1. What imageToDraw stands for?? is it a string for the output filename? or something else?

Does someone know how to do it correclty? or anyway tell me a nice source to learn about how to use this library?



Look here what a Image class is:

If the method says Image then it’s not a String !!

Typicall you create an image, then a graphics to draw on it and you are done:

Image img (Image::ARGB, 800, 600, false);
Graphics g(img);

g.setColour  (Colours::red);
g.drawLine (0, 0, 800, 600);

OutputStream* out = File("my_png_file.png").createOutputStream();
    PNGImageFormat pngFormat;
    pngFormat.writeImageToStream  (img, *out);
delete out;

ps. it’s better you start off learning C++ from scratch instead of starting with stuff like this

Grazie per la risposta, questo mi darà una mano.

Si lo so che queste cose non sono facili conosco bene il signal processing e l’audio processing…ma conosco solo le basi del C++, e non conosco molte librerie per elaborare l’audio ed usare le FFT, il mio corso di studi non mi ha dato solide conoscenze informatiche, specialmente di programmazione ad oggetti.

So che sarebbe meglio ripartire da capo, ma…non ne ho affatto il tempo, quindi tocca sfondare il muro a testate :stuck_out_tongue:

Grazie ancora per il consiglio.


need a translator…


no, there’s no need for a translation, I was just thanking kracken for his answer. I figured out he he’s Italian too, so I answered in our language, he’s answer helped me a lot but I think I have problems importing the library.
Still I get a compiler error, I think the problem comes from how I import the juce library on eclispe, maybe I have the wrong headers.
I migrated on netBEANS and that’s what I get:

g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/analyzer.o.d -o build/Debug/GNU-Linux-x86/analyzer.o analyzer.cpp In file included from /home/gio/Scrivania/juce/src/juce_app_includes.h:723, from /home/gio/Scrivania/juce/juce.h:66, from analyzer.cpp:10: /home/gio/Scrivania/juce/src/juce_appframework/gui/components/special/juce_QuickTimeMovieComponent.h:45: error: ‘NSViewComponent’ does not name a type /home/gio/Scrivania/juce/src/juce_appframework/gui/components/special/juce_QuickTimeMovieComponent.h:54: error: expected class-name before ‘{’ token make[2]: *** [build/Debug/GNU-Linux-x86/analyzer.o] Errore 1

basically what I see from the headers of that component is the following:

#include "juce_appframework/gui/components/special/juce_QuickTimeMovieComponent.h"

#include "src/juce_app_includes.h"

I included the library this way:

#include "/home/gio/Scrivania/juce/juce.h"

and these are the lines where i get errors in the QuickTimeMovieComponent.h header file:

on this line of the header says:

[code]class JUCE_API QuickTimeMovieComponent : public QTCompBaseClass
/** Creates a QuickTimeMovieComponent, initially blank.

    Use the loadMovie() method to load a movie once you've added the
    component to a window, (or put it on the desktop as a heavyweight window).
    Loading a movie when the component isn't visible can cause problems, as
    QuickTime needs a window handle to initialise properly.

/** Destructor. */

here the problem is that when at the beginning there’s the “{” symbol the compiler finds the following error:

any ideas?

Thanks again.