How to code a self destructive sound loop

Hi everybody! For an art project I would like to make my Arduino Uno play a short sound loop (from an micro-sd card shield) that self-destructs progressively over a relatively long period of time. My question is super simple: how can I code this this self-destruction/degradation of the sound loop? I don't really know where to start, I really hope you can help me out!
Claudio

Hi,
What do you mean by degradation?
Does the sound file get shorter or do you introduce more and more distortion until you have just noise?

Tom... :slight_smile:

Thank you for your reply!
Basically yes, I want it to be more and more distorted so that I eventually only have some sort of noise.

Easiest:
Get a DF Player Mini (mp3 player with built-in SD card and speaker output). On that SD card place the sound file and all the progressively degrading versions of it. Play back in order.

yes that would definitely be an effective way, but for the sake of my art project I would like to get that progressive degradation as an automatic process based on coding. no one has hints on how to achieve it?

Use a RPi.
An Arduino can tell the mp3 player to play back a song, there's no chance for it to do any actual processing on the file. It can't even decode the mp3 file by itself.

Maybe you could play the sound unchanged but mix more and more noise into it.

Use a RPi.
An Arduino can tell the mp3 player to play back a song, there's no chance for it to do any actual processing on the file. It can't even decode the mp3 file by itself.

That's a very good suggestion, although there are ways of playing limited-quality WAV files.

You probably don't want to destroy the original audio file, so you probably want to alter a copy in RAM or change the data as it's playing. Limited RAM is another good reason NOT to use the Arduino.

A [u]WAV file[/u] is a header followed by a series of samples* so it would be pretty simple to corrupt the samples with random data. If all of the samples are random you have white noise.

But... It's a LOT of data... CD audio is 44,100 samples per second, and it 16-bit stereo so that's 176k bytes per second.

And another thing is... If you just start randomly changing bytes you'll get some loud "cllcks" and "pops" here-and-there.

If you want a smoother transition you can generate white noise, or create a white noise or pink noise** file and mix (blend) it in. For example, you can slowly fade-out the while slowly fading-in the noise.

Mixing is done by summation (summing the 1st sample from file-A and the 1st sample from file-B, etc.) But if you want to avoid clipping (distortion) or "rolling over" integers you usually make a weighted average by multiplying the A-sample by 90% and the b-sample by 10%, etc., before adding. In your case, you might actually want the distortion so that's up to you.

In Audacity, it's easy to make a long-*slow crossfade and save the results to an audio file, but I guess you want it to "interact" in real time?

If you are working with the "raw data" (bytes) from a WAV file, you'll have to know how the bytes are organized. For example, with 16 & 24-bit files the most-significant byte comes first and if it's a stereo file, the left & right channel samples alternate.

Technically, noise isn't distortion so it depends on what you want to do. Noise is "unwanted sound". Usually it's more-or-less constant like a constant hiss or hum that's always present and it's usually in the background (depending on how bad it is.) But a barking dog could also be considered noise, unless the dog is what you want to record the dog. :wink: Regular background noise is most noticeable during the quiet parts and often unnoticeable during the loud parts.

Distortion is a (usually unwanted) change in the sound and the wave-shape. Unlike noise, there is no distortion when there is no signal. There are various kinds of distortion. The most common kind of distortion is [u]clipping[/u] (squared-off waves) . That's "overload" distortion where you try to get 150 Watts out of a 100W amplifier, or if you have 16-bit audio data that "tries" to go higher than you can "count" with 16-bits. And of course, clipping only happens during the loud parts. (Actually, worse things can happen digitally if an integer "rolls-over"... The sign-bit gets flipped so it suddenly goes from positive to negative (or vice-versa) so audio programmers have to take extra steps to get clipping instead of roll-over... The lesser of two evils.)

** Pink noise is more "natural sounding" than purely random white noise (less harsh with reduced high frequency content).

I know very little about audio but I believe it should be very simple to create the blending of noise into the original sound in hardware. Maybe a digital pot? Just slowly increase the noise and decrease the sound. Or is is more difficult?

In my little experience playing with audio amplifiers it is VERY easy to introduce unwanted noise.

The difference is that the OP is trying to introduce WANTED noise - assuming that's indeed what he's looking for when talking about "degradation". That's a whole different ballgame :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.