Discussion:
How to generate .wav files from sound pressure data
(too old to reply)
Gurdas
2006-03-03 16:10:42 UTC
Permalink
Hi,
 
I have sound pressure data (as dB values) vs frequency data.
How can I create a playable .wav file based on above?
 
Note: I do NOT have sound pressure vs time data
 
I am working in LV 7.1 FDS on Win2000.
If really required, I can incorporate VIs from sound and vibration toolkit (version 1.0).
However, I would prefer a solution that does not need me to do that.
 
Thanks in anticipation,
Gurdas
David H
2006-03-07 04:10:47 UTC
Permalink
Gurdas,
You are right in what you are trying to do can probably be done without the sound and vibration toolkit.  In general, that toolit is geared towards analyzing signals, not producing them.  However, I think what you are trying to do can be done with some of LabVIEW's analysis VI's.
One specific VI that might be helpful is the Inverse FFT VI.  This VI takes an array of complex FFT data and returns an array of the actual values that would produce such results.  In general, when you take an FFT of a signal in the time domain, your result will be an array of amplitudes in the frequency domain (dB vs frequency).  However, we typically only think about the real values associated with this calculation.  The often forgotten part is that taking an FFT also gives us phase information as well, in the form of complex data.  Thus, while we normally view the "real" data, there is a forgotten complex side of an FFT graph that tells us phase information.  My point here is that this might be helpful when reconstructing an actual signal from your dB vs Frequency array. 
Another option is to simply create a set of sine waves for every frequency specified by your dB vs Frequency array.  In such case, you would create an individual sine wave for each frequency in the array, and the ampltude of that sine wave would be determined by the power (dB) at that frequency.  You would then add all sine waves together and divide by the total Peak-to-Peak to normalize the graph.  I'm not completely that sure that this would work entirely in that taking an FFT of the "created" signal would be the same as the original plot.  However, it is certainly worth a try. 
 
Anyway, these are just a few ideas of how you could create a signal based on your original dB versus frequency graph.  Once the actual signal has been created in LabVIEW, writing it as a sound file can be done with some of the sound VI's.  I hope this helps and let me know if you have any further questions!
 
Regards,
David Hall | Applications Engineering | National Instruments
Gurdas
2006-03-08 14:41:08 UTC
Permalink
Dear David,
Thanks for replying.
Kindly refer to attached screen shot of my code.
Heres what I am doing:1) Reading Freq. and dB values from a file2) Doing an Inv FFT on the dB values3) Decimating the output from Inv FFT so that it comes close to 44.1Khz (because my original time data sampling was at 75.59 Khz). Do I need to do this?4) Convert decimated array to U16 data type and play it.
What I get is trash sound (very sharp and noisy) which is unlike what is expected.
My questions:
1) Do I need to have "replay sampling rate" exactly same as original time data sampling rate? If yes, how can I convert my 75.59Khz data to say 44.10 KHz?
2) Am I making some mistake in my code? I have not used the Freq. data and this makes me uncomfortable.
Thanks,Gurdas.


Code_screenshot.jpg:
Loading Image...
Justin M.
2006-03-10 06:10:40 UTC
Permalink
Could you post an example of the data file you are using as input?  Also, have you looked at the waveform you are sending to the sound write VI?  You would want to send in a smooth, continuous waveform.  Do you have an expected output that you could compare it to?
-Justin
Gurdas
2006-03-10 09:12:57 UTC
Permalink
All,
 
With some help from NI-India, we managed to build a nice sound player and .wav saving utility.
 
I have attached the VI sent by NI-India. The key component which was missing in my VI was "resample waveform".
Note: For some reason, I could not use the attached VI to generate sound but did use the concept to succesfully read my sound pressure data and output it to the speaker (and also save it as .wav file tha can be played on Windows Media Player). Also note that I am now generating sound from sound pressure vs time data. I have not tried generating sound from sound pressure vs frequency data.
 
I would love to have the following answered:
 
1) What data does the sound write VI expect? Is it Sound Pressure values? What units (N/m2 or dB or dBA)? I think it expects sound pressure data and the units are not relevant. Reason being my next question.
 
2) I found that until I mutliply the sound pressure data by a very large number say 10e7, the sound is hardly audible (even when volume was programmatically set to max. i.e. 65535). The sound QUALITY does not change when I change this multiplier.
      2.a) Does that mean its only the relative difference between wave data points that affects sound quality? If yes, then I believe the sound pressure data can be in any units.
      2.b) Is it expected to use this huge multiplier OR did I do something without really knowing what it meant?
 
 
Thanks,
Gurdas
 
 


Sound from FFT (LV 8).vi:
http://forums.ni.com/attachments/ni/170/172818/1/Sound from FFT (LV 8).vi
Gurdas
2006-03-14 08:42:52 UTC
Permalink
Dear Sulzer,
Thanks for the input. I shall checkout what is available out there.
However, I am also happy with minimalistic "copyright" information going into the .wav file and would be glad if this can be done in a simple and easy manner. Let me rephrase my requirement.
I would like to display some string (such as song name in song files) that comesup when my .wav file is played. I have seen this in .mp3 files. How about .wav files?
I do NOT need any digital signatures.
One method (though quite naive) is to insert an audio announcement into the file! But I guess this might act as an irritant because it will play everytime the file plays.
Let me know your thoughts.
- Gurdas
Gurdas
2006-03-14 11:43:10 UTC
Permalink
Hi GerdW,
Thanks. I checked the link and had only more questions at the end!!
I am able to write .wav files from the standard LV functions. I have never worked with audio formats before and might be unabe to understand even 'simple' ideas (so pls elaborate on your solution).
1) Is the Label chunk the right place to hold my company name?
2) Will the label chunk get displayed each time the file is played?
3) If answer to both of the above is 'yes', then, how do I write to the label chunk in LV?
 
Best rgds,
Gurdas
GerdW
2006-03-14 12:43:23 UTC
Permalink
Hello Gurdas,

1+2) It depends on the player you use. If the player is displaying
those data you can use this chunk. And the player will probably display
the text each time it plays the wav.

3) How to write: Have a look at an wav file with a hex viewer/editor.
So you easily can recognize the pattern: You have a type identifier
("chunk label"), followed by the size of the chunk (intel format, U32),
followed by chunk data. To append a chunk: open wav file, append new
chunk data to file, readjust file size.
Filesize is stored in byte 4-7 of a wave file, following the identifier
RIFF (also Intel format; contains "data to follow" that is actual
filesize-8 (RIFFxxxx)).
A wav file contains of:
RIFF   -   indentifier
xxxx   -   filesize-8
while (chunks)
  chunk type   -    identifier (like data, fact, labl)
  chunk size   -   size in bytes
  chunk data   -   data bytes
wend
That's what I mean easy to implement :-)

Loading...