# Audio thumbnails

**URL:** <https://forum.juce.com/t/audio-thumbnails/2633>\
**Category:** General JUCE discussion\
**Created:** [March 7, 2008, 9:31am UTC](https://forum.juce.com/t/audio-thumbnails/2633 "2008-03-07T09:31:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 7, 2008, 9:31am UTC](https://forum.juce.com/t/audio-thumbnails/2633/1 "2008-03-07T09:31:32Z")

</div>

If anyone’s interested, I’ve just posted some code on the SVN tip that adds a few classes for generating audio thumbnails. I think people have asked about how to do this before, and any comments would be welcome!

---

<div class="post-metadata">

**Author:** ![ptomaine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ptomaine/32/245_2.png) [@ptomaine](https://forum.juce.com/u/ptomaine)\
**Post date:** [March 9, 2008, 3:39pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/2 "2008-03-09T15:39:28Z")

</div>

Thank you thank you thank you thank you Julian.  
Yesterday, I’ve played a bit with the new class and I think this is very handy class a lot of people were waiting for.

A small request. Sometimes, it’s very good to pass already opened AudioFormatReader to the class instead of InputSource. Can you provide an additional initialization method for this purpose? Of course, if you can duplicate an AudioFormatReader class instance.

One more. The building process is very CPU time consuming, so can you add something like Thread::sleep(20) to lower that?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 9, 2008, 9:06pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/3 "2008-03-09T21:06:37Z")

</div>

Ok, I can add an extra method to take an audioformatreader.

Since the cache object is a thread, you could lower its priority to whatever level you need. That’d probably be a better fix than forcing it to sleep.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 9, 2008, 9:09pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/4 "2008-03-09T21:09:01Z")

</div>

Ah, no - sorry, I forgot. It can’t use an audio reader, because it needs to have the ability to create and delete the stream itself whenever needs to. That’s why it uses the new InputSource class.

---

<div class="post-metadata">

**Author:** ![ring2](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ring2](https://forum.juce.com/u/ring2)\
**Post date:** [March 10, 2008, 11:10am UTC](https://forum.juce.com/t/audio-thumbnails/2633/5 "2008-03-10T11:10:44Z")

</div>

I’m also interested in the audio thumbnails. 😃

> [@](#):
>
> One more. The building process is very CPU time consuming, so can you add something like Thread::sleep(20) to lower that?

For example, Apple’s Logic Pro asks users that whether the processing requires high CPU load or background when the audio thumbnail is being created. An alert dialog is shown and it has a toggle button to set the answer as default. (“Don’t show this alert next time”)

I think developers who use the JUCE’s thumbnail class wantto implement the similar thing.

Best regards,  
Masanao Hayashi

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 10, 2008, 11:29am UTC](https://forum.juce.com/t/audio-thumbnails/2633/6 "2008-03-10T11:29:06Z")

</div>

would be cool if you can pass a priority flag to the constructor of the thumbnailer, in order to lower the overall cpu usage of the inner scan/calculation thread.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 10, 2008, 8:58pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/7 "2008-03-10T20:58:03Z")

</div>

It’s only a case of calling setPriority() on your cache object when you create it.

---

<div class="post-metadata">

**Author:** ![tim\_is\_tof](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tim\_is\_tof](https://forum.juce.com/u/tim_is_tof)\
**Post date:** [April 8, 2008, 2:51pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/8 "2008-04-08T14:51:32Z")

</div>

There seems to be a bug in the audioThumbnail class (in the juce-tip). I was testing how long it would take to thumnail a aif file of a complete CD. Sometimes (after fullyLoaded == true) a call to drawChannel causes an acces violation. Before updating to the tip I used rev 406 and wasn’t able to thumnail aif files at all. The funny thing is that the bug only manifests itself in Windows XP, OS X doesn’t seem to suffer from it.

Also, why the need to delete the reader after a certain amount of time?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 8, 2008, 5:24pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/9 "2008-04-08T17:24:58Z")

</div>

I checked in a new version a couple of days ago - you might want to try that. But if you can narrow down the bug, I’d love to know about it.

It releases the reader to avoid locking the file for longer than it needs it. I’ve fine-tuned this in the latest version too.

---

<div class="post-metadata">

**Author:** ![tim\_is\_tof](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tim\_is\_tof](https://forum.juce.com/u/tim_is_tof)\
**Post date:** [April 10, 2008, 2:17pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/10 "2008-04-10T14:17:09Z")

</div>

Yes, i’ve tried the new revision to no avail… The bug seems rather hard to reproduce, but mostly happens when using really long files (like an hour).

The bug manifests itself in the drawChannel function, just after this bit (line #517 of AudioThumbnail.cpp):

const char\* cacheData = ((const char\*) cachedLevels.getData())  
+ (channelNum \<\< 1)  
+ skipLeft \* (numChannelsCached \<\< 1);

I doubt that it has anything to do with the variables I’m passing in  
(x=0,y=0,w=722,h=36,start=0.0,end=3913.48,channel=0,zoom=1)

---

<div class="post-metadata">

**Author:** ![tim\_is\_tof](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tim\_is\_tof](https://forum.juce.com/u/tim_is_tof)\
**Post date:** [April 10, 2008, 2:18pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/11 "2008-04-10T14:18:23Z")

</div>

Oh yeah, it’s not just AIF files, but WAVs as well…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 10, 2008, 3:50pm UTC](https://forum.juce.com/t/audio-thumbnails/2633/12 "2008-04-10T15:50:11Z")

</div>

I can’t see any errors with that code, but have never tried it on a file that long (in fact, I don’t think I even have any files that long…)

Maybe a maths overflow? If you can catch it in the debugger, any numbers you can find would be helpful.
