home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 3_2004-2005.ISO / Data / Zips / Matt_Playe176515722004.psc / FFT / mixer / mixer.frm < prev    next >
Text File  |  2004-07-02  |  22KB  |  753 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00A4A3A5&
  4.    BorderStyle     =   0  'None
  5.    ClientHeight    =   6060
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   6555
  9.    ControlBox      =   0   'False
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   404
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   437
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.PictureBox VUBox 
  17.       DrawWidth       =   2
  18.       FillStyle       =   0  'Solid
  19.       ForeColor       =   &H000080FF&
  20.       Height          =   735
  21.       Left            =   480
  22.       ScaleHeight     =   45
  23.       ScaleMode       =   3  'Pixel
  24.       ScaleWidth      =   53
  25.       TabIndex        =   14
  26.       Top             =   360
  27.       Width           =   855
  28.    End
  29.    Begin VB.Frame Frame1 
  30.       BorderStyle     =   0  'None
  31.       Height          =   855
  32.       Left            =   1560
  33.       TabIndex        =   12
  34.       Top             =   240
  35.       Width           =   3495
  36.       Begin VB.Label lblstatus 
  37.          Alignment       =   2  'Center
  38.          BackColor       =   &H80000012&
  39.          BeginProperty Font 
  40.             Name            =   "Courier"
  41.             Size            =   24
  42.             Charset         =   0
  43.             Weight          =   400
  44.             Underline       =   0   'False
  45.             Italic          =   0   'False
  46.             Strikethrough   =   0   'False
  47.          EndProperty
  48.          ForeColor       =   &H8000000D&
  49.          Height          =   615
  50.          Left            =   540
  51.          TabIndex        =   13
  52.          Top             =   120
  53.          Width           =   2415
  54.       End
  55.    End
  56.    Begin VB.ListBox List1 
  57.       BackColor       =   &H00C0C0C0&
  58.       Height          =   2985
  59.       ItemData        =   "mixer.frx":0000
  60.       Left            =   4080
  61.       List            =   "mixer.frx":0002
  62.       TabIndex        =   11
  63.       Top             =   1680
  64.       Width           =   2295
  65.    End
  66.    Begin VB.CommandButton cmdExit 
  67.       Caption         =   "X"
  68.       Height          =   255
  69.       Left            =   5760
  70.       TabIndex        =   10
  71.       Top             =   480
  72.       Width           =   255
  73.    End
  74.    Begin VB.CommandButton cmdPlay 
  75.       Caption         =   ">"
  76.       Height          =   375
  77.       Left            =   3480
  78.       TabIndex        =   9
  79.       Top             =   1200
  80.       Width           =   375
  81.    End
  82.    Begin VB.CommandButton cmdNext 
  83.       Caption         =   ">>"
  84.       Height          =   375
  85.       Left            =   3840
  86.       TabIndex        =   8
  87.       Top             =   1200
  88.       Width           =   375
  89.    End
  90.    Begin VB.CommandButton cmdPrev 
  91.       Caption         =   "<<"
  92.       Height          =   375
  93.       Left            =   2520
  94.       TabIndex        =   7
  95.       Top             =   1200
  96.       Width           =   375
  97.    End
  98.    Begin VB.CommandButton cmdStop 
  99.       Caption         =   "STOP"
  100.       Height          =   375
  101.       Left            =   2880
  102.       TabIndex        =   6
  103.       Top             =   1200
  104.       Width           =   615
  105.    End
  106.    Begin VB.CommandButton cmdVolume 
  107.       Caption         =   "Vol"
  108.       Height          =   375
  109.       Left            =   4200
  110.       TabIndex        =   5
  111.       Top             =   1200
  112.       Width           =   495
  113.    End
  114.    Begin VB.CommandButton cmdEject 
  115.       Caption         =   "EJ"
  116.       Height          =   375
  117.       Left            =   2160
  118.       TabIndex        =   4
  119.       Top             =   1200
  120.       Width           =   375
  121.    End
  122.    Begin VB.ComboBox DevicesBox 
  123.       Height          =   315
  124.       Left            =   120
  125.       Style           =   2  'Dropdown List
  126.       TabIndex        =   3
  127.       Top             =   5640
  128.       Visible         =   0   'False
  129.       Width           =   2265
  130.    End
  131.    Begin VB.PictureBox FFTPanel 
  132.       BackColor       =   &H00000000&
  133.       DrawStyle       =   5  'Transparent
  134.       FillStyle       =   0  'Solid
  135.       ForeColor       =   &H000080FF&
  136.       Height          =   3825
  137.       Left            =   120
  138.       ScaleHeight     =   251
  139.       ScaleMode       =   3  'Pixel
  140.       ScaleWidth      =   251
  141.       TabIndex        =   2
  142.       Top             =   1680
  143.       Width           =   3825
  144.    End
  145.    Begin VB.PictureBox Scope 
  146.       BackColor       =   &H00000000&
  147.       FillStyle       =   0  'Solid
  148.       ForeColor       =   &H000080FF&
  149.       Height          =   360
  150.       Index           =   0
  151.       Left            =   5280
  152.       ScaleHeight     =   20
  153.       ScaleMode       =   3  'Pixel
  154.       ScaleWidth      =   68
  155.       TabIndex        =   1
  156.       Top             =   5160
  157.       Width           =   1080
  158.    End
  159.    Begin VB.PictureBox Scope 
  160.       BackColor       =   &H00000000&
  161.       FillStyle       =   0  'Solid
  162.       ForeColor       =   &H000080FF&
  163.       Height          =   360
  164.       Index           =   1
  165.       Left            =   4080
  166.       ScaleHeight     =   20
  167.       ScaleMode       =   3  'Pixel
  168.       ScaleWidth      =   68
  169.       TabIndex        =   0
  170.       Top             =   5160
  171.       Width           =   1080
  172.    End
  173. End
  174. Attribute VB_Name = "Form1"
  175. Attribute VB_GlobalNameSpace = False
  176. Attribute VB_Creatable = False
  177. Attribute VB_PredeclaredId = True
  178. Attribute VB_Exposed = False
  179. '******************************************************
  180. 'Matt Player
  181. '******************************************************
  182. 'Thank you for Downloading MattPlayer.  This program has been
  183. 'created as an experiment with FFT (Fast Fourier Transforms) to
  184. 'visualize sound.  This application is a little rough around the
  185. 'edges but is fun to use and watch.
  186. 'NOTE:  The visualization will not work unless either the Wave OUT Mixer, or CDPlayer
  187. 'is selected in the volume control under the Recording Control.
  188. 'Please email me any bug fixes or enhancements at sco_stinks@yahoo.com
  189. '
  190. 'Enjoy
  191. 'Matt Gillmore
  192.  
  193. 'Kudos to Murphy McCauley for his FFT algorithm
  194.  
  195.  
  196. Option Explicit
  197.  
  198. Private Type BGRQuad
  199.   b As Byte
  200.   g As Byte
  201.   R As Byte
  202.   Empty As Byte
  203. End Type
  204. Private Type BITMAPINFOHEADER
  205.   biSize As Long
  206.   biWidth As Long
  207.   biHeight As Long
  208.   biPlanes As Integer
  209.   biBitCount As Integer
  210.   biCompression As Long
  211.   biSizeImage As Long
  212.   biXPelsPerMeter As Long
  213.   biYPelsPerMeter As Long
  214.   biClrUsed As Long
  215.   biClrImportant As Long
  216. End Type
  217.  
  218. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, D@) As Long
  219. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
  220. Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  221. Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal srcx As Long, ByVal srcy As Long, ByVal wSrcWidth As Long, ByVal wSrcHeight As Long, lpBits As Any, lpBitsInfo As BITMAPINFOHEADER, ByVal wUsage As Long, ByVal dwRop As Long) As Long
  222.  
  223. 'Mixer-Vars
  224. Dim hMixer&, SrcArr(20) As MIXERCONTROL, DstArr(20) As MIXERCONTROL
  225. 'WaveIn-Vars
  226. Dim DevHandle&, RBuf(29) As WavBuf, RIdx&, FNr&, FSize&
  227. Dim WithEvents xt As XTimer, pArr() As BGRQuad, MaxL&, MaxR&
  228. Attribute xt.VB_VarHelpID = -1
  229. Dim status As Boolean
  230. Dim Num_Tracks As Long
  231. Dim curTrack As Integer
  232. Dim Cd_Open As Boolean
  233. Dim gX As Long
  234. Dim gY As Long
  235. Dim offset As Integer
  236.  
  237. Private Sub cmdEject_Click()
  238. Dim lRet As Long
  239.     If Not Cd_Open Then
  240.         lRet = mciSendString("set cd door open", 0, 0, 0)
  241.         Cd_Open = True
  242.     Else
  243.         lRet = mciSendString("set cd door closed", 0, 0, 0)
  244.         Cd_Open = False
  245.     End If
  246. End Sub
  247.  
  248. Private Sub cmdExit_Click()
  249.     Unload Me
  250. End Sub
  251.  
  252. Private Sub cmdNext_Click()
  253. Dim lRet As Long
  254.     curTrack = GetCurTrack()
  255.     curTrack = curTrack + 1
  256.     If curTrack <> GetNumTracks Then
  257.         
  258.         If CheckIfPlaying = 1 Then
  259.             mciSendString "play cd from " & CStr(curTrack), 0, 0, 0
  260.         Else
  261.             mciSendString "seek cd to " & CStr(curTrack), 0, 0, 0
  262.         End If
  263.     
  264.     End If
  265. End Sub
  266.  
  267. Private Sub cmdPlay_Click()
  268. Dim lRet As Long
  269. Dim sPos As String * 30
  270. Dim nCurrentTrack As Integer
  271.     
  272.     lRet = mciSendString("play cd", 0&, 0, 0)
  273.     nCurrentTrack = 1
  274.     lRet = mciSendString("play cd from" & Str(nCurrentTrack), 0&, 0, 0)
  275.  
  276. End Sub
  277.  
  278.  
  279.  
  280. Private Sub cmdPrev_Click()
  281. Dim lRet As Long
  282.     If curTrack = 1 Then
  283.         '
  284.     Else
  285.         curTrack = curTrack - 1
  286.         If CheckIfPlaying = 1 Then
  287.             lRet = mciSendString("play cd from" & Str(curTrack), 0&, 0, 0)
  288.         Else
  289.             mciSendString "seek cd to " & CStr(curTrack), 0, 0, 0
  290.         End If
  291.     End If
  292.     
  293. End Sub
  294.  
  295. Private Sub cmdStop_Click()
  296.     Dim lRet As Long
  297.     
  298.     lRet = mciSendString("stop cd wait", 0&, 0, 0)
  299.  
  300.     DoEvents
  301.  
  302. End Sub
  303.  
  304. Private Sub cmdVolume_Click()
  305.     Shell "sndvol32.exe", vbNormalFocus
  306. End Sub
  307.  
  308.  
  309.  
  310. Public Sub SetTrackList(lnumfiles As Long)
  311. Dim i As Integer
  312.     List1.Clear
  313.     For i = 1 To lnumfiles Step 1
  314.         Form1.List1.AddItem "Track " & i
  315.     Next
  316.  
  317. End Sub
  318. Private Sub Form_Load()
  319. Dim i&, mxl As MIXERLINE, MCaps As MIXERCAPS
  320.     
  321.     If Not InitDevices Then Unload Me: Exit Sub
  322.     
  323.     If mixerOpen(hMixer, 0, 0, 0, 0) Then Exit Sub
  324.     
  325.     Randomize
  326.   
  327.     mixerGetDevCaps hMixer, MCaps, Len(MCaps)
  328.     For i = 0 To MCaps.cDestinations - 1
  329.         mxl.cbStruct = Len(mxl)
  330.         mxl.dwDestination = i
  331.         mixerGetLineInfo hMixer, mxl, 0 'by DestinationLine
  332.     Next i
  333.   
  334.  
  335.     i = mciSendString("open cdaudio alias cd wait shareable", 0&, 0, 0)
  336.     i = mciSendString("set cd time format tmsf", 0&, 0, 0)
  337.  
  338.     SetWindowRgn Form1.hWnd, CreateRoundRectRgn(0, 0, Form1.ScaleWidth, Form1.ScaleHeight, 150, 150), True
  339.     SetWindowRgn List1.hWnd, CreateRoundRectRgn(0, 0, List1.Width, List1.Height, 15, 15), True
  340.     SetWindowRgn Frame1.hWnd, CreateRoundRectRgn(0, 0, Frame1.Width, Frame1.Height, 15, 15), True
  341.     Num_Tracks = GetNumTracks
  342.     If Num_Tracks <> 0 Then
  343.         SetTrackList Num_Tracks
  344.     End If
  345.     Set xt = New XTimer
  346.     xt.Interval = 1
  347.     
  348. '    ExplodeForm Form1, 500
  349.     StartListening
  350.     curTrack = 1
  351.     Cd_Open = False
  352.  
  353. End Sub
  354. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  355.     status = True
  356.     gX = X
  357.     gY = Y
  358. End Sub
  359.  
  360. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  361. Dim lXdiff As Long
  362. Dim LYdiff As Long
  363.  
  364.     lXdiff = gX - X
  365.     LYdiff = gY - Y
  366.     If status = True Then
  367.  
  368.         Form1.Move Form1.Left - lXdiff, Form1.Top - LYdiff
  369.     End If
  370. End Sub
  371.  
  372. Private Function FillControlInfos(mxl As MIXERLINE, Arr() As MIXERCONTROL, L As ListBox)
  373. Dim i&, mxlc As MIXERLINECONTROLS, hMem&
  374.     mxlc.cbStruct = Len(mxlc)
  375.     mxlc.dwLineID = mxl.dwLineID
  376.     mxlc.cControls = mxl.cControls
  377.     mxlc.cbmxctrl = Len(Arr(0))
  378.     hMem = GlobalAlloc(&H40, Len(Arr(0)) * mxlc.cControls)
  379.     mxlc.pamxctrl = GlobalLock(hMem)
  380.     L.Clear
  381.     If mixerGetLineControls(hMixer, mxlc, 0) Then Exit Function
  382.     
  383.     mixerGetLineControls hMixer, mxlc, 0 'again, because mxlc.cControls is now exact
  384.     
  385.     For i = 0 To mxl.cControls - 1
  386.         CopyStructFromPtr Arr(i), mxlc.pamxctrl + i * mxlc.cbmxctrl, Len(Arr(i))
  387.         L.AddItem Left(Arr(i).szShortName, InStr(Arr(i).szShortName, Chr(0)) - 1)
  388.     Next i
  389.     
  390.     If L.ListCount Then L.ListIndex = 0
  391.     GlobalFree hMem
  392. End Function
  393.  
  394. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  395.     status = False
  396. End Sub
  397.  
  398.  
  399.  
  400.  
  401. Private Function SetValue(mxctl As MIXERCONTROL, ByVal Value&) As Boolean
  402. Dim MCD As MIXERCONTROLDETAILS, ValArr&(50)
  403.     
  404.     MCD.cbStruct = Len(MCD)
  405.     MCD.dwControlID = mxctl.dwControlID
  406.     
  407.     If mxctl.fdwControl And 2 Then
  408.         MCD.item = mxctl.cMultipleItems
  409.         ValArr(Value) = 1
  410.     Else 'Default
  411.         ValArr(0) = Value
  412.     End If
  413.     
  414.     MCD.cbDetails = Len(ValArr(0))
  415.     MCD.paDetails = VarPtr(ValArr(0))
  416.     MCD.cChannels = 1
  417.     
  418.     If mixerSetControlDetails(hMixer, MCD, 0) Then Exit Function
  419.     SetValue = True
  420. End Function
  421.  
  422. Private Function GetValue&(mxctl As MIXERCONTROL)
  423. Dim MCD As MIXERCONTROLDETAILS, ValArr&(50), i&
  424.     MCD.cbStruct = Len(MCD)
  425.     MCD.dwControlID = mxctl.dwControlID
  426.     If mxctl.fdwControl And 2 Then MCD.item = mxctl.cMultipleItems
  427.     
  428.     MCD.cbDetails = Len(ValArr(0))
  429.     MCD.paDetails = VarPtr(ValArr(0))
  430.     MCD.cChannels = 1
  431.     If mixerGetControlDetails(hMixer, MCD, 0) Then Exit Function
  432.     GetValue = ValArr(0)
  433.     If mxctl.fdwControl And 2 Then
  434.         For i = 0 To MCD.item - 1
  435.             If ValArr(i) Then Exit For
  436.         Next i
  437.         GetValue = i
  438.     End If
  439. End Function
  440.  
  441. '*******WaveIn-Example follows
  442. Private Function InitDevices()
  443. Dim Caps As WaveInCaps, i&
  444.     DevicesBox.Clear
  445.     For i = 0 To waveInGetNumDevs - 1
  446.         waveInGetDevCaps i, Caps, Len(Caps)
  447.         If Caps.Formats And WAVE_FORMAT_4S16 Then DevicesBox.AddItem StrConv(Caps.ProductName, vbUnicode)
  448.     Next
  449.     If DevicesBox.ListCount Then InitDevices = True: DevicesBox.ListIndex = 0
  450. End Function
  451.  
  452. Private Sub StartListening()
  453. Static WaveFormat As WaveFormatEx
  454. On Error Resume Next
  455. '    FNr = FreeFile
  456. '    If Dir(App.Path & "Test.Wav") <> "" Then Kill App.Path & "Test.Wav"
  457. '    Open App.Path & "Test.Wav" For Binary As FNr
  458. '    FSize = 0
  459. '    If Err Then MsgBox "Cannot open File!"
  460.     
  461.     With WaveFormat
  462.       .FormatTag = WAVE_FORMAT_PCM
  463.       .Channels = 2
  464.       .SamplesPerSec = 44100
  465.       .BitsPerSample = 16
  466.       .BlockAlign = (.Channels * .BitsPerSample) \ 8
  467.       .AvgBytesPerSec = .BlockAlign * .SamplesPerSec
  468.     End With
  469.     
  470.     waveInOpen DevHandle, DevicesBox.ListIndex, WaveFormat, 0, 0, 0
  471.     If DevHandle = 0 Then Exit Sub
  472.     
  473.     waveInStart DevHandle
  474.     xt.Enabled = True
  475. End Sub
  476.  
  477. Private Sub StopButton_Click()
  478.     DoStop
  479.     Close FNr
  480. End Sub
  481.  
  482. Private Sub DoStop()
  483. Dim i&
  484.     xt.Enabled = False
  485.         If DevHandle Then
  486.         For i = 0 To UBound(RBuf)
  487.             waveInUnprepareHeader DevHandle, RBuf(i).Hdr, Len(RBuf(i).Hdr)
  488.         Next i
  489.         waveInReset DevHandle
  490.         waveInClose DevHandle
  491.         DevHandle = 0
  492.     End If
  493. End Sub
  494.  
  495. Private Sub DrawOsz(Arr() As Stereo)
  496. Dim X&, Y&, dx&, dy&, dy2&, dc0&, dc1&
  497.  
  498.     dx = Scope(0).ScaleWidth: dy = Scope(0).ScaleHeight
  499.     dy2 = dy \ 2
  500.     dc0 = Scope(0).hdc: dc1 = Scope(1).hdc
  501.     
  502.     Scope(0).ForeColor = Scope(0).BackColor: Scope(1).ForeColor = Scope(1).BackColor
  503.     Rectangle dc0, 0, 0, dx, dy: Rectangle dc1, 0, 0, dx, dy
  504.     
  505.     Scope(0).ForeColor = 33023: Scope(1).ForeColor = 33023
  506.     MoveToEx dc0, 0, dy2, 0: MoveToEx dc1, 0, dy2, 0
  507.     MaxL = 0: MaxR = 0
  508.     For X = 0 To UBound(Arr)
  509.         If Abs(CLng(Arr(X).L)) > MaxL Then MaxL = Abs(CLng(Arr(X).L))
  510.         If Abs(CLng(Arr(X).R)) > MaxR Then MaxR = Abs(CLng(Arr(X).R))
  511.         If X Mod 15 = 0 Then
  512.             LineTo dc0, X \ 4, Arr(X).L \ 4000 + dy2
  513.             LineTo dc1, X \ 8, Arr(X).R \ 4000 + dy2
  514.         End If
  515.     Next
  516. End Sub
  517.  
  518. Private Sub DrawVU(Arr() As Stereo)
  519. Dim dx, dy, dy2, dx2, dc0 As Long
  520. Dim dAmp As Long
  521. Dim lAmpSum As Long
  522. Dim lAmpCount As Long
  523. Dim i As Integer
  524.  
  525.     dx = VUBox.ScaleWidth
  526.     dx2 = VUBox.ScaleWidth \ 2
  527.     dy = VUBox.ScaleHeight
  528.     dy2 = VUBox.ScaleHeight
  529.     
  530.     dc0 = VUBox.hdc
  531.     VUBox.Cls
  532.     MoveToEx dc0, dx2, dy2, 0
  533.     
  534.     lAmpCount = UBound(Arr)
  535.     VUBox.ForeColor = 33023
  536.     For i = 0 To UBound(Arr)
  537.         If i Mod 15 = 0 Then
  538.             lAmpSum = lAmpSum + Arr(i).L \ 250
  539.         End If
  540.     Next i
  541.     
  542.     dAmp = lAmpSum / (1024 / 15)
  543.     dAmp = Abs(dAmp)
  544.     LineTo dc0, dAmp, 2
  545.  
  546. End Sub
  547.  
  548. Private Sub DrawFFT(Buf As WavBuf)
  549. Dim i&, j&, X&, Y&, dx&, dy&, dc&, xlo&, xro&
  550. Static Fl&, xScale#, xl#, xr#, BIH As BITMAPINFOHEADER
  551.     xScale = 1 / 11111123456#
  552.     
  553.     FFTAudio Buf.Arr, Buf.FFT
  554.     
  555.     dx = FFTPanel.ScaleWidth: dy = FFTPanel.ScaleHeight
  556.     dc = FFTPanel.hdc
  557.       
  558.     If Fl = 0 Then 'init
  559.         ReDim pArr(1 To dx, 1 To dy)
  560.         BIH.biSize = 40: BIH.biBitCount = 32: BIH.biPlanes = 1
  561.         BIH.biWidth = dx: BIH.biHeight = dy
  562.     Else
  563.         For X = 1 To dx
  564.             For Y = 1 To dy
  565.                 If pArr(X, Y).R <> 0 Then
  566.                     If pArr(X, Y).R >= 20 Then pArr(X, Y).R = pArr(X, Y).R - 20
  567.                     If pArr(X, Y).g >= 10 Then pArr(X, Y).g = pArr(X, Y).g - 10
  568.                 End If
  569.             Next Y
  570.         Next X
  571.     End If
  572.     
  573.     xlo = dx / 2 - 6: xro = dx / 2 + 6
  574.     X = 0: Y = 5
  575.     For i = 1 To 23
  576.       xl = 0: xr = 0
  577.       For j = 1 To CLng(1.194 ^ i)
  578.         With Buf.FFT(X)
  579.           xl = xl + .L: xr = xr + .R
  580.         End With
  581.         X = X + 1
  582.       Next j
  583.       Y = Y + 5
  584.     '    Rect pArr, xlo - Sqr(xl * xScale), y, xlo, y + 1
  585.       RECT pArr, 5, dx - 6 - Y, 5 + Sqr(xr * xScale), dx - 4 - Y, dy - 3, "Vertical"
  586.       RECT pArr, 5, Y, 5 + Sqr(xl * xScale), Y + 2, dy - 6, "Vertical"
  587.     Next i
  588.     '  RECT pArr, xlo + 3, 3, xlo + 5, MaxL / 32768 * (dy - 6), dy - 6
  589.     '  Rect pArr, xro - 5, 3, xro - 3, MaxR / 32768 * (dy - 6), dy - 6
  590.     
  591.     StretchDIBits dc, 0, 0, dx, dy, 0, 0, dx, dy, pArr(1, 1), BIH, 0, vbSrcCopy
  592.     Fl = 1
  593. End Sub
  594.  
  595. Private Sub RECT(pArr() As BGRQuad, ByVal xs&, ByVal ys&, ByVal xe&, ByVal ye&, Optional Max&, Optional Spec$)
  596. Dim X&, Y&, Mx&, MM&, D As Byte
  597.  
  598.     If xs < 1 Then xs = 1
  599.     If ys < 1 Then ys = 1
  600.     If xe > UBound(pArr, 1) Then xe = UBound(pArr, 1)
  601.     If ye > UBound(pArr, 2) Then ye = UBound(pArr, 2)
  602.     If Max And Spec = vbNullString Then
  603.         Mx = Max * 0.85
  604.         MM = Max * 0.5
  605.         For X = xs To xe
  606.             For Y = ys To ye
  607.                 If Y > Mx Then D = 0 Else If Y > MM Then D = 222 Else D = 128
  608.                 pArr(X, Y).R = 255
  609.                 pArr(X, Y).g = D
  610.             Next Y
  611.         Next X
  612.     Else
  613.         Mx = Max * 0.85
  614.         MM = Max * ((0.4 - 0.35) * Rnd + 0.35)
  615.         For Y = xs To xe
  616.             For X = ys To ye
  617.                 If Y > Mx Then D = 0 Else If Y > MM Then D = 222 Else D = 128
  618.                 pArr(X, Y).R = 255
  619.                 pArr(X, Y).g = D
  620.             Next X
  621.         Next Y
  622.     End If
  623. End Sub
  624.  
  625.  
  626.  
  627. Private Sub List1_DblClick()
  628. Dim i As Integer
  629. Dim lRet As Long
  630.     For i = 0 To List1.ListCount - 1 Step 1
  631.         If List1.Selected(i) Then
  632.             'change current track
  633.             curTrack = i + 1
  634.             If CheckIfPlaying = 1 Then
  635.                 mciSendString "play cd from " & CStr(curTrack), 0, 0, 0
  636.             Else
  637.                 mciSendString "seek cd to " & CStr(curTrack), 0, 0, 0
  638.             End If
  639.        End If
  640.     Next i
  641. End Sub
  642.  
  643. Private Sub XT_Timer()
  644. Dim i&
  645. Dim sPos As String * 30
  646. Dim sTrack As Integer
  647. Dim sMin As Integer
  648. Dim sSec As Integer
  649. Dim lRet As Integer
  650. Dim c1(2) As POINTAPI
  651. Static lTicCount As Long
  652.  
  653.     lTicCount = lTicCount + 1
  654.     If lTicCount > 10 Then
  655.         If Num_Tracks <> GetNumTracks Then
  656.             Num_Tracks = GetNumTracks
  657.             SetTrackList Num_Tracks
  658.         End If
  659.         
  660.         lRet = mciSendString("status cd position", sPos, Len(sPos), 0)
  661.         If lRet = 0 Then
  662.             sTrack = CInt(Mid$(sPos, 1, 2))
  663.             sMin = CInt(Mid$(sPos, 4, 2))
  664.             sSec = CInt(Mid$(sPos, 7, 2))
  665.         End If
  666.         
  667.         lblstatus.Caption = Format(sTrack, "00") & " " & Format(sMin, "00") & ":" & Format(sSec, "00")
  668.         
  669.         lTicCount = 0
  670.     
  671.     End If
  672.  
  673.     Do While RBuf(RIdx).Hdr.dwFlags And WHDR_DONE
  674.         ProcessBuf RBuf(RIdx)
  675.         RIdx = CIdx(RIdx + 1)
  676.     Loop
  677.     
  678.     DoEvents
  679.     
  680.     For i = RIdx To RIdx + UBound(RBuf)
  681.         InitBuf RBuf(CIdx(i))
  682.     Next i
  683.     
  684. End Sub
  685.  
  686. Private Sub InitBuf(Buf As WavBuf)
  687.   If Buf.Hdr.dwUser Then Exit Sub
  688.   With Buf.Hdr
  689.     .dwUser = 1
  690.     If .lpData = 0 Then .lpData = VarPtr(Buf.Arr(0))
  691.     If .dwBufferLength = 0 Then .dwBufferLength = (UBound(Buf.Arr) + 1) * 4
  692.     waveInPrepareHeader DevHandle, Buf.Hdr, Len(Buf.Hdr)
  693.     waveInAddBuffer DevHandle, Buf.Hdr, Len(Buf.Hdr)
  694.   End With
  695. End Sub
  696.  
  697. Private Sub ProcessBuf(Buf As WavBuf)
  698. Static lTicCount As Long
  699.  
  700.     waveInUnprepareHeader DevHandle, Buf.Hdr, Len(Buf.Hdr)
  701.     Buf.Hdr.dwFlags = 0
  702.     Buf.Hdr.dwUser = 0
  703.     DrawOsz Buf.Arr
  704.     DrawFFT Buf
  705.     
  706. '    lTicCount = lTicCount + 1
  707. '    If lTicCount > 3 Then
  708.         DrawVU Buf.Arr
  709.         lTicCount = 0
  710. '    End If
  711. '    WriteFile Buf
  712. End Sub
  713.  
  714. Private Function CIdx&(ByVal Idx&)
  715.     CIdx = Idx Mod (UBound(RBuf) + 1)
  716. End Function
  717.  
  718. Private Sub Form_Unload(Cancel As Integer)
  719. Dim retvalue As Integer
  720. Dim returnstring As Long
  721.     xt.Enabled = False
  722.     cmdStop_Click
  723.     retvalue = mciSendString("close all", returnstring, 127, 0)
  724.     mixerClose hMixer
  725.     
  726.     If DevHandle Then DoStop
  727.  
  728.     Set xt = Nothing
  729.     Close
  730. End Sub
  731.  
  732. Private Sub WriteFile(Buf As WavBuf)
  733. Static L&(10)
  734.     FSize = FSize + 4096
  735.     If L(0) = 0 Then
  736.         L(0) = 1179011410: L(2) = 1163280727: L(3) = 544501094: L(4) = 16: L(5) = 131073
  737.         L(6) = 44100: L(7) = 176400: L(8) = 1048580: L(9) = 1635017060
  738.     End If
  739.     L(10) = FSize
  740.     L(1) = FSize + 36
  741.     Put FNr, FSize + 44 - 4095, Buf.Arr
  742.     Put FNr, 1, L
  743. End Sub
  744.  
  745. Private Function CheckIfPlaying() As Integer
  746. Dim strTemp As String * 30
  747.  
  748.     CheckIfPlaying = 0
  749.     mciSendString "status cd mode", strTemp, Len(strTemp), 0
  750.     If Mid(strTemp, 1, 7) = "playing" Then CheckIfPlaying = 1
  751.     
  752. End Function
  753.