Go Down

### Topic: Skipping samples limit (Read 504 times)previous topic - next topic

#### suraj_150890

##### Dec 09, 2016, 10:34 amLast Edit: Dec 09, 2016, 11:02 am by suraj_150890
Hii Mates,

I have one doubt, If suppose I have 6000 samples in an audio and now I want to skip samples for e.g: every 5th samples or every 10th samples. So how much number of samples I can skip? Is it possible to skip every 100th samples too? I know that skipping sample will degrade the audio quality but for me that is not so important since I am preparing sound generator for Electric vehicle. For skipping samples I am using exponential approach which ranges from 0.5 to 5 i.e it will skip samples every 0.5th or 5th samples based upon the velocity of vehicle.

Here is the code implementation
Code: [Select]
`  float idx = kph / SPEED_THRESHOLD;  // i.e Speed threshold = 75  n1 = (Speed[0] - (Speed[0] * exp(-idx / 2))) + CSpeed[0]; // exp in range 0 to 5sampler[0].setSpeed1(n1);  if (n1 < SPEED_MIN) {              n1 = SPEED_MIN; //0.5            }            if (n1 > SPEED_MAX) {              n1 = SPEED_MAX; //5            }`

#### Grumpy_Mike

#1
##### Dec 09, 2016, 01:41 pm
Quote
now I want to skip samples
Why?

Quote
So how much number of samples I can skip?
As many as you want. The problem is that when you skip a sample you are in effect reducing the sample rate and so opening the whole thing up to producing aliasing errors, which sound awful.

Quote
I know that skipping sample will degrade the audio quality but for me that is not so important since I am preparing sound generator for Electric vehicle.
This sounds to me like an X-Y Problem

#### pjrc

#2
##### Dec 13, 2016, 01:39 pm
I know that skipping sample will degrade the audio quality but for me that is not so important since I am preparing sound generator for Electric vehicle.
If you're willing to have quality so terrible, so horrible the Nyquist aliasing will overpower any remaining signal, why bother with the original samples at all?  Why not just generate some random numbers or something?

Nyquist aliasing is real.

#### DVDdoug

#3
##### Dec 13, 2016, 08:09 pm
Quote
I have one doubt, If suppose I have 6000 samples in an audio and now I want to skip samples for e.g: every 5th samples or every 10th samples.
Use an audio editor (such as Audacity) to resample/downsample before saving the audio file.    The sample rate is samples-per-second, so if you want to reduce the number of samples, reduce the sample rate.

A proper downsampling algorithm will low-pass filter before downsampling to prevent aliasing (false frequencies).

The Nyquist theory says your sample rate must be at least twice the audio frequency.  For example, audio CDs have a sample rate of 44.1kHz for a theoretical maximum audio frequency of 22,050Hz (above the limit of human hearing).    If you think about it, you need at least one sample for the top-half of the wave and one sample for the bottom-half.     If none of that makes sense, the Audacity manual has a nice little Introduction to Digital Audio showing how audio is digitized and how you "connect the dots" to reconstruct the analog waveform.

If your goal is smaller files or lowering the processing requirements, consider getting an MP3 audio shield.  MP3 files are smaller (without as much quality loss) and the shield takes care of decoding & playing the audio.

Go Up