Home | Audio Magazine | Stereo Review magazine | Good Sound | Troubleshooting Departments | Features | ADs | Equipment | Music/Recordings | History |
By Leonard Feldman [This all-in-one program handles nine common audio calculations, faster than a scientific calculator and with no need to remember which formula lurks behind which calculator button. Written in Microsoft BASIC, it can be modified easily for other BASICs. ] I have finally succumbed! After resisting the temptation to get involved with computers for several years, I finally admitted to myself that I'd better learn a little about computers or be left out in the cold. So, after much agonizing and mind-changing about what to buy, I ended up with a dual disc-drive, CP/M-based unit equipped with a 9-inch CRT, 64K of RAM, and lots of ready-to-run software. (See how quickly I'm learning the jargon?) Actually, this is my second computer. The first cost only $100 and was used primarily as a learning tool on which to do homework as I took a couple of courses in elementary (and then not so elementary) programming. Not content with just the computer package as it came, I also decided to purchase some "peripherals," as they say in the computer game. To start with, I bought a good-quality dot-matrix printer and a modem, for future communications with publishers who can accept manuscripts by wire (Editor's Note: Including Audio, eventually), and for accessing those data bases that I keep seeing advertised everywhere. After getting all this stuff home, I quickly discovered that, compared with computer and software manuals, audio equipment manuals are veritable masterpieces of lucidly clear prose. The ones I got with certain of my software discs were written by and for computer scientists with at least two (and possibly more) Ph.D. degrees in the subject. Since I don't even possess one such degree, I hurried out to my local library and then to my not-so local bookstore to purchase a somewhat more decipherable book on CP/M (the operating system of my computer). After several frustrating weeks of effort, I had gotten to the point where I could begin to do some elementary programming on my fancy computer--albeit in BASIC, which I am told is not the most efficient or fastest language to use. Nonetheless, it is a language I now understand how to "speak" and use, and it's also the language built into most lower cost computers, especially those which don't use disc drives like mine but which store programs on cassette tapes. I suspect that there are thousands of you out there who, after following pretty much the same course that I did, suddenly are faced with the question of what to do with the new home computer. To be sure, I thought, the software supplied with it would be great for creating an inventory of everything I possess, for filing names and addresses of all my friends and relatives, for creating "what if" business spreadsheets and more. If I become proficient enough, I may even be able to save some time in calculating my income taxes once a year with this dandy machine. But surely, I figured, there must be some tasks associated with my daily work that can be eased with the aid of this not inexpensive adult toy. Back to the library again, and to the book shops, to discover that there are any number of great (and elaborate) programs written for electronic circuit designers. There are complex pro grams for Fast Fourier Transform analysis of transient pulses (great for measuring speaker frequency response in non-anechoic environments). I ran across a program (actually a fairly simple one) for calculating the optimum speaker cabinet enclosure, given certain parameters of the driver to be used, all based on the famous Thiele/ Small equations. Unfortunately, while these programs are certainly well conceived, they are of little use to me, since I haven't been involved in the design of speakers or audio electronics for some years. [Nothing is as unforgiving of typos or incorrect punctuation as a computer, so the program listing is a reproduction of the original printout. All parts should work-if you enter it correctly. ] Most y, my job is to measure performance. To do that, I use relatively few formulas which, until recently, were all stored in my Hewlett-Packard printing/ programmable calculator. The problem had always been the slow speed with which the H-P executed those programs, and the fact that I could never remember which code number applied to which program without looking at a scrap of paper I had pasted to the back cover of the calculator. When you have to convert a bunch of voltage readings to power across a known impedance, or a bunch of microvolt signal levels to dBf, all of that can become pretty tedious and time-consuming. So, I. decided that my first use of my new computing power would be to create an all-in-one program to take care of my daily (if simple) electrical calculations in the lab. As the program became more and more refined, I became so excited about it that I decided to share it with readers of Audio-with no license or royalty fees expected. Before we get to the program itself, let me state up front that I'm certain there are a bunch of computer freaks out there who will be tempted to write and tell me that I wasted a lot of memory and could have written the program in a much more sophisticated manner. My answer to them is, "The program works!" and is simple enough for any neophyte (such as myself) to understand and use. There'll be time for fancier programs later, I'm sure. The Program Figure 1 is a copy of the "menu" that appears on my CRT when I call for the program to be run. Basically, it gives me a choice of nine calculations which I have to make practically every time I work at the lab bench on audio equipment. You select which calculation you need by typing in the appropriate numeral (1 through 9). If you type in a zero (meaning that you've changed your mind and don't want to do any audio calculations after all), the program ends with a courteous message. If you try to outsmart the computer and type a number greater than 9, the computer simply questions your entry and waits for you to stop fooling around and enter a legal number. Figure 2 is what appears on my printer (and on the CRT of my computer) when I run programs 1 through 9. (I added the numerals at the left of each program run later, just to identify the program. They will not appear in your printout or on your CRT.) After each calculation has been completed, the program asks the user if he or she wishes to return to the menu. Typing the letter "y" (for "yes"), in lower case letters, causes the menu of Fig. 1 to reappear on the screen. You are now ready to have the computer do another calculation-either the same type, or a new type if you now select another number. After you are through using the program, when the computer asks you if you want to return to the menu, you simply type a lower case "n" (for "no"). This terminates the program, and the message "Happy to have been of service! SEE YOU LATER!!" appears on your screen (and, if you have a printer connected, prints out as well). Pretty neat, eh? Actually, I wrote two versions of the program. The one published here, as Fig. 3, is intended for use with a system that also has a printer hooked up to the computer. A simpler one omits all the printing steps; I use it in the lab when it isn't important to make a hard copy of all the calculations and their results. If your computer has no printer, all you have to do when you type in the program is to omit every step that begins with the word LPRINT. That's the BASIC command for most computers that sends whatever follows to your line printer. For example, if you don't own a printer or don't want the program to send data to your printer, you would omit lines 340, 360, 390, 400, 430, etc. Should you elect to omit the LPRINT lines, I would suggest that you not renumber all the other lines in the program, but keep the number order shown in Fig. 3. That way, if you do run into problems and the program needs debugging, your computer will refer to "problem" lines using the same numbers appearing in Fig. 3-and you'll have an easier time finding your typing or syntax mistakes. Not All BASICs are Identical Unlike audio equipment, which is almost always completely compatible with other audio equipment, there are differences between computers and even between the versions of the BASIC language which they understand. Not all computer keyboards are alike either. As a result, you may find that some of the numbered command lines shown in the complete program of Fig. 3 cannot be entered as written on your particular computer. Or, in some cases, if they can be entered as shown, they won't run properly and the program will "hang up" at a given line. The BASIC language that I use on my computer is known as Microsoft BASIC, and it's one of the more popular versions of BASIC around. Still, here are some possible keyboard problems you may encounter in trying to type in and run the program. In line 270 I used the BASIC command "ON GOTO ###, ###, ###, etc." where " " represents a variable (in this case, C) and the "###s" represent line numbers. There are a few computers which do not recognize this useful command. If yours does not, you can substitute the following individual line numbers: 270 IF C =1 GOTO 290 271 IF C=2 GOTO 420 272 IF C=3 GOTO 550 273 IF C=.4 GOTO 680 274 IF C=5 GOTO 810 275 IF C=6 GOTO 900 276 IF C = 7 GOTO 990 277 IF C=8 GOTO 1110 278 IF C=9 GOTO 1220 That will use up a tiny bit more computer memory, but the program will work just as well. With all of the above command lines, as well as in lines 260 and 280, some computers will require the word "THEN" with the "IF" command. In such computers, these lines would have to be written, to give an example, as: 260 IF C = 0 THEN GOTO 1430, etc. In line 370, an upward-pointing arrow stands for exponent-in other words, P=V raised to the second power divided by R. Some computers use a double asterisk (a') to denote exponents, instead of the upward-pointing arrow. For such computers, line 370 would read: 370 LET P = V**2/R. Incidentally, many forms of BASIC (including mine) do not require the word "LET" when setting up a variable or an equation. Because so many others do, however, I have chosen to include the word "LET" in all lines involving variable identification or equation defining. ============ THE PROGRAM Fig. 3--Complete listing of the nine-part audio lab program. If you don't need a printout of the program runs, program length can be reduced by omitting all "LPRINT" lines. ============ If you are familiar with the various formulas involving decibel (dB) calculations, you may be wondering why, in lines 630 and 760, for example, it is necessary to divide the logarithm expression by the logarithm of 10. That's because, while most computers using BASIC are able to calculate logarithms, they only "know" natural logarithms-those that use the base "e" (2.30259). Since decibel calculations all require the use of logarithms to the base 10, it is necessary to divide the log expression in these equations by the natural log of 10. Most authors (or at least this one) aren't too careful about punctuation. After all, isn't that what good editors are for? (Editor's Note: Well, ... I.B.) The first thing I learned about programming is that there is nothing as unforgiving of incorrect punctuation as a home computer. The program in Fig. 3 has been reproduced from my original printout, so its "syntax" is correct and all parts of the program will work. If you leave out a semicolon, or a quotation mark, or even a space, the computer will mess things up and, of course, we always blame the computer. If you find this sort of program useful, let us know, and perhaps when I become more proficient I can create a few more useful audio programs that may be of interest to you. By the same token, if you have come up with a program or two that you think might be useful to me (or to other readers of Audio), perhaps you'd like to share them with us. ============= (Audio magazine, Nov. 1983) Also see: Computer-Aided Filter Design (Nov. 1983) Time Delay Spectrometry (TDS) Computing (Nov. 1983) The Computer in Sound System Design (Aug. 1970)
|
|