Code archives/Audio/Waveform Functions
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Here we have a function you can use to retreive the "height" of a wave at any certain time.... You pass the function the WaveType, Time into Playing and Frequency. Parameters: WT can be 1 (sine), 2(square), 3(saw) or 4 (triangle). Time= The time into playing in 100th of a millisecond... Frequency= Frequency the note is playing... I made a synth before using this called BlitzSynth, however, the project code was lost and so much was lost i didnt want to start over. Shame... I hope you enjoy these functions, and i expect to see some impressive BlitzSynths soon :D (BlitzSynth (c) 2005 Damien Sturdy) :P | |||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function wave#(wt,time#,freq#) Local ret#,frq#=(time/100000.0)*360.0*freq*.5 If wt=1 Then ret#=Sin(frq*2) ;Sine If wt=2 Then ret#=(((Int(frq*2 Mod 360)/180) Mod 2)-.5) ;Square If wt=3 Then ret=(((frq*2 Mod 180)/180.0)-.5)*2 ;Saw If wt=4 Then ret=((Abs(((90-(frq Mod 180)) Mod 180)/90.0))-.5) ;Saw.. bit zhit to be honest.. Return ret End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Global scx=640,scy=480 Graphics scx,scy,16,2 SetBuffer BackBuffer() Dim oy#(3); store old poisions. Used for making lines Repeat time=time+1 Delay 1 For n=1 To 3 y#=wave(n,time*100,1) y#=(scy/2.0)+y*(scy/2.0) r=0:g=0:b=0 If n=1 Then r=255 Else If n=2 Then g=255 Else If n=3 Then b=255 Color r,g,b Line scx-2,oy(n),scx-1,y oy(n)=y Next CopyRect 0,0,scx,scy,-1,0 Color 0,0,0 Line scx-1,0,scx-1,scy Flip 0 Until KeyDown(1) |
Comments
None.
Code Archives Forum