[PD] Ram disk script for OS X (was Re: saving state of a patch)

Phil Stone pkstone at ucdavis.edu
Tue Jul 22 18:49:49 CEST 2008


Enrique Erne wrote:
> Phil Stone wrote:
>> Hi Atte,
>> Now that you're on your way with sssad, there's a nice trick you 
>> should know.  If you find that loading a preset causes dropouts, 
>> consider using a ram disk to hold your presets during performance.  
>> This solved all my dropout problems, and it's easy to do (I can post 
>> a script for OS X if anyone wants it).
> Hi Phil
> yes please post the script.
> thanks
> eni

OK.  Most of this script is error checking; three lines do all the real 

This creates the ram disk as a volume called "RamDisk".  You can change 
that name, if you like, by editing the line that begins with "DISK_NAME=..."

#echo "Creating ramdisk..."
if [ -n "$2" ]; then ARG_ERR=ERR; fi
if [ -z "$1" ]; then ARG_ERR=ERR; fi
if [ -n "$ARG_ERR" ];
echo 1 argument: size in MB

let "MB_SIZE *= 2048"
echo Creating ${MB_SIZE} 512-blocks ramdisk
CREATED_RAMDISK=`hdiutil attach -nomount ram://${MB_SIZE}`
echo New block device: ${CREATED_RAMDISK}

echo Creating volume with label: ${DISK_NAME}
newfs_hfs -v ${DISK_NAME} ${CREATED_RAMDISK}
echo Mounting in /Volumes/${DISK_NAME}
diskutil mount ${CREATED_RAMDISK}

exit 0

In my case, I call this from another script, which copies the presets I 
need into the ram disk:


# Create a 2M ramdisk:
~/ramdisk 2

# Copy music data to it
cp -R ~/PD_Patches/Presets/ /Volumes/RamDisk/Presets/
cp -R ~/PD_Patches/Presets_Meta/ /Volumes/RamDisk/Presets_Meta/
cp -R ~/PD_Patches/Scales/ /Volumes/RamDisk/Scales/
exit 0

Note that this works well for presets, and would probably be okay with 
small sound files.  However, all that's really happening is that the 
load time is shorter because of faster access to ram as opposed to hard 
drive.  If you load a big enough file, even from ram disk, and it takes 
longer than one dsp cycle to load, you'll still get dropouts.

Phil Stone

More information about the Pd-list mailing list