It seems the cat protector project documentation has a small gap. There is just a hint that you have to use some scripts to prepare the SD card to play the audio files, but no details about this.
To use the scripts you need some knowledge how to use a command line interface on your operating system. The scripts are very simple to use on Linux and Mac OS X, but on Windows it is very tricky. I strongly advice you to use either Linux or Mac OS X. If you are working on Windows, just use a free virtual machine application and install a Linux (I suggest Ubuntu) or a Linux live CD where you don’t have to install anything.
Why? …. Why … that … complicated
The used microcontroller is not very fast, if the software on the microcontroller also has to deal with a complicated filesystem, no sequential blocks and other obstacles, changes are small to produce sound output in a good quality. Therefore I prepare the samples in a very simple format and instead of a complicated file system, I just store the blocks with the audio data sequentially onto the SD card.
Install Required Software
You have to install SOX which is a command line tool to convert audio files from one to many formats. SOX is available here. You find installers for all operating systems on this website.
After installing SOX, open a terminal window and test if SOX is working on the command line. Enter this command:
sox --help
You should get an output like this:
sox: SoX v Usage summary: [gopts] [[fopts] infile]... [fopts] outfile [effect [effopt]]... SPECIAL FILENAMES (infile, outfile): - Pipe/redirect input/output (stdin/stdout); may need -t ... ...
If you get an error message, there is something wrong. Check if you correctly installed the tool and if the tool is accessible.
The scrips also require the script language Perl to work. This is usually installed on all modern operating systems (except Windows).
Prepare the Sound Files
First prepare your sound files. Record them using any suitable audio tool and save them in any possible format which is supported by the SOX tool. I suggest you record and save your samples as uncompressed WAV files, 44.1kHz.
In this example I name the original audio files as shown below:
OriginalSound01.wav OriginalSound02.wav OriginalSound03.wav
Create the Work Directory
Create a new directory Work
somewhere and copy the script files ConvertAudio.pl
and CreateDiskImage.pl
and your original sound files into this working directory.
Create a sub directory DiskA in the work directory.
Convert the Sound Files
Now use the ConvertAudio.pl
script to convert your original sound files in the required raw format.
> cd [to your work directory]/Work > ./ConvertAudio.pl OriginalSound01.wav DiskA/v01.snd Input File : 'OriginalSound01.wav' Channels : 1 Sample Rate : 22050 Precision : 16-bit Duration : 00:00:01.25 = 27563 samples ~ 93.7517 CDDA sectors File Size : 55.2k Bit Rate : 353k Sample Encoding: 16-bit Signed Integer PCM In:100% 00:00:01.25 [00:00:00.00] Out:27.6k [!=====|=====!] Hd:0.4 Clip:0 Done.
Repeat the conversion with all your original files, until your directory DiskA
contains all the sound files.
Please Note: Do not use any space or special character in the file names. Use simple letters and numbers, nothing else. The file names on the DiskA
are stored in the disk image. They should be as short as possible.
Create the Disk Image File
As next step, convert the files in the DiskA
directory to a disk image file.
> ./CreateDiskImage.pl -i DiskA -o DiskA.bin Create Disk Image ------------------------------------------------------------------------------ File "v01.snd" size=3177472 bytes startBlock=1 File "v02.snd" size=3763200 bytes startBlock=6208 File "v03.snd" size=3763200 bytes startBlock=13559 File "v04.snd" size=55126 bytes startBlock=20910 File "v05.snd" size=88200 bytes startBlock=21018.66796875 Writing disk image... Writing file v01.snd ... position=512, block=1 Writing file v02.snd ... position=3178496, block=6208 Writing file v03.snd ... position=6942208, block=13559 Writing file v04.snd ... position=10705920, block=20910 Writing file v05.snd ... position=10761558, block=21018.66796875 Disk image was successfully written.
Now you have a new file DiskA.bin
. This is the “disk image” which has to be written on the SD card. Not copied as a file on the SD card. We talk here about overwriting the contents (and filesystem) of a SD card with this binary file.
Write the SD Card
Absolute serious warning! No kidding, if you do the next steps wrong, you will definitely overwrite your operating system or lose random data. It will hurt, you will cry. Therefore read carefully.
For the next step we are using a low level write operation to write directly on the SD card. To do this, we need to know the correct device name for the SD card. By the way, the SD card will get overwritten, all previous stored files on the used SD card will be lost.
Linux
On Linux use the lsblk
command. First use it without the SD card plugged in your computer. You will get an output like this:
> lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 19G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 1022M 0 part [SWAP] sr0 11:0 1 1024M 0 rom
Now plug the SD card into your computer, wait a few seconds and use the lsblk
command again:
> lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 19G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 1022M 0 part [SWAP] szz 8:48 1 59.9G 0 disk └─szz1 8:49 1 59.9G 0 part sr0 11:0 1 1024M 0 rom
You see there is a new device szz
. This has to be the plugged in SD card. For Linux the device path is therefore:
/dev/szz
Warning! This is an example, the name for the SD card is for sure different in your case.
Max OS X
On Mac us the command diskutil list
First use it without the SD card plugged in your computer. You will get an output like this:
> diskutil list /dev/disk0 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *1.0 TB disk0 1: EFI EFI 209.7 MB disk0s1 2: Apple_CoreStorage Macintosh HD 999.7 GB disk0s2 3: Apple_Boot Recovery HD 650.0 MB disk0s3
Now plug the SD card into your computer, wait a few seconds and use the diskutil list
command again:
> diskutil list /dev/disk0 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *1.0 TB disk0 1: EFI EFI 209.7 MB disk0s1 2: Apple_CoreStorage Macintosh HD 999.7 GB disk0s2 3: Apple_Boot Recovery HD 650.0 MB disk0s3 /dev/disk4 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *64.3 GB disk4 1: Windows_NTFS 64.3 GB disk4s1
You see there is a new device /dev/disk4
. This has to be the plugged in SD card. For Mac OS X the device path is therefore:
/dev/disk4
Warning! This is an example, the name for the SD card is for sure different in your case.
For Mac OS X before you can write to the SD card, you have to “unmount” it with this command:
diskutil unmountDisk /dev/disk4
Write the Disk Image
Now you can use the dd
command to write the SD card. You have to prefix the command with sudo
to execute the command with admin rights. You will be prompted for the administrator password.
sudo dd if=DiskA.bin of=/dev/disk4 bs=512
Depending on the size of your image, this can take a while.
Success!
After this steps, the SD card is prepared to use it with the Cat Protector project.