Sonic Visualiser is a re­cent dis­cov­ery for me, and I’m ab­solutely hooked on its breath­tak­ing spec­tro­grams. Its melodic range spec­tro­gram, when com­bined with A-B re­peat play­back and tempo ad­just­ment, has proven to be the per­fect tool for learn­ing to im­i­tate new man­dolin parts.

Sonic Visualiser spectrograph

Its syn­chro­nous au­dio play­back and spec­tro­gram dis­play can, how­ever, be an­noy­ingly slow at times. Disk IO ap­pears to be the lim­it­ing fac­tor.

From the Sonic Visualiser web­site,

The work Sonic Visualiser does is in­trin­si­cally proces­sor-hun­gry and (often) memory-hungry, but the aim is to al­low you to work with long au­dio files on ma­chines with mod­est CPU and mem­ory where rea­son­able. (Disk space is an­other mat­ter. Sonic Visualiser eats that.)

Sonic Visualiser saves on RAM us­age by keep­ing a huge disk cache. On faster hard dri­ves this may not pose a prob­lem, but my lap­top’s 5400 RPM disk just can’t de­liver the cached data fast enough dur­ing syn­chro­nous play­back.

Since I do have oo­dles of free RAM just itch­ing to be put to good use, I would like to make the re­verse trade-off to sac­ri­fice mem­ory con­sump­tion in re­turn for faster cache ac­cess. Sonic Visualiser does­n’t ap­pear to have a built in way to do this, but there’s an old trick we can use to ac­com­plish the same ef­fect:

tmpfs filesys­tems ap­pear as nor­mal disk space, but be­hind the scenes are stored pri­mar­ily in RAM. If Sonic Visualiser’s cache file di­rec­tory is put on a tmpfs filesys­tem, it will have the same ef­fect as stor­ing its cache in RAM.

With the fol­low­ing en­try in /etc/fstab,

# Faster cache location in RAM
fastcache /home/ak/.fastcache tmpfs size=1600M,noauto,user,exec,uid=1000,gid=1000 0 0

the com­mand

mount /home/ak/.fastcache

will cre­ate an empty tmpfs filesys­tem for use. All that’s left to do is tell Sonic Visualiser to keep its cache in that new lo­ca­tion.

Sonic Visualiser: Application Preferences

When you’re done, use the com­mand

umount /home/ak/.fastcache

to de­stroy the tmpfs and free mem­ory.

Quick stats to get a feel for how much space might be needed:

Size Used Avail Use%
Before open­ing Sonic Visualiser 2.2G 0 2.2G 0%
While dis­play­ing the spec­tro­gram of a 5-min track 2.2G 997M 1.2G 47%
After clos­ing Sonic Visualiser 2.2G 254k 2.2G 1%

Don’t worry about set­ting the max­i­mum size too high. Memory is only al­lo­cated for tmpfs as it grows in size, so RAM is­n’t wasted in that re­gard. Also, if there is­n’t enough free RAM to hold the en­tire tmpfs, the least-used parts will be stored in swap space in­stead. Once in swap space, the cache will lose its speed boost but con­tinue to func­tion up to its max­i­mum size.

Thanks go to steven­robert­son for the idea in­spi­ra­tion.