You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
File audio flac error
1 view (last 30 days)
Show older comments
How to create file audio in flac format? I have used audiowrite but it hasn't worked. The error is described as "Warning: Data clipped when writing file. > In audiowrite>clipInputData (line 396) In audiowrite (line 176) " Can you solve this problem please? Thank you!
2 Comments
Geoff Hayes
on 22 Jan 2016
Ferz14 - you are observing a warning and not an error or is there a problem with the audio file?
See Walter's answer at http://www.mathworks.com/matlabcentral/answers/257223-audiowrite-clipping-warning-issue for an explanation of the warning.
Answers (1)
Walter Roberson
on 23 Jan 2016
You could write out an audio file with amplitude 5, but it would have to be integer 5, representing 5/255 of maximum amplitude (uint8) or 5/32767 of maximum amplitude (int16) or 5/(2^31-1) of maximum amplitude (int32)
If you are writing a floating point value, then the value always represents fraction of the maximum; if you were able to represent a value 5 times the maximum then the clearly the maximum would be high enough to encompass that 5 times value, so by way of contradiction the value cannot exceed 1.0 in floating point.
24 Comments
Ferz14
on 23 Jan 2016
Edited: Walter Roberson
on 23 Jan 2016
Thank you! But I don't understand where I'm wrong.
This is my code :
amp=5;
fs=4800;
duration=10;
freq=5000;
values=0:1/fs:duration;
a=amp*sin(2*pi*freq*values);
Could you explain me where I'm wrong please?
Walter Roberson
on 23 Jan 2016
Edited: Walter Roberson
on 23 Jan 2016
In .wav files as .flac files, an amplitude of 1.0 means "move the speaker cone as out as it can go", and an amplitude of -1.0 means "move the speaker cone as far in as it will go." An amplitude of 5.0 would then have to mean "move the speaker cone five times further out than it can go".
Audio files do not hold information about absolute magnitudes such as "5 volts peak to peak" or "5 mm" or "5 decibels": they hold relative magnitudes, relative to 1.0 being "maximum".
What is wrong with your code is your expectation that audio files store absolute information.
If you want to store absolute information instead of relative information, then you need to use a different kind of file, such as using save(), or xlswrite(), or using fopen()/fwrite()/fclose() to create a binary file.
Walter Roberson
on 23 Jan 2016
DAQ boards seldom receive audio files. DAQ boards usually receive data samples without going through the step of creating an audio file. If you do not go through an audio file then you can send up to the maximum value your DAQ channel supports. Typically that would be a 16 bit integer or a 32 bit integer or a 32 bit single precision number, but it varies with how the channel is configured.
But, Yes, if your DAQ is one of the few that does need an audio file, then the maximum value you can send is equivalent to 1.0 . Whether the file will actually represent it as single precision or not is going to depend on the exact parameters you pass to wavwrite() or audiowrite(). And then on the other side of your DAQ, you would set up your amplifier so that the 1.0 came out as 5 of whatever units you are looking for.
I have never encountered a DAQ that needed an audio file. The closest I have encountered is that on early SGI workstations, the sound subsystem took μLaw encoded samples -- which was a per-sample format, not a file.
Walter Roberson
on 23 Jan 2016
Digital triggers are not audio files! You just create the samples the way you did already, and send them out on a channel that is configured to expect single precision or double precision.
However, generally speaking it is only analog channels that expect floating point, with digital channels expecting bits
The situation is a bit different if you are using Instrument Control toolbox to talk to an instrument, rather than talking to a DAQ board.
Ferz14
on 23 Jan 2016
I wrote the program in c to sample an analog input with a digital trigger. So, I create a binary file then I send it out on a channel that I configured in my code. Or I use addDigitalChannel. Is it right? Thank you and sorry for my numerous questions.
Walter Roberson
on 24 Jan 2016
Is the intention that the DAQ board will convert to analog, such as for playing out a speaker? If so then you will want to add an analog output
Ferz14
on 25 Jan 2016
I have a file audio that I send to my DAQ board. I need a digital trigger so I have in output 125000 samples of my analog input. How can do it? I have the program in c where I configured analog/digital channel. The program works but I don't know how to create digital trigger and how to send trigger to my DAQ board. Thank you so much!
Walter Roberson
on 25 Jan 2016
We need to know how many bits wide the digital trigger is, and what the encoding format is for what is being sent to it.
Please note that "trigger" is usually used for the case where a particular value is used to initiate or terminate an action, such as to trigger a motor to start or stop. A digital trigger is usually only a single bit wide. If you are sending values that will be interpreted as data, such as brightness level or amplitude for a speaker, then that would be referred to as a "sample" rather than a "trigger".
What kind of DAQ are you using? And what will the DAQ do with the data you send it?
Walter Roberson
on 25 Jan 2016
Is the point to tell the DAQ to sample 125000 inputs?? If so then the "file audio" would have nothing to do with that, especially not for a digital trigger. Now if you had a DAQ which is triggered by the rising edge of an analog signal and your amp*sin(2*pi*freq*values) is all about constructing that analog signal, that would be more understandable... but I suspect unnecessary.
Ferz14
on 25 Jan 2016
I send to my DAQ an analog input. The DAQ start to sample the input at the rising edge of digital trigger. But I don't know how to create the digital trigger and how to send trigger to my DAQ. Sorry but I'm very confused.
Walter Roberson
on 25 Jan 2016
The NI USB-6210 is directly supported by the Data Acquisition Toolbox, which will take care of the details of reading samples if you configure it with addAnalogInputChannel()
Walter Roberson
on 25 Jan 2016
You do not need the addDigitalOutputChannel for this, I am pretty sure. Let the DAQ Toolbox take care of whatever triggering it needs when you acquire data;
Walter Roberson
on 25 Jan 2016
I really doubt that you need to send a pulse to your DAQ. If that were the case, then the DAQ would have to be somewhere remote from you, and you would need a second DAQ to generate the pulse to send to the DAQ you are referring to.
If it is your NI USB-6210 that is connected directly to your computer, and you want to do analog to digital conversion at the NI USB-6210, then the startForeground / startBackground will communicate over the USB to tell the DAQ to do the sampling.
Communication over the USB is always digital, a packet of data; you cannot send a pulse through the USB port. Exactly what needs to be transferred to the NI USB-6210 to tell it to start collecting data is irrelevant: what-ever the protocol is, the DAQ will hide it from you.
The computer (running MATLAB) sends commands to the DAQ; the DAQ responds by configuring itself or by starting to record and transfer data to be transferred digitally over the USB to the computer.
addTriggerCondition has to do with something fairly different: it is for the situation where you do not always want to be recording input data, and instead want the recording to start only when a particular external condition is met, such as a voltage exceeding a certain value.
Ferz14
on 25 Jan 2016
So I create a session and use addAnalogInputChannel and then I use startBackground to start the operation. But, in this way, no sampling begins at the rising edge of the digital trigger. Where is the digital trigger? I don't understand.
Walter Roberson
on 25 Jan 2016
What part of the documentation for that device leads you to understand that you need to have the computer generate a pulse before the device will digitize?
Walter Roberson
on 25 Jan 2016
Why do you think you need a trigger? What document are you looking at?
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)