7

First of all i have to say that i’m far from being pro at music/audio and i’m not an electronic engineer neither, but i like music and electronics so i thought it could be fun to mix them together and play around.

The tool i’m using for testing/understanding the designs is LTspice, the reason is because it’s freeware, easy to use and powerful. The only problem is that it’s just distributed for windows, but thanks to opensource gods it runs more than perfect on wine. That means if you’re MacOSX user or Linux user, just install wine and run LTspice installator within wine:

wine LTspiceIV.exe

LTspice is a software for simulating electronic circuits without the need of building and testing them in real life. This software runs on top of the powerful spice electronics simulation engine, it helps us to use it in a more confortable way and in case we need advanced features that aren’t present on the GUI, it’s always possible to insert spice commands in our designs.

Note that real components are going to behave close to, but not exacly as, the simulated ones, however we can get a whole bunch of virtual components for free, so who’s gonna complain?

LTspice lets us use wav audio files as input for our circuits, that’s a great feature for our proupose. Let’s take your guitar, plug in to your machine and record some clean riffs to start working, or as an alternative pick a free wav over the internet. I’ll use this one: http://guitar-wav.com/Riff41.wav obtained from http://guitar-wav.com/riffs5.html and copyright guitar-wav.com.

Ok, now that we have some music to mess with, we need to make it available to our electronic design, so launch ltspice and click on the New Schematic option from the File menu. Once we get our fancy new schematic created, we add a new component by clicking on the new component icon on the toolbar:

1

 

On the component window write “voltage” and press enter:

2

 

Now place the voltage component on the schematic. Make sure you have the Riff41.wav file on the same directory of the saved schematic file. Click on the v letter next to the voltage component and substitute the v on the textbox with this string:

wavefile=.\Riff41.wav chan=0

3

 

That’s all we have to do in order to include an audio file into our designs for simulation, isn’t that hard, right? Well, now we have to tell ltspice to simulate and we’ll see how this guitar sound looks like. Go to the simulate menu, Edit Simulation Cmd option. Now on the Transient tab we’re entering for how many seconds we want to simulate, i wrote .5 indicating half second simulation, then click ok and place the simulation string somewere on your schematic.

4

 

Now we can click on Run, that’s the running man on the toolbar. It keeps on doing it’s calculations for a second and when it ends simulating we get a black empty window over our design. To see what we want we have to click with the probe curor on the positive node of our voltage component, and automagically we see the sound.

5

 

We are going to make a volume control. First with static resistors to see how it works, but on a final design you could substitute it by a potentiometer (variable resistor) to control volume in realtime.

Now place a couple of resistors from the toolbar and right click them to give a value of 100 (ohms) for both, add a label from the toolbar, between the two resistors, with the string “out”. Go to Simulation, Edit Simulation Cmd and tell it to simulate for 10 seconds (Riff41.wav is 10s long). You shoud end with something like this:6

Click on the running guy, and when the simulation ends, click with the probe first on the positive terminal like before, and second on the out label, this way we can compare the input and the output of our circuit. As you can see it’s a voltage divider . In this case the output is 0.5 times the input, or -6 dBV. (check this good explanation about dB)

7

 

What if we change the value of R1 to 27k (ohm) that could be the value for our volume potentiometer.

Change it and simulate again. Yes, we see no difference with the input signal, that’s 1 times the input or 0dBV (full volume).

An important note here is that the human ear does not feel volume in a linear manner, it feels changes in a logaritmic manner, that’s why volume is measured in dB (logaritmic ratio) and volume potentiometers must be of logaritmic type, otherwise you’ll get a strange feeling when decreasing or increasing the volume.

Now, seeing the signal is an important tool to see how behaves the electronics, but what if we want to hear the results? That’s what music is all about, hearing and feeling it! Right, so let’s save the output signal to a wav file.

Insert a spice directive ( last button on the right of the toolbar) containing this string:

.wave .\out.wav 8 11025 V(out)

That means save a wave file named out.wav in the current directory made of 8 bit samples at a 11025 samples per second. That’s same quality as the input file has. Now you’ll see that saving the output with the 2 resistors having the same value, the output signal is 0.5 times the input, being -6dB. If you hear that output you’ll see that you hardly appreciate the volume reduction, that’s because of the non linearity of our ear, so edit the output resistor value to be 10 times lower than R2, this way we’ll get 0.1 times the input or -20dB. Let’s save it again and play it, now we see a volume decrease, we’re on the correct way :) My final schematic looks like this:

8

 

Now when you click on the Run button you’ll get a out.wav file.

Hope you liked it, next post will be an intro to filtering and frequency response, stay tunned!

2 thoughts on “Electronics & Audio 1

  1. Hello,
    I saw you explanation of using wav files as source for LTSpice.
    Very nice job, thank you for that.
    I have testet it with your “Riff41” file. It works.
    But I have tried to export one of my riffs from Logic and these files are not working.
    Do you know the settings you have used for the export?

    Greets from Germany
    Marinus

  2. Hi Marinus!

    Yes, it’s explained in the post! Let me resume it for you :)

    1: Add a label from the toolbar, between the two resistors, with the string “out”.
    2: Edit Simulation Cmd and tell it to simulate for 10 seconds (Riff41.wav is 10s long).
    3: Insert a spice directive ( last button on the right of the toolbar) containing this string (Without the quotes!!): “.wave .\out.wav 8 11025 V(out)” .
    4: Check that it looks like the Image of the post.
    5: click on the Run button you’ll get a out.wav file!

    Hope it helps!

    Greets from Barcelona
    Noel

Leave a Reply

Your email address will not be published. Required fields are marked *