Go Down

Topic: Replicating a cat purring? Newbie question (Read 1 time) previous topic - next topic

arduinokov

Hi,

I would like to replicate the sound of a cat purring, just a simple loop. My project already plays some other sounds, but I at a loss where to start with making it "purr". I mean an audible purr, not just a vibration.

I am just looking for some advice on where to start with generating a purr, I am happy to work on the code to achieve the final result.

Thanks :)

robtillaart

use an mp3 player with different tracks on an SD card and play them at tandom?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

arduinokov

Hi,

Thank you very much for taking the time to reply :)

It is a very small project, I am using an Arduino Pro mini with a very small speaker and I do not have room to fit in an MP3 module. I would like to generate the purr sound through code.

:)

robtillaart

Try to sample it (8 bit mono)  and store it in PROGMEM? (or external EEPROM)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

tmd3

#4
Aug 23, 2015, 01:36 am Last Edit: Aug 23, 2015, 01:58 am by tmd3
Here's my advice:  You can find a couple of sound files on SoundBible.com, using "cat purr" for a search, and "cat purring" for another search.  Pick the one you like the best, keeping in mind that you have a limited amount of flash memory to store sounds in - with about 32K of flash memory and a sample rate of 8 kHz, certainly not as much as four seconds, and substantially less if your program is long and complicated.  Use Audacity to resample the file to 8000 Hz.  Clip the purr to 1 cycle of breathing in and out, and amplify the result as much as Audacity recommends.  Use Analyze>Sample data export to export a set of samples, selecting the linear scale.  

Import the sample file into a spreadsheet, separate the data by columns, and multiply the data by 128 [Edit: add this] and add 128, and round to zero digits after the decimal.  Write formulas to concatenate each entry with a comma, and concatenate that to the entry below, cascading until you have them all - it will be a very long string.  If you like, you can restart the string every 16 or so rows, and then use an index function to fetch the data into a single column.  That data will be the initialization for an array of samples in progmem.

That gets the sample into your code.  From there, play it with PWM.

I'm going to guess that your project is intended to soothe somebody that's fond of cats, as a sort of relaxation or sleep aid.  It's not clear that just repeating the same two seconds of purring will satisfy a bona fide cat lover, so you might have to experiment with random changes, maybe with volume, and with the lengths of the silent spaces between purring sounds.

A text file of a list of numbers generated from one of the purr files, and a wav file generated from that list and repeated five times, are attached.  [Edit:  No, it's a zip file with just the wav inside; the forum won't let me attach a wav]  The wav is written as an 8-bit PCM, with 8000 samples / second, so it's a fair approximation of how it should actually sound in a well-filtered PWM implementation.  This isn't necessarily what you'll want to use, since it's hard to predict whehter a cat afficianado will be satisfied with any particular electronic imitation of a purr, but it will give you an idea of what's reasonably possible using an ATmega328P.

arduinokov

Thanks very much for the detailed answer. I will take some time and try to implement your suggestion. I really appreciate your time and effort, thanks again. :)

Go Up