warning Data clipped during write to file

144 views (last 30 days)
Judyta
Judyta on 4 Dec 2012
Commented: Shan Shaffi on 9 Aug 2021
Im trying to create .wav file
s3 = (s2-min(s2))./(max(s2)-min(s2)).*2-1;
wavwrite(s3, 1250, 16, 'signal.wav');
and I got those warnings:
Warning: Data clipped during write to file:2012-11-23_13-08-18p.wav
> In wavwrite>PCM_Quantize at 285
In wavwrite>write_wavedat at 301
In wavwrite at 138
Does anybody knows how to solve it?
I fougth that clipped during write means that my data are not in the range of -1 and 1?

Answers (4)

Walter Roberson
Walter Roberson on 4 Dec 2012
-1 exactly is allowed in the data, but +1 exactly is not allowed.

fatima zahra manzah
fatima zahra manzah on 7 Apr 2021
I put this to save the 2 songs
f=44100
audiowrite("singingChurch.wav",singingChurch,f)
audiowrite("singingDungeon1.wav",singingDungeon,f)
i got this :
Warning: Data clipped when writing file.
How can i deal with this please
  4 Comments
Walter Roberson
Walter Roberson on 7 Aug 2021
If you are using a newer version of MATLAB, see rescale(); otherwise see mat2gray() .
However, you should be careful about whether you map minimum your data has, to -1, and the maximum to +1, or if you should instead map fixed values to -1 and +1. If you map according to the minimum and maximum present in your data, then you cannot use the result for absolute comparisons.
For example suppose that you were implementing a simple echo. If you had a loud enough original data happening at the time that a loud portion of earlier data was being mixed in, then you could exceed 1.0, and you might consider rescaling according to what is present in the data. For example the input data range might be [-1/2 1/2] and the echo data range might be [-3/4 5/4] and mapping might then be multiplying by 4/5, giving [-3/4 5/4] * 4/5 --> [-3/5 1] as the new data range.
Now suppose you take the same input data range [-1/2 1/2] and apply no echo -- so the output of the echo stage should be exactly the same as the input. Does it make logical sense that the unaltered input needs to be mapped (in which case you would double it to get [-1 1] in this situation)? Or does it make logical sense that instead in such a situation the output should be the same as the input? Remembering that the input expresses relative volumes: does it make sense that a light flute that receives no echo (perhaps the echo was longer than the piece; perhaps the angle was wrong relative to the surroundings) should suddenly become a much louder flute?
Also, watch out: that case of [-3/4 5/4], rescale() and mat2gray() would by default end up processing by subtracting 1/4, getting [-4/4 4/4] rather than scaling by 4/5: you need to decide which approach is right for your purposes.
Shan Shaffi
Shan Shaffi on 9 Aug 2021
Sorry for the late reply. I just read your answer. Thank you for taking the time to answer in detail. This was very helpful. I will try with rescale()

Sign in to comment.


Jan
Jan on 5 Dec 2012
The documentation explains: For 16 bit precision, the values are limited to –1.0 <= y < +1.0, when the signal is provided as floating point format. A workaround is to convert the data manually before calling wavwrite():
yInt = y * 32768;
yInt(yInt == 32768) = 32767;
  5 Comments
Walter Roberson
Walter Roberson on 18 Jun 2021
Edited: Walter Roberson on 18 Jun 2021
I woud recomment using audiowrite(), which does permit +1 exactly.

Sign in to comment.


Judyta
Judyta on 5 Dec 2012
Thank You for your answers, i wanted to ask one more thing, When this warning about clipping occurs, what really happends with those samples equal to 1? are reduced or avoided?
and Jan Simon, thank You for Your answer but i don't understand what this code does. May I please ask you to explain me?
  1 Comment
Daniel Shub
Daniel Shub on 5 Dec 2012
They are "reduced" by clipping them to the maximum/minimum allowed value. A difference between 1 and 1-2^15 is probably not anything to worry about.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!