'This Q-Basic file will read a *.txt file generated by "Cool Edit" 'and convert it into the PSpice VPWL_File format which controls the '"VPWL_File" voltage source symbol in PSpice. This provides a means 'where audio files from cool edit can be displayed/manipulated using 'PSpice's PROBE application. By D.J. Mehrl, 1/2/98. 'note-a fix was added to fix a convergence problem when 2-successive 'time values(using only 4 significant digits) were identical -1/2/98 WSPC$ = CHR$(9) 'white space character CLS PRINT "This quick_basic program will read in a Cool Edit " PRINT "(*.txt) audio file and save it in a form compatible" PRINT "with the PSpice VPWL Piecewise-Linear file-controlled" PRINT "voltage source. For mono files, the (1) output file should" PRINT "be named right.pwl, and for stereo files the (2) output files" PRINT "will be named left.pwl and right.pwl ." INPUT "Hit after you have read this and are ready to continue"; a$ CLS myloop1: INPUT "File Name of (*.txt) Cool Edit data file to be converted"; myfin$ m1 = INSTR(myfin$, "."): m2 = LEN(myfin$): mypath$ = LEFT$(myfin$, m1 - 1) myext$ = RIGHT$(myfin$, m2 - m1 + 1): myext$ = LCASE$(myext$) myerr1$ = "ERROR - input file does not have the .txt extension" myerr2$ = "TRY AGAIN!" IF myext$ <> ".txt" THEN PRINT myerr1$: PRINT myerr2$: PRINT " ": GOTO myloop1 OPEN myfin$ FOR INPUT AS #1 LINE INPUT #1, a$ m1 = INSTR(a$, CHR$(9)) 'search for the tab delimiter character m2 = LEN(a$) 'find the overall string length b$ = RIGHT$(a$, m2 - m1): nsamp = VAL(b$) 'find number of samples LINE INPUT #1, a$ m1 = INSTR(a$, CHR$(9)) 'search for the tab delimiter character m2 = LEN(a$) 'find the number of bits per sample b$ = RIGHT$(a$, m2 - m1): mybits = VAL(b$) LINE INPUT #1, a$ b$ = RIGHT$(a$, 1): nochan = VAL(b$) LINE INPUT #1, a$ m1 = INSTR(a$, CHR$(9)) 'search for the tab delimiter character m2 = LEN(a$) 'find the sampling rate (Hz) b$ = RIGHT$(a$, m2 - m1): srate = VAL(b$) LINE INPUT #1, a$ m1 = INSTR(a$, CHR$(9)) 'search for the tab delimiter character m2 = LEN(a$) 'find the NORMALIZED (True or False) parameter b$ = RIGHT$(a$, m2 - m1): norm$ = b$ 'Print results to screen. PRINT "Extracted Input File Parameters:" PRINT " " PRINT "Number of Samples = "; nsamp PRINT "Number of bits/sample = "; mybits PRINT "Number of channels (1=mono, 2=stereo) = "; nochan PRINT "Sampling rate (Hz) = "; srate PRINT "NORMALIZED VALUES = "; norm$ mytime = nsamp / srate PRINT "Calculated total sampling time interval = "; mytime; " (secs)" 'nsamp = 10 'FOR DEBUG ONLY - COMMENT THIS OUT LATER!!! smax = 2 ^ (mybits - 1) 'a normalization value CLS IF nochan = 1 THEN PRINT " " mymlft$ = "left.pwl" PRINT "Mono Output file will be named as "; mymlft$ PRINT "Enter a new path/filename if you do not like this default" INPUT "Otherwise just hit to take default"; a$ IF a$ <> "" THEN mymlft$ = a$ END IF IF nochan = 2 THEN CLS myslft$ = "left.pwl" mysrgt$ = "right.pwl" PRINT "Stereo Output files will be named as "; myslft$ PRINT "and "; mysrgt$ PRINT " " PRINT "Enter a new path/filename for left channel path/filename if" PRINT "you do not like this default" INPUT "Otherwise just hit to take default"; a$ IF a$ <> "" THEN myslft$ = a$ PRINT "Enter a new path/filename for right channel path/filename if" PRINT "you do not like this default" INPUT "Otherwise just hit to take default"; a$ IF a$ <> "" THEN mysrgt$ = a$ END IF IF nochan = 1 THEN OPEN mymlft$ FOR OUTPUT AS #2 FOR ii = 1 TO nsamp LINE INPUT #1, a$ 'read in data values chan1 = VAL(a$) / smax 'normalize the values to +/- 1 volt. myout$ = STR$(chan1) myout$ = LTRIM$(RTRIM$(myout$)) 'trim any leading/trailing spaces 'try to print out fewer significant digits to reduce file size nsdig = 4 'desired number of significant digits rgt$ = "": IF INSTR(myout$, "E") <> 0 THEN rgt$ = RIGHT$(myout$, 4) mydec = 0: IF INSTR(myout$, ".") <> 0 THEN mydec = 1 'see if there's a decimal point spos = 0: IF LEFT$(myout$, 1) = "-" THEN spos = 1 'see if it is a negative number myout$ = LEFT$(myout$, spos + nsdig + mydec) + rgt$ mytime = (ii - 1) / srate: mytim$ = STR$(mytime) mytim$ = LTRIM$(RTRIM$(mytim$)) 'trim any leading/trailing spaces 'try to print out fewer significant digits to reduce file size nsdig = 6 'desired number of significant digits rgt$ = "": IF INSTR(mytim$, "E") <> 0 THEN rgt$ = RIGHT$(mytim$, 4) mydec = 0: IF INSTR(mytim$, ".") <> 0 THEN mydec = 1 'see if there's a decimal point spos = 0: IF LEFT$(mytim$, 1) = "-" THEN spos = 1 'see if it is a negative number mytim$ = LEFT$(mytim$, spos + nsdig + mydec) + rgt$ PRINT #2, mytim$; WSPC$; myout$ 'PRINT mytim$; WSPC$; myout$ 'for DEBUG ONLY --COMMENT THIS OUT LATER NEXT ii CLOSE #1 CLOSE #2 END IF IF nochan = 2 THEN OPEN myslft$ FOR OUTPUT AS #2 OPEN mysrgt$ FOR OUTPUT AS #3 FOR ii = 1 TO nsamp LINE INPUT #1, a$ 'read in data values m1 = INSTR(a$, CHR$(9)) 'search for the tab delimiter character m2 = LEN(a$) b1$ = LEFT$(a$, m1 - 1): chan1 = VAL(b1$) / smax b2$ = RIGHT$(a$, m2 - m1): chan2 = VAL(b2$) / smax myout1$ = STR$(chan1) myout1$ = LTRIM$(RTRIM$(myout1$)) 'trim any leading/trailing spaces 'try to print out fewer significant digits to reduce file size nsdig = 4 'desired number of significant digits rgt$ = "": IF INSTR(myout1$, "E") <> 0 THEN rgt$ = RIGHT$(myout1$, 4) mydec = 0: IF INSTR(myout1$, ".") <> 0 THEN mydec = 1 'see if there's a decimal point spos = 0: IF LEFT$(myout1$, 1) = "-" THEN spos = 1 'see if it is a negative number myout1$ = LEFT$(myout1$, spos + nsdig + mydec) + rgt$ mytime = (ii - 1) / srate: mytim$ = STR$(mytime) mytim$ = LTRIM$(RTRIM$(mytim$)) 'trim any leading/trailing spaces 'try to print out fewer significant digits to reduce file size nsdig = 6 'desired number of significant digits rgt$ = "": IF INSTR(mytim$, "E") <> 0 THEN rgt$ = RIGHT$(mytim$, 4) mydec = 0: IF INSTR(mytim$, ".") <> 0 THEN mydec = 1 'see if there's a decimal point spos = 0: IF LEFT$(mytim$, 1) = "-" THEN spos = 1 'see if it is a negative number mytim$ = LEFT$(mytim$, spos + nsdig + mydec) + rgt$ myout2$ = STR$(chan2) myout2$ = LTRIM$(RTRIM$(myout2$)) 'trim any leading/trailing spaces 'try to print out fewer significant digits to reduce file size nsdig = 4 'desired number of significant digits rgt$ = "": IF INSTR(myout2$, "E") <> 0 THEN rgt$ = RIGHT$(myout2$, 4) mydec = 0: IF INSTR(myout2$, ".") <> 0 THEN mydec = 1 'see if there's a decimal point spos = 0: IF LEFT$(myout2$, 1) = "-" THEN spos = 1 'see if it is a negative number myout2$ = LEFT$(myout2$, spos + nsdig + mydec) + rgt$ PRINT #2, mytim$; WSPC$; myout1$ PRINT #3, mytim$; WSPC$; myout2$ 'PRINT mytim$; WSPC$; myout1$; "-----"; mytim$; WSPC$; myout2$ 'FOR DEBUG ONLY NEXT ii CLOSE #1 CLOSE #2 CLOSE #3 END IF