#pragma rtGlobals=1 // Use modern global access method. #pragma rtGlobals=1 // Use modern global access method. //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// //Panel for generating tones for output on a PC or Mac //Josef G. Trapani, Amherst College (jtrapani@amherst.edu // 12/06/12 version 1.0 Menu "Macros" "Sound-O-Matic",Start_Sound_Panel("start") End //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// Function Start_Sound_Panel(ctrlName) String ctrlName String savedDataFolder = GetDataFolder(1) // Save DoWindow Sound_Panel0 variable tempvar1 = V_flag If (tempvar1!=0) KillWindow Sound_Panel0 Endif KillWaves /Z /A KillDataFolder /Z root:Sound_Stim If (cmpstr(ctrlName,"closePanelbutton")!=0) NewDataFolder /O/S root:Sound_Stim Variable/G WaitingInterval = 1 // holding interval (seconds) Variable/G EpisodeTime=100 // Single episode length (milliseconds) Variable/G EpisodeNum =1 // Stimulation episode number Variable/G gAMP = 100 // DAC points in output & input buffers (each point = 300 microvolt) Variable/G gFreq =300 // Stimulation Frequency Variable/G SamplingInterval // sampling interval (milliseconds) Variable/G SamplingFreq // sampling frequency Variable/G BufferSize //Wave size Sound_Panel(ctrlName) //Load the selected stimulus waveform Endif SetDataFolder savedDataFolder // and restore End //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// Function Sound_Panel(ctrlName) String ctrlName Variable Xcoord=190 Variable Ycoord=330 String info = IgorInfo(0) String screen1RectStr = StringByKey("SCREEN1", info) //e.g., "DEPTH=23,RECT=0,0,1280,1024" Variable depth, left, top, right, bottom sscanf screen1RectStr, "DEPTH=%d,RECT=%d,%d,%d,%d", depth, left,top, right, bottom top+=40 //adjust for title bar String platform= UpperStr(igorinfo(2)) If (cmpstr(platform,"WINDOWS")==0) NewPanel /N=Sound_Panel /W=(right-350,top,right,600) /K=2 as "soundOmatic v1.0" Else NewPanel /N=Sound_Panel /W=(right-400,top,right-50,560) /K=2 as "soundOmatic v1.0" Endif SetActiveSubwindow _endfloat_ ModifyPanel /W=Sound_Panel0 cbRGB=(61166,61166,61166), frameStyle=3, frameInset=5, noEdit=1, fixedSize=1 SetDrawLayer /W=Sound_Panel0 UserBack SetDrawEnv /W=Sound_Panel0 fillfgc= (65535,46535,26214) DrawRect /W=Sound_Panel0 25,13,323,45 SetDrawEnv /W=Sound_Panel0 linefgc= (21845,21845,21845) DrawText /W=Sound_Panel0 120,40,"Tone Generator" DrawRect /W=Sound_Panel0 Xcoord-10,Ycoord-10,Xcoord+130,Ycoord+100 SetDrawEnv /W=Sound_Panel0 fsize= 14,fstyle= 1,textrgb= (65535,65535,65535) Button closePanelbutton,pos={260,20},size={60,20},proc=Start_Sound_Panel,title="Close", win=Sound_Panel0 SetVariable setvar0,pos={Xcoord,Ycoord},size={120,16},proc=updateSound,title="Frequency (Hz)", win=Sound_Panel0 SetVariable setvar0,fSize=10,limits={100,20000,0},value= root:Sound_Stim:gFreq, win=Sound_Panel0 SetVariable setvar4,pos={Xcoord,Ycoord+20},size={100,16},proc=updateSound,title="Length (ms)", win=Sound_Panel0 SetVariable setvar4,fSize=10,limits={50,10000,0},value= root:Sound_Stim:EpisodeTime, live=0, win=Sound_Panel0 SetVariable setvar5,pos={Xcoord,Ycoord+60},size={100,16},title="Repeat:", win=Sound_Panel0 SetVariable setvar5,fSize=10,limits={1,100,1},value= root:Sound_Stim:EpisodeNum, win=Sound_Panel0 SetVariable setvar6,pos={Xcoord,Ycoord+80},size={100,16},title="Delay (s)", win=Sound_Panel0 SetVariable setvar6,fSize=10,limits={0,10,0},value= root:Sound_Stim:WaitingInterval, win=Sound_Panel0 Checkbox check4,pos={20,Ycoord-40},size={40,10},value=0,disable=0,proc=PlayPanel0,title="Big \rButton", win=Sound_Panel0 Button button3,pos={80,Ycoord-40},size={80,40},disable=0,proc=SoundStart,title="Play", win=Sound_Panel0 Button button3,fSize=16,fStyle=16,fColor=(1,3,39321), win=Sound_Panel0 NVAR gAMP=root:Sound_Stim:gAMP Slider setvar1,pos={80,Ycoord+40},size={100,100},proc=updateVolume, title="% Volume", win=Sound_Panel0 Slider setvar1,fSize=10,limits={0,100,5}, value=gAMP, disable=0, win=Sound_Panel0 SetVariable setvar2,pos={50,Ycoord+20},size={110,16},title="Volume (%)", win=Sound_Panel0 SetVariable setvar2,fSize=10,limits={100,10000,0},value= root:Sound_Stim:gAMP, disable=2, win=Sound_Panel0 Sound(ctrlName) //Load the selected stimulus waveform Display/W=(15,50,330,250) /K=2 /HOST=Sound_Panel0 wDACData ModifyGraph rgb=(0,0,0) Label left "Signal Amplitude" Label bottom "Time (s)" SetAxis left -10000,10000 SetAxis/A/N=1 bottom SetActiveSubwindow ## End //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// //Big Button popup window Function PlayPanel0(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked If (checked==1) // 1 if selelcted, 0 if not String info = IgorInfo(0) String screen1RectStr = StringByKey("SCREEN1", info) //e.g., "DEPTH=23,RECT=0,0,1280,1024" Variable depth, left, top, right, bottom sscanf screen1RectStr, "DEPTH=%d,RECT=%d,%d,%d,%d", depth, left,top, right, bottom String platform= UpperStr(igorinfo(2)) If (cmpstr(platform,"WINDOWS")==0) NewPanel /N=BigSound_Panel /W=(right-250,top,right,150) /FLT=2 Else NewPanel /N=BigSound_Panel /W=(right-300,top,right-50,150) /FLT=2 Endif ModifyPanel cbRGB=(30583,30583,30583) DoWindow /HIDE=1 /W=Sound_Panel0 Sound_Panel0 SetDrawLayer UserBack DrawRRect 16,15,240,135 Button button0,pos={30,25},size={200,100},proc=SoundStart,title="Play",fSize=72 Checkbox check4,pos={0,0},size={40,10},value=1,disable=0,proc=PlayPanel0,title="Close" Else DoWindow /F /HIDE=0 /W=Sound_Panel0 Sound_Panel0 Checkbox check4,value=0, win=Sound_Panel0 Killwindow BigSound_Panel Endif EndMacro //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// //Make the stimulation wave Function Sound(ctrlName) String ctrlName String savedDataFolder = GetDataFolder(1) // Save SetDataFolder root:Sound_Stim NVAR BufferSize // points in output & input buffers NVAR SamplingInterval // sampling interval (seconds) NVAR SamplingFreq NVAR EpisodeTime // Single episode length (seconds) NVAR gAMP NVAR gFreq // Tone Frequency NVAR WaitingInterval // Wait interval (microseconds) If (gFreq<300) //gAmp=gAmp/2 //Slider setvar1, value=gAMP Endif SamplingFreq = 44100 // Sample at CD quality SamplingInterval = 1/SamplingFreq Variable EpisodeRealTime = EpisodeTime/1000 Variable gAmpVol = 50*gAmp //scaling the "Volume" setting in the control panel BufferSize = floor(EpisodeRealTime/SamplingInterval) Make /W /O /N = (Buffersize) wDACData // make input and output buffers and the inter episode buffer wDACData = gAmpVol * sin(2 * pi * gFreq*(SamplingInterval)* x) // cycles per sec times sec per sample (frequency * samplerate) SetScale/P x,0,(SamplingInterval),"s",wDACData // Set sample rate SetDataFolder savedDataFolder // and restore End //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// //Update Sound Volume Function updateVolume (ctrlName,value,event) : SetVariableControl String ctrlName Variable value // value of variable as number Variable event String savedDataFolder = GetDataFolder(1) // Save SetDataFolder root:Sound_Stim NVAR gAMP gAMP=value Sound("update") SetDataFolder savedDataFolder // and restore End //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// //Update Sound Stimulus Function updateSound (ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum // value of variable as number String varStr // value of variable as string String varName // name of variable String savedDataFolder = GetDataFolder(1) // Save SetDataFolder root:Sound_Stim NVAR EpisodeTime // Single episode length (milliseconds) NVAR gAMP // DAC points in output & input buffers (each point = 300 microvolt) NVAR gFreq // Stimulation Frequency If (stringmatch (varName,"setVar0")) gFreq=varNum Elseif (stringmatch (varName,"setVar1")) gAMP=varNum Elseif (stringmatch (varName,"setVar4")) EpisodeTime=varNum Endif //Load wADCData and wDACData with newest stim wave values Sound("update") SetDataFolder savedDataFolder // and restore End //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// //START the Sound output Function SoundStart(ctrlName) : ButtonControl String ctrlName Variable temp, temp1 Variable i, ticktime, elapsetime String savedDataFolder = GetDataFolder(1) // Save SetDataFolder root:Sound_Stim NVAR BufferSize // points in output & input buffers NVAR SamplingInterval // sampling interval (microseconds) NVAR EpisodeTime // Single episode length (milliseconds) NVAR gAMP // DAC points in output & input buffers (each point = 300 microvolt) NVAR gFreq // Stimulation Frequency NVAR WaitingInterval // holding interval (microseconds) NVAR EpisodeNum //Number of episodes WAVE wDACData //First episode number set to 1 i = 1 do If(i>1) ticktime=((WaitingInterval)*60.15) //converts to 60ths of a second for "ticks" timer elapsetime = ticks do while (ticks<=elapsetime + ticktime) Endif PlaySound wDACData //add 1 to previous episode number i = i +1 while (i <= EpisodeNum) SetDataFolder savedDataFolder // and restore End //////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////