Output simulation signal to *.wav file?

Just upgraded from 8.x to 9.0.1 and boy! After ages of trying to debug simulation issues with the error message of “Timestep too small” that I just could not track down I’m finally able to plot the full output of a drum voice I’m working on:

I think the visual cues for what’s excluded from simulation might have helped me here but I also think something has just started working that wasn’t before. All spice models are the same as before.

Anyway, thank you so much for making KiCad better each day!

And to the question, is there an established way to output the plot of an output like this into a wave file that I could actually listen to? I’m staring at this sound wave and I deeply want to listen to it :slight_smile:

I see that I could plot it to a csv and go that route, but figured I should ask about it?

Others here have more experience with ngSpice then I do…

The Time step too small is a “catch all” error message from ngSpice. When a simulation does not converge (for whatever reason) ngSpice attempts to decrease the time step, and it continues doing so untill it reaches some limit and gives up. So the timestep itself is never the reason. You could argue the message is misleading, or at least could be improved :slight_smile:

I am certain ngSpice can read a wav file for simulation input, so I assume it can also output data to a wav file. To be certain, read the ngSpice manual on the sourceforge website. KiCad cooperates with ngSpice, but the ngspice project has it’s own website and documentation.

I’ve found

Escpecially this part seems interesting and very much like what I want:

I tried toying with similar text fields to trigger those nspice special commands but seems its still not merged yet to the main ngspice version, at least not in that form:

sndparam: no such command available in ngspice
sndprint: no such command available in ngspice

So i guess next up is trying to build ngspice from that PR possibly? But I can’t even find how I use a special ngspice command from KiCad?

I’ve started trying to script the csv output to a *.wav file but the sample time scale doesn’t look linear:

time;V(Output);V(TrigIn);
0;1.30592;0;
2e-11;1.30592;0;
4e-11;1.30592;0;
8e-11;1.30592;0;
1.6e-10;1.30592;0;
3.2e-10;1.30592;0;
6.4e-10;1.30592;0;
1.28e-09;1.30592;0;
2e-09;1.30592;0;
2.128e-09;1.30592;0.32;
2.384e-09;1.30592;0.96;
2.896e-09;1.30592;2.24;
3.60593e-09;1.30592;4.01482;
4e-09;1.30592;5;
4.14199e-09;1.30592;5;
4.42596e-09;1.30592;5;
4.9939e-09;1.30592;5;
6.12979e-09;1.30592;5;
8.40156e-09;1.30592;5;
1.29451e-08;1.30592;5;
1.94395e-08;1.30592;5;

I’m really new to this and thought I could use 1 / 44100s steps in the spice cmd settings here

to get a 44.1 kHz sample rate :slight_smile: But I realize now that timestep is just some initial step length and that the engine would zoom the timesteps in for convergence just as described for the *timestep to low" issue. I just thought the output would probably still be linear.

Gonna be more work :slight_smile: I guess, but just interpolating linearly for the target sample rate between the actual sample points in the output would be fine…?

There is a ngspice git branch at ngspice / ngspice / Commit [276c4f] with current ngspice-44.2 enhanced by reading and writing wav files. This features the sndparam and sndprint commands.

For Windows users there is a compiled executable (standard ngspice and shared ngspice) available at Ngspice, the open source Spice circuit simulator - Downloads (ngspice nightly and others).

Some of your questions are answered by the image you have posted:

Add a sequence of commands to ngspice by putting them into a

.control 
<command1>
<command2>
.endc

section onto the Eeschema canvas. Don’t forget to give set controlswait if the commands are to be executed only after the simulation has finished.

For linearizing the samples, use the linearize command.

See the ngspice manual (Ngspice, the open source Spice circuit simulator - Documentation: manual and control flow) for details.

2 Likes