C Programming / Maybe WAV Source

Hello Mike & QSpice Team.

I’m really liking QSpice so far. The ability to insert native C/C++ code is a brilliant feature.

I’m thinking to add a unit to allow using a WAV file (or likely any audio format) as a source. Other than finding a library to open/parse the audio file, it seems simple enough. (Famous last words that I’ve regretted often.)

As a first pass, I simply created a block with an input port (clock) and output port (the voltage corresponding to the sample voltage at that clock cycle). However, this approach will require hardcoding the source file name and sample bitrate. I’d like to make those bits more flexible.

So, I have questions:

(1) Can a string parameter (in a .param statement or as an attribute) be passed to the C DLL at runtime (i.e., the user-supplied audio filename)?

(2) Same for an integer value (i.e., the user-supplied bitrate)?

At this point, I have the clock input driven by a pulse source at (twice) the bitrate. I’m assuming – perhaps incorrectly – that the DLL code will be called at least at every clock transition.

It might be better to have the DLL get the bitrate from the file parsing library. How could I pass that back to QSpice and have that used by the clock source?

Or is there a better way, maybe using the min/max time block that is available in the advanced settings when generating the code template? If so, does the DLL have access to the elapsed simulation time when called?

Thanks again for making such a promising tool.

Strings are supported yet, but will be, in the interest of being able to load ROM.

But the code compiles fast enough that for now, you can just put the file name in the .DLL and recompile when you want to change audio source files.


Thanks, Mike. I won’t chase my tail over passing strings. Looking forward to that addition.

Meantime, I’ve divined how to pass/capture numeric attributes. I’ll post some code examples as I figure more stuff out and, hopefully, not distract you further from working on the simulator.


wow, very cool. I look forward to seeing this in action.

some thoughts…

  1. you could convert ASCII of the file name to numbers, then pass one or more numbers, or pack into a 32bit integer value.

  2. you could read parameters from an ASCII config INI file, containing file name, time offset, …