How to make Arduino purr? (serious question)

I can imagine 2 ways to make Arduino purr (like a cat):

a) to record an actual purr and play it

b) to "build" the purr sound from scratch, pattern-by-pattern

This is a serious question.

As for a) I can go the usual way like playing music (from an SD card :slight_smile: or eeprom or FRAM)

For b) I have no idea and I could not find anything on the net. I suppose I shall use pwm in a certain intensity (amperage?) and pattern of wave (?).

Any idea , link or hint highly appreciated!

I don't think PWM will work. PWM is at a constant frequency (usually rather high in an Audio respect) and the PWM rate is the Ration of how Long the Signal is high vs low.

I suspect that to replicate a cats purr, you would first have to take your recording and look at it through an oscilloscope to see what it is you are trying to recreate.

falexandru:
I can imagine 2 ways to make Arduino purr (like a cat):

a) to record an actual purr and play it

b) to "build" the purr sound from scratch, pattern-by-pattern

This is a serious question.

As for a) I can go the usual way like playing music (from an SD card :slight_smile: or eeprom or FRAM)

For b) I have no idea and I could not find anything on the net. I suppose I shall use pwm in a certain intensity (amperage?) and pattern of wave (?).

Any idea , link or hint highly appreciated!

Get a short sound sample( half or one second), resample it to 8-bit/8kHz or 8-bit/4kHz WAV format.

Prepare the snippet for sound looping( begin an end must match,using an audio editing software, then you can play the sound endlessly as PCM sound from PROGMEM.

Regular digital audio is PCM (not [u]PWM[/u]) The Arduino doesn't have a DAC (digital-to-analog converter) so it can't directly play PCM. PWM is good enough to "dim" and LED or to control a motor, but it's NOT true analog.

With PCM, you "sample" the analog waveform (44,100 samples per second for CD audio). If you know how a speaker vibrates to generate sound, the waveform/samples represent the position of the speaker in-time. Then when you play-back, the digital-to-analog converter "connects the dots" to re-create the analog waveform. The [u]Audacity website[/u] has a nice introduction to how digital audio works.

a) to record an actual purr and play it

There is a [u]TMRpcm library[/u] that's supposed to approximate PCM pretty well and give decent sound. I've never used it.

b) to "build" the purr sound from scratch, pattern-by-pattern

It might be possible to [u]synthesize[/u] a purring sound, but you'd need to study-up on some concepts (maybe starting with [u]Fourier[/u], and then do some experimentation. it would be a LOT easier to record & loop the sound.

For b) I have no idea and I could not find anything on the net. I suppose I shall use pwm in a certain intensity (amperage?) and pattern of wave (?).

It's about Amplitude and time. The analog waveform shows you the amplitude at any/all points in time and the waveform exactly-represents the sound.

In the electrical domain, the amplitude is represents voltage. in the digital domain, the amplitude is simply a number (on an 8-bit, 16-bit, or floating-point scale, etc.). But, it's all relative... If you cut the volume in half, the voltages/amplitudes are all cut in half, but the basic "sound" is the same.

There is an amperage (current), but it doesn't come-into play until we're trying to get power out of a speaker. Power (Watts) is the product of Voltage x Current.

A constant pure-tone is a single constant-frequency sine wave. Real world sounds are of course not constant-intensity, and they contain multiple-simultaneous tones. It's these additional tones (harmonics & overtones) that make a guitar sound different from a piano when they are playing the same notes, and it's what makes two singers sound different when they are singing the same song/notes.

Most real-world sounds are mathematically complex and difficult to synthesize. Most modern "synthesizers" use sampled audio rather than attempting to build realistic sounds with an algorithm. And, it's virtually impossible (with current technology) to synthesize a singer. ...You can "fake" an entire orchestra with virtual instruments, but the singer has to be human.

P.S.
If you want to drive a speaker or headphones, you'll need an amplifier. The Arduino can put-out a "signal" but not enough current (amperage) to drive a 4 or 8 Ohm speaker. It can drive a piezo transducer, but a piezo can't put-out the low-frequencies of a purr.

Thanks Java and Jours! To the point!

Thanks DVDoug! Really comprehensive!

@DVDoug

I am looking for the easiest solution, as this is a component of a robo-cat. It is supposed Arduino to purr when petting it (:-). IF-THEN example for children.

To be honest I have difficulties in refraining myself to research the cat purr and re-create it digitally. :-))

A square wave or PWM signal includes many harmonic frequencies. If the intended signal contains (only) such harmonics, the digital signal can be filtered to achieve the right sound. A simple RC low pass filter may be sufficient, find out yourself. I'd start with a tone() of the lowest frequency, something between 10-30Hz I suppose, and vary the R and C to shape the signal. A better result may be obtained with a PWM signal of that keynote frequency, and the duty cycle can be varied to optimize the effective sound. Or you can mix two filtered digital (PWM) signals.

The required frequencies can be determined by a Fourier analysis of the intended sound, perhaps the Arduino FFT library can be used for that purpose. Then you can determine the frequencies from the amplitude peaks, the higher the more important. The synthesized signal can be analysed in the same way, what can help in the adjustment of the frequencies, duty cycles and filter values.

As mentioned above, record a .wav file of the sound of your choice. A PWM player that reads it off of an SD card, and plays it back in stereo, using only an ATTiny, is described here: Simple SD Audio Player with an 8-pin IC

Sound quality is amazing!

falexandru:
To be honest I have difficulties in refraining myself to research the cat purr and re-create it digitally. :-))

and you cannot provide any audio recording of a cat purring? Not even half a second recorded sound/audio file?

Actually, "difficulties in refraining" would mean feeling compelled to do it. :slight_smile:

@jurs
I will do it. Hope I am allowed to attached to post.
@aarg
100% right. :slight_smile:
@jremington
Do you consider stereo as mandatory to reach a certain quality threshold?
@DrDiettrich
Very clear and detailed idea! Thank you
@DVDdoug
Thank you for detailed explanation!
@JaBa
I do not have an oscilloscope :frowning: But the idea is worth exploring.

++++

For the moment, I am struggling to understand how an external EEPROM works, to understand the its needed coding.

I guess I could use the EEPROM rather than an SD, since I have to record it only once. As it has 1 million cycles, I hope the robo-cat will purr as long as a real cat does (15-20 years) :slight_smile:

The external EEPROM on I2C is very elegant and effective. But its coding requires deep understanding of C++, as far as I can see. Any tips or link to understand EEPROM coding will be highly appreciated. Also in respect in writing sounds to it.

@jremington
Do you consider stereo as mandatory to reach a certain quality threshold?

Of course not.

falexandru:
@jurs
I will do it. Hope I am allowed to attached to post.

What about his:
http://www.wavsource.com/snds_2017-06-18_4861080274558637/animals/cat_purr.wav

editing it a bit,convert to data, then playing either once or looping round and round in Arduino code?

How long do you want to play the sound?

@jurs
I have two options:
a) for as long as the touch senor is pressed (like a real cat :-)) - preferred
b) for 10-20 seconds , after touching the robo-cat between his ears - a bit bizarre

Both EEPROM and flash ( SD card ) can be read an unlimited number of times it is only write that is limited.

Reading a flash is not difficult, but you can not read it fast enough through normal speed I2C for good audio.

When I have used it for audio I transfer the data into SRAM connected to the SPI bus.

Grumpy_Mike:
Reading a flash is not difficult, but you can not read it fast enough through normal speed I2C for good audio.

When I have used it for audio I transfer the data into SRAM connected to the SPI bus.

I had a terrible time with SDs. I want to keep myself as far as possible from this modern torture tool.
I also suspect the real cat purr does not vary much, so once I figure out how to sort out few seconds, I can loop them indefinitely, no need for GB storage.

I prefer the EEPROM, since it gives more control over writing than an SD card. I am still learning EEPROM management ( I have posted the difficulties in the General electronic section of the forum).

I also like the flexibility of multiple EEPROM on the same I2C bus. I hope un module = 256 kb (=32 kB) will suffice for a few seconds (looping) purr. If I will figure out how to record or re-create it digitally.

Once I figure out how to manage the EEPROM, I have a good chance to "create" the cat's brain entirely, by assigning certain functions to each of the EEPROM modules.

This is not to ambitious. But the critical point is deep understanding of EEPROMs. That is really difficult.

[ /* OT Perhaps the Arduino.cc site would deserve a much more expanded reference section for EEPROMs. But this is another story and I do not want to hijack the thread.*/]

I didnt know the EEPROMs can be read indefinitely. Thank you!

The robocat shall perform (imitate) basic cat's operations, is not intended to be a modern Frankencat :-). But I want to model the life as much as possible in a hobby decent environment.

+++

I downloaded the cat purr, it is in wav format (thanks @Jurs!). I have now to find the way to store it in the EEPROM (fitting 256 kb). I shall have a look on TMRpcm library (Thanks @DVDoug!).

falexandru:
The robocat shall perform (imitate) basic cat's operations, is not intended to be a modern Frankencat :-). But I want to model the life as much as possible in a hobby decent environment.

I downloaded the cat purr, it is in wav format (thanks @Jurs!). I have now to find the way to store it in the EEPROM (fitting 256 kb).

I don't know of any Arduino sketch/example playing audio from EEPROM.

Why do you want to do it using EEPROM?

Typically you can store a short audio in aPROGMEM arraylike that:
Arduino Playground - HomePage preparing the datayou could easily play thr same sound loop from PROGMEM again and again.

I attempted to visualise the .wav file content (the cat purr), using Notepad. I got the following:

RIFFîx WAVEfmt + + dataÊx yyyy}}xux€}wuy€€yuw... rtc. Below 10 rows of text, which is encouraging.

++++

But I was expecting to see hexa data, not this string. OK, it is said to use Notepad++, which I do not have for the moment.

First bytes in this string are RIFF and WAVE - which belong to the header, I guess. The following characters are a complete mistery. Perhaps the Notepad attempted to translate hexa in ASCII or something similar.

++++

The easiest way would be to record to SD and then transfer from SD to EEPROM. Although I would be happier to send the .wav sequency directey from the PC to EEPROMs.

Or I can copy all data from notepad into a Arduino tab and slice it up from there to main body in order to send them via I2c to the poor EEPROMs (just my thoughts) - but either case I have to view the hexa sequence.

Any idea?

And here it is a detailed answer for part of the same subject (replicating the cat purr), dated 2015:

https://forum.arduino.cc/index.php?topic=343271.0

I am trying to keep track. :slight_smile:

falexandru:
I attempted to visualise the .wav file content (the cat purr), using Notepad. I got the following: [....]
Any idea?

.wav files contain binary data. It's not printable.