This is a first pass at a component to read *.wav files. Works but not yet perfect.
The forum doesn’t allow attaching *.cpp and *.h (and *.qsch) files. So I appended “.txt” to the file names to work around this limitation.
This doesn’t work for *.qsch presumably due to some non-plaintext characters in the *.qsch file. The component/schematic is pretty simple to create – just a single output port named Out of type float (64-bit double). Looks like this:
I just added the ability to pass a string to a .DLL device. So you can pass a path to a .DLL, have it read the .wav file, and then play it into the simulation.
FWIW, I also tried bool loop=false & bool loop=0. Those also didn’t get included in the code although present in the netlist. Also tried exiting/restarting QSpice. No joy.
Oh, it was only working if the char * parameter was the last attribute. But I changed it as of the current update so that you can put “int loop=1 bool done=false” after the char * parameter.
But you will have to regenerate the C++ template with the right click C++ => Create C++ Template command.
Looks like the code generation issue is fixed. Will roll it into my code and let you know if there are more problems. I don’t expect any.
While it’s not your issue to solve or a proper topic for this thread, the QSpice update process is horribly broken. I’ll post about that separately. Just had to vent.
OK, I think that I have the WavSrc component functionally complete. Here’s what it does:
Reads a *.wav file with single or dual channels. Currently only basic 16-bit PCM-encoded files are supported. (Probably won’t add more formats.) If only one channel is present, it simply duplicates the data on the second output.
File is specified with an attribute. Seems to honor path bits properly.
Has a gain attribute to apply to the nominal 1.0Vp input values.
Has a Vref input which is sets the 0V reference. It could be a DC offset or , in theory, be used to modulate the wav outputs.
Has a loops attribute to specify how many times the input file is read/processed,
I’m running into a strange issue. I generated a very simple .wav file. (1KHz for 100ms at 1Vpp).
However, if a place a 1 ohm resistor to GND on the output, the output Voltage is 1mVpp.
If I change the resistor to GND to 1Gohms. I get the 1Vpp of the .wav file.
I’m getting use to the C++ interface and your original .cpp code. However, I hadn’t detected the effect of a series resistance in your code.
Len
UPDATE!!!
I just found the ROUT=1000 ohm default output setting in the Symbol Text help info. Once I change ROUT = 1f, I get my expected 1Vpp results.
Note that, after I learn a bit more about GitHub, I’ll likely move the project to a different repository with better organization. In other words, the link won’t likely be active forever…
Let me know what works, doesn’t work, etc. TIA.
Edit: I’m struggling with trying to get the code rolled into a symbol. Seems like it should be simple but passing in parameters (i.e., filename, loops, gain) from the symbol dropped into a schematic to the underlying stuff is eluding me. Feel free to beat me to that, share, and be my hero.
Are you planning to create the compliment feature, outputting a WAV file from a QSPICE signal? I used that feature in LTspice to simulate the stereo output of the ShortSniffer during the development phase. The hardware prototype performed in a similar fashion, sounding just like the simulation!
I looked at the C++ code and realized that I’m not the guy to do the job. I’m an Analog Guy with minimal code hacking abilities (BASIC and assembly from TRS-80 and early PCs). Maybe somebody else will get excited about the challenge . . .
Thanks for what you are doing.
Carl