SmileBASIC

Program List

SU_SIMPLE

Load the program from "Create Programs with SmileBASIC" on the TOP MENU, and then press the EDIT key on the keyboard to edit this program.


'======================================
'
' Simple Effector Example
'
' Ver.1.00 2016/02/23
'
' (C)2016 SmileBoom
'
'======================================
OPTION STRICT

VAR SIZE=1024
VAR CENTER=32768

'======================================
'DELAY EFFECTOR
'  DLYTIME: 0 - 99
'   Time(msec)=DLYTIME*1024sample/32730Hz
'             =DLYTIME*31msec
'  FEEDBACK: 0 - 1.0
'======================================
VAR DLYBUFSIZE=SIZE*100
DIM DLYBUF[DLYBUFSIZE]
VAR DLY_WR,DLY_RD
DIM TMPBUF[SIZE]

DEF FX_DELAY OUTBUF,INBUF,DLYTIME,FEEDBACK
 DLY_RD=DLY_WR-SIZE*DLYTIME
 IF DLY_RD<0 THEN DLY_RD=DLY_RD+DLYBUFSIZE
 COPY TMPBUF,0,DLYBUF,DLY_RD,SIZE
 ARYOP #AOPMAD,OUTBUF,TMPBUF,
FEEDBACK,INBUF DLY_WR=RINGCOPY(DLYBUF,DLY_WR,OUTBUF
,0,SIZE) END '====================================== 'DRAW WAVEFORM IMAGE '====================================== VAR X=0 DEF DRAWWAVE OUTBUF,INBUF VAR Y,Y0 VAR I FOR I=0 TO SIZE-1 STEP SIZE/4 GLINE X,0,X,239,RGB(0,0,0) Y0=60 Y=INBUF[I]*60/CENTER GLINE X,Y0,X,Y0+Y,RGB(255,0,0) Y0=180 Y=OUTBUF[I]*60/CENTER GLINE X,Y0,X,Y0+Y,RGB(0,0,255) INC X IF X>=400 THEN X=0 NEXT GLINE X,0,X,239,RGB(255,255,0) END '====================================== 'SIGNAL PROCESSING '====================================== DEF AUDIO_PROC OUTBUF,INBUF 'CONVERT ARRAY VALUE FROM 0..65535 TO
-32768..+32767 ARYOP #AOPSUB,INBUF,INBUF,CENTER 'SIGNAL PROCESSING FUNCTIONS FX_DELAY OUTBUF,INBUF,10,0.5 'DRAW WAVEFORM IMAGE DRAWWAVE OUTBUF,INBUF 'CONVERT ARRAY VALUE FROM -32768..+32767
TO 0..65535 ARYOP #AOPADD,OUTBUF,OUTBUF,CENTER END '====================================== 'MAIN LOOP '====================================== DEF MAINLOOP VAR NUM_AREA=8 VAR CUR_AREA=NUM_AREA-2 VAR READPOS VAR LASTPOS=0 DIM STREAMBUF[SIZE*NUM_AREA] DIM MICBUF[SIZE] DIM TMPBUF[SIZE] FILL STREAMBUF,0 PCMSTREAM STREAMBUF XON MIC MICSTART 3,1,0 '32730Hz 16bit Loop WHILE BUTTON()==0 'WAIT DATA MICREADY LASTPOS 'UPDATE INPUT POINTER READPOS=LASTPOS LASTPOS=MICPOS 'READ DATA FROM MIC MICGET READPOS,MICBUF 'SIGNAL PROCESSING AUDIO_PROC TMPBUF,MICBUF 'WRITE DATA TO STREAM COPY STREAMBUF,CUR_AREA*SIZE,TMPBUF
,0,SIZE 'UPDATE STREAMBUF WRITE POINTER CUR_AREA=(CUR_AREA+1) MOD NUM_AREA WEND XOFF MIC PCMSTOP END '====================================== 'WAIT FOR MIC STATUS UNTIL ENOUGH DATA SIZE '====================================== DEF MICREADY LASTPOS VAR POS,READABLE_SIZE REPEAT POS=MICPOS IF POS=SIZE END '====================================== 'READ MIC DATA '====================================== DEF MICGET POS,ARY DIM TMP[SIZE] VAR SIZE1,SIZE2 IF (POS+SIZE)<=MICSIZE THEN MICSAVE POS,SIZE,ARY ELSE SIZE1=MICSIZE-POS SIZE2=SIZE-SIZE1 MICSAVE POS,SIZE1,ARY MICSAVE 0,SIZE2,TMP COPY ARY,SIZE1,TMP,0,SIZE2 ENDIF END '====================================== 'MAIN PROGRAM '====================================== XOFF MIC ACLS LOCATE 0, 0:COLOR 3:PRINT "INPUT" LOCATE 0,17:COLOR 9:PRINT "OUTPUT" MAINLOOP ACLS END