Re: Convert CSV File to WAV

>My Hantek signal generator only saves in CSV format. I would like to >covert this to WAV so it may be played back as an audio loop using one >of the commonly available Windows programs. > >Does anyone know how to do this "in house", eg. without resorting to a >specialized scripting language? > >There is an assortment of converters online (one selection below), but >none I can find that compiles the data into WAV format. > >
formatting link
> >It can be done, apprently, if you are proficient in Python. >Unfortunately, I am not. > >
formatting link
> >Arthur Brooks

I can think of a round-about way...

Play the CSV as a PWL file in LTspice and then write to a WAV, from the LTspice Help...

.WAVE -- Write Selected Nodes to a .Wav File. LTspice can write .wav audio files. These files can then be listened to or be used as the input of another simulation.

Syntax: .wave V(out) [V(out2) ...]

Example: .wave C:\output.wav 16 44.1K V(left) V(right)

is either a complete absolute path for the .wav file you wish to create or a relative path computed from the directory containing the simulation schematic or netlist. Double quotes may be used to specify a path containing spaces. is the number of sampling bits. The valid range is from 1 to 32 bits. is the number of samples to write per simulated second. The valid range is 1 to 4294967295 samples be second. The remainder of the syntax lists the nodes that you wish to save. Each node will be an independent channel in the .wav file. The number of channels may be as few as one or as many as 65535. It is possible to write a device current, e.g., Ib(Q1) as well as node voltage. The .wav analog to digital converter has a full scale range of -1 to +1 Volt or Amp.

Note that it is possible to write .wav files that cannot be played on your PC sound system because of the number of channels, sample rate or number of bits due to limitations of your PC's codec. But these .wav files may still be used in LTspice as input for another simulation. See the sections LTspice=>Circuit Elements=>V. Voltage Source and I. Current source for information on playing a .wav file into an LTspice simulation. If you want to play the .wav file on your PC sound card, keep in mind that the more popularly supported .wav file formats have

1 or 2 channels; 8 or 16 bits/channel; and a sample rate of 11025, 22050, or 44100 Hz.

...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| Phoenix, Arizona  85048    Skype: Contacts Only  |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 
              
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson
Loading thread data ...

No. Saying you have a CSV file is about like saying you have an Excel file; it allows you to reliably produce the same set of numbers, but it doesn't carry any information about what the numbers represent. You have to provide this knowledge to whatever program you use to convert the CSV file to something else. For widely-used CSV formats (maybe US Census data?) there are ready-made programs for it, but for all the other millions of CSV formats in the world, you get to roll your own.

For jobs like this, it usually works out better to implement the program in more of a scripting language (awk, Perl, Python, etc) instead of a real, official compiled language (FORTRAN, C, C++, etc). The scripting language will have built-in features for parsing the CSV file that you will take a long time for you to reimplement badly in an official compiled language. Also, the requirements are almost guaranteed to be poorly specified, which means more revisions of the code, which is usually easier with a scripting language.

A lot of these are probably wrappers around existing open-source libraries that they then charge you $17 to $80 for. Which would be OK if the perpetrators provided any end-user support in return, or supported further development of the underlying code, but they don't.

That looks like a reasonable approach, actually. It expects a CSV file with two columns: time and amplitude. It reads both values, discards the time (it seems to assume that the input data is sampled at 100 kHz), keeps the amplitudes in an array, normalizes the entire array, resamples to 44.1 kHz, and writes a 16-bit mono 44.1 kHz WAV file.

I am not sure what a couple of the fixed constants do, so this might die or do an incomplete job if you try to convert a really huge file (several dozen minutes maybe?), but for shorter files it should be fine.

On Linux you would save the contents of that github file to (say) hantek-csv-converter.py . Then you would put the CSV data in (say) hantek.csv in the same directory. Then, in that directory, do

chmod 755 hantek-csv-converter.py

./hantek-csv-converter.py hantek.csv

and after a bit, a new file named hantek.wav should appear in the same directory.

On Windows you need to install Python for Windows first, which exists. If the installer asks you about configuring it to run Python scripts from the command line, say yes. Save the contents of that github file to (say) hantek-csv-converter.py . Then you would put the CSV data in (say) hantek.csv in the same directory. Then, in a cmd.exe window, navigate to that directory, and do

python hantek-csv-converter.py hantek.csv

and after a bit, a new file named hantek.wav should appear in the same directory.

If the only thing that will do is a single .exe with a nice happy clicky interface, you'll probably either need to get it from Hantek or pay to have one written. It will probably be cheaper to buy a different signal generator that saves files in a reasonable format than to buy a custom- written program.

Matt Roberds

Reply to
mroberds

CSV, as it comes out of the Hantek will be of the form of PAIRS...

time, voltage

which is the exact same format as a Spice PWL file.

So it is quite trivial to add nodes and the text PWL...

v1 1 2 PWL (0,1) (1.2,5) (1.4,2) (2,4) (3,1)

Most spices will accept the list-style format...

v1 1 2 PWL

  • (0,1)
  • (1.2,5)
  • (1.4,2)
  • (2,4)
  • (3,1)

So the most work will be in adding the "+" continuation to the CSV as it comes straight out of Excel... easier to do with an editor such as UltraEdit with macro capability.

I go back and forth all the time from PSpice to Excel to PSpice producing PWL's or processing .DAT files from PSpice Probe. ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| Phoenix, Arizona  85048    Skype: Contacts Only  |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 
              
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

I've done the reverse with sox, i.e. wave to data. The webpage says it can take data to wav, but I doubt you will be doing this without minimal scripting or a simple program. Sox can't anticipate every data format.

The C programs I've thrown together for reformatting data are less than a hundred lines. It isn't a major project.

Reply to
miso

For anyone who is interested, I found tbis free arb gen software that saves in several formats including WAV.

formatting link

Arthur Brooks

Reply to
abrooks

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.