# AudioThumbnail example

**URL:** <https://forum.juce.com/t/audiothumbnail-example/3759>\
**Category:** General JUCE discussion\
**Created:** [March 12, 2009, 1:36pm UTC](https://forum.juce.com/t/audiothumbnail-example/3759 "2009-03-12T13:36:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [March 12, 2009, 1:36pm UTC](https://forum.juce.com/t/audiothumbnail-example/3759/1 "2009-03-12T13:36:53Z")

</div>

i can’t get any pciture out of this class

```auto
	AudioFormatManager::getInstance()->registerBasicFormats();
	fi = new FileInputSource (File (T("d:\\file.ogg")));

	thumbnail = new AudioThumbnail (128, *AudioFormatManager::getInstance(), cache);
	thumbnail->addChangeListener (this);
	thumbnail->setSource (fi);
```

and in my paint method

```auto
thumbnail->drawChannel (g, 16, 64, getWidth()-128, getHeight()-128, 0, thumbnail->getTotalLength(), thumbnail->getNumChannels(), 1.0f);
```

i get the callback info, but i don’t know how to set the AudioThmubnailCache, i initialize it with 512, and the AudioThumbnail with 128 and i tired more. and nothing paints itself.

does anyone have a working example of how to use this, i see that the cache is a TimeSliceThread, i don’t know if i have to start it myself?

–  
i don’t want to post a third post (someone will hate me), i was wondering if anyone had any examples on how to write a frequency analyzer component, like in any audio player.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 12, 2009, 3:09pm UTC](https://forum.juce.com/t/audiothumbnail-example/3759/2 "2009-03-12T15:09:49Z")

</div>

I do mine like this:

```auto
	// set up the format manager to read basic formats
	formatManager = new AudioFormatManager();
	formatManager->registerBasicFormats();
	
	// instansiate the cache and the thumbnail
	thumbnailCache = new AudioThumbnailCache(2);
	thumbnailViewLow = new AudioThumbnail(512, *formatManager, *thumbnailCache);
```

Then the drawing in the same way you have. Bare in mind that you have to draw each of the channels separately eg. channel 0 for left and 1 for right. If your using thumbnail-\>getNumChannels() it will return 2 (most probably) so you’re trying to draw a channel that doesn’t exist.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [March 12, 2009, 3:14pm UTC](https://forum.juce.com/t/audiothumbnail-example/3759/3 "2009-03-12T15:14:08Z")

</div>

damn …

your right, rookie mistake.

it works now, thanks.
