• Welcome to Theos PowerBasic Museum 2017.

BassBox

Started by Patrice Terrier, October 08, 2007, 10:57:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

#465
Here is a copy of a private message i got from Jordi Vallès, about the BassBox CPU usage reduction on his VISTA system.

I post it there because it could help other VISTA's user as well.

Quote
Today I implemented your sugestion to reduce the Bassbox CPU usage and playing with the value of ApiSleep and reducing the FPS to 42 the problem with of Bassbox on Windows Vista on my PC disapears. Now can see the beautiful screens without any problems, equal as my other PC with Windows XP. 

I sent you this good notice for your information.

By the way, there is another small code modification you could add to the RenderOpenGL subroutine if your CPU is very busy at the time BassBox starts runing:

SUB RenderOpenGL(BYVAL glCtrl AS LONG)

    IF IsWindowVisible(glCtrl) = 0 THEN EXIT SUB

    LOCAL graphics, nLevel, nLpeak, nRpeak, glDC, InDWMmode AS LONG
    LOCAL BBP AS BBPLUGIN
    LOCAL C1, C2, C3 AS LONG


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Emil Weiss

#466
Please can anybody tell me where i can found the Source of BassBox
has great Visualisation and think translate (Interface in/out) it do Delphi used in BassVis ( Visualisation wrapper for Bass Audio Library )
your help is welcome

sorry my english is not the best i hope you can understand me...

i hope the translation is not to hard ;)

greets Emil


Patrice Terrier

The source code is attached as a ZIP file to the first post of this thread.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Eros Olmi

#468
Hi Emil,

usually you can find project files attached to the first post of a thread.
So go to the very first page of this long long thread and look at the bottom of the first post.

Patrice code merit a deep study.

Ciao
Eros




Patrice, 35 secs faster than me  :D
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Emil Weiss

#469
thanks  :)
i hope this is the right thread or should make new for this ?

i'm have load Archive BassBox_1_27.zip
think this is right..

greets Emil

Patrice Terrier

This is how to perform further CPU usage reduction in BassBox.

Just cut and paste the code below into the BassBox source code as a replacement for the previous RenderOpenGL subroutine.


SUB RenderOpenGL(BYVAL glCtrl AS LONG)

    STATIC bFlip AS LONG
    bFlip = NOT bFlip

    IF IsWindowVisible(glCtrl) = 0 OR bFlip = 0 THEN EXIT SUB

    LOCAL graphics, nLevel, nLpeak, nRpeak, glDC, InDWMmode AS LONG
    LOCAL BBP AS BBPLUGIN
    LOCAL C1, C2, C3 AS LONG

    STATIC C0, CB1, CB2, CB3, CG1, CG2, CG3, TickCount, hOscillo AS LONG
    IF CB1 = 0 THEN
        C0 = zColorARGB(255, 0)
       CB1 = zColorARGB(255, RGB(0,23,66))
       CB2 = zColorARGB(255, RGB(0,37,103))
       CB3 = zColorARGB(255, RGB(0,74,201))
       CG1 = zColorARGB(255, RGB(0,66,23))
       CG2 = zColorARGB(255, RGB(0,103,37))
       CG3 = zColorARGB(255, RGB(0,201,74))
       hOscillo = zGetMainItem(%ID_OSCILLO)
    END IF

    glDC = GetDC(glCtrl)

    IF glRC THEN

       nLevel = BassChannelGetLevel()

       nLpeak = SolvePeak(LO(WORD, nLevel), 128)
       nRpeak = SolvePeak(HI(WORD, nLevel), 128)

       BBP.Msg          = %BBP_RENDER
       BBP.ParentWindow = glCtrl
       BBP.DC           = glDC
       BBP.RC           = glRC
       BBP.Lpeak        = nLpeak
       BBP.Rpeak        = nRpeak
       BBP.BackARGB     = SK_AEROCOLOR()
       BBP.FFTdata      = BassChannelGetData()
       BBP.FFTsize      = 256
       BBP.MediaLength  = gnMediaLength
       BBP.MediaPos     = gnMediaPos
       BBP.WIMdata      = BassChannelGetWimData()

       CALL BBP_PLUGIN(BBP)

       '// Refresh display
       CALL SwapBuffers(glDC)
       CALL zUpdateWindow(glCtrl, 0)
       'CALL wglSwapBuffers(glDC)

       STATIC FPScount, nFPScount AS LONG
       INCR nFPScount
       IF FPScount = 0 THEN FPScount = GetTickCount() + 1000
       IF GetTickCount() > FPScount THEN
          FPScount = 0
          CALL zSetCTLText(zGetMainItem(%ID_FPS), ("FPS" + STR$(nFPScount)))
          nFPScount = 0
       END IF
       
'      --------------------------------------------------------------------
'      //Start drawing the ViewMeter's LED directly onto the main window DC
       LOCAL OkL, OkR, K, C, hDC, nCell, CellW, CellH, x, y AS LONG
       LOCAL rc AS RECT

       CALL DrawOscillo(hOscillo, BBP.WIMdata)

'      // Compute both channel colors
       OkL = 0: OkR = 0
       nLpeak = nLpeak \ 320: nRpeak = nRpeak \ 320
       FOR K = 1 TO 100
           IF K <= nLpeak THEN
              C = K \ 3: gPeak(K,1) = gColor(C)
           ELSE
              IF gPeak(K,1) AND OkL = 0 THEN
                 gPeak(K,1) = SetRGB(gPeak(K,1)): IF OkL = 0 AND gPeak(K,1) = 0 THEN OkL = K
              ELSE
                 gPeak(K,1) = 0
              END IF
           END IF
           IF K <= nRpeak THEN
              C = K \ 3: gPeak(K,2) = gColor(C)
           ELSE
              IF gPeak(K,2) AND OkR = 0 THEN
                 gPeak(K,2) = SetRGB(gPeak(K,2)): IF OkR = 0 AND gPeak(K,2) = 0 THEN OkR = K
              ELSE
                 gPeak(K,2) = 0
              END IF
           END IF
       NEXT

'      // Draw both channels directly onto main window DC
       hDC = GetDC(zMainWindow(0))
       
          CALL GetClientRect(zMainWindow(0), rc)
          'nCell = 13: CellH = 3: CellW = 32: x = rc.nRight - 133: Y = 50
          IF hOscillo = 0 THEN
             nCell = 16: CellH = 3: CellW = 16: x = rc.nRight - 133 + 16: Y = 50
          ELSE
             nCell = 16: CellH = 3: CellW = 8: x = rc.nRight - (163 + 9): Y = 50
          END IF
          CALL GdipCreateFromHDC(hDC, graphics)
         
          'IF zGetCheckButtonStatus(zGetMainItem(%ID_AEROBLUR)) OR _
          '   zGetCheckButtonStatus(zGetMainItem(%ID_AEROCRYSTAL)) THEN
          '   InDWMmode = -1
          'ELSE
          '   InDWMmode = 0
          'END IF
          FOR K = nCell TO 1 STEP -1
              C = SolvePeak(K, nCell)
              'IF InDWMmode THEN
                 CALL zPaintBrushBitmap(hDC, x, y, CellW, CellH, zColorARGB(255, gPeak(C,1)))
                 IF hOscillo = 0 THEN
                    CALL zPaintBrushBitmap(hDC, x + CellW + CellH , y, CellW, CellH, zColorARGB(255, gPeak(C,2)))
                 ELSE
                    CALL zPaintBrushBitmap(hDC, x + 128 + 10 , y, CellW, CellH, zColorARGB(255, gPeak(C,2)))
                 END IF
              'ELSE
              '   CALL zsGdipFillRect(graphics&, x, y, CellW, CellH, zColorARGB(255, gPeak(C,1)) )
              '   CALL zsGdipFillRect(graphics&, x + 128 + 10 , y, CellW, CellH, zColorARGB(255, gPeak(C,2)) )
              'END IF
              y = y + CellH + 1
          NEXT
          CALL GdipDeleteGraphics(graphics&)
'         // End ViewMeter section

          IF hOscillo = 0 THEN
             LOCAL p AS POINTAPI
             STATIC xPos AS LONG, stepX AS LONG
             CALL GetWindowRect(glCtrl, rc)
             p.X = rc.nLeft: p.Y = rc.nTop
             CALL ScreenToClient(GetParent(glCtrl), p)
             x = p.X: y = p.Y + rc.nBottom - rc.nTop
             CellW = rc.nRight - rc.nLeft
             xPos = xPos + stepX
             CellW = CellW - 69 ' 30 + 2 + 20 + 2 + 15
             IF stepX = 0 THEN stepX = 1
             IF xPos > CellW THEN xPos = cellW: stepX = - stepX
             IF xPos < 0 THEN xPos = 0: stepX = - stepX
         
'            // Select active or inactive color
             IF nLpeak OR nRpeak THEN
                C1 = CG1: C2 = CG2: C3 = CG3
             ELSE
                C1 = CB1: C2 = CB2: C3 = CB3
             END IF
         
             IF stepX > 0 THEN
                CALL zPaintBrushBitmap(hDC, x, y, xPos, 2, C0)
                CALL zPaintBrushBitmap(hDC, x + xPos, y, 30, 1, C1)
                CALL zPaintBrushBitmap(hDC, x + xPos + 30 + 2, y, 20, 1, C2)
                CALL zPaintBrushBitmap(hDC, x + xPos + 50 + 4, y, 15, 1, C3)
             ELSE
                CALL zPaintBrushBitmap(hDC, x + xPos, y, 15, 1, C3)
                CALL zPaintBrushBitmap(hDC, x + xPos + 15 + 2, y, 20, 1, C2)
                CALL zPaintBrushBitmap(hDC, x + xPos + 35 + 4, y, 30, 1, C1)
             END IF
             CALL zPaintBrushBitmap(hDC, x + xPos + 50 + 4 + 15, y, CellW - xPos, 2, C0)
          END IF
         
       CALL ReleaseDC(zMainWindow(0), hDC)
'      --------------------------------------------------------------------


'      // Update the trackbar location
       IF gnAudioChannel THEN
          'IF TickCount < GetTickCount() + 1000 THEN       
          'TickCount = GetTickCount() + 1000
          INCR TickCount
          IF TickCount = 100 THEN
             gnMediaPos = BassChannelGetPos()
             CALL zSetTrackValue(zGetMainItem(%ID_TRACK_SEARCH), gnMediaPos)
             CALL zSetCTLText(zGetMainItem(%ID_ELLAPSED), BassAudioToTime(gnMediaPos))
             TickCount = 0
          END IF
       END IF

    END IF
    CALL ReleaseDC(glCtrl, glDC)

END SUB



And here is s screen shot of the CPU usage on my VISTA computer while using the FLASH plugin:



The result gives an average FPS of 34, that is almost the same than for a movie.

...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Emil Weiss

i have replace it ;)
thanks ;)

greets Emil

Patrice Terrier

#472
Here is another way to perform CPU usage reduction, and please tell me which one gives the best result on your system.


SUB RenderOpenGL(BYVAL glCtrl AS LONG)

    STATIC bFlip AS LONG
    bFlip = NOT bFlip

    IF IsWindowVisible(glCtrl) = 0 THEN EXIT SUB

    LOCAL graphics, nLevel, nLpeak, nRpeak, glDC, InDWMmode AS LONG
    LOCAL BBP AS BBPLUGIN
    LOCAL C1, C2, C3 AS LONG

    STATIC C0, CB1, CB2, CB3, CG1, CG2, CG3, TickCount, hOscillo AS LONG
    IF CB1 = 0 THEN
        C0 = zColorARGB(255, 0)
       CB1 = zColorARGB(255, RGB(0,23,66))
       CB2 = zColorARGB(255, RGB(0,37,103))
       CB3 = zColorARGB(255, RGB(0,74,201))
       CG1 = zColorARGB(255, RGB(0,66,23))
       CG2 = zColorARGB(255, RGB(0,103,37))
       CG3 = zColorARGB(255, RGB(0,201,74))
       hOscillo = zGetMainItem(%ID_OSCILLO)
    END IF

    glDC = GetDC(glCtrl)

    IF glRC THEN
       IF bFlip THEN
          nLevel = BassChannelGetLevel()

          nLpeak = SolvePeak(LO(WORD, nLevel), 128)
          nRpeak = SolvePeak(HI(WORD, nLevel), 128)

          BBP.Msg          = %BBP_RENDER
          BBP.ParentWindow = glCtrl
          BBP.DC           = glDC
          BBP.RC           = glRC
          BBP.Lpeak        = nLpeak
          BBP.Rpeak        = nRpeak
          BBP.BackARGB     = SK_AEROCOLOR()
          BBP.FFTdata      = BassChannelGetData()
          BBP.FFTsize      = 256
          BBP.MediaLength  = gnMediaLength
          BBP.MediaPos     = gnMediaPos
          BBP.WIMdata      = BassChannelGetWimData()

          CALL BBP_PLUGIN(BBP)

          '// Refresh display
          CALL SwapBuffers(glDC)
          CALL zUpdateWindow(glCtrl, 0)
          'CALL wglSwapBuffers(glDC)

          STATIC FPScount, nFPScount AS LONG
          INCR nFPScount
          IF FPScount = 0 THEN FPScount = GetTickCount() + 1000
          IF GetTickCount() > FPScount THEN
             FPScount = 0
             CALL zSetCTLText(zGetMainItem(%ID_FPS), ("FPS" + STR$(nFPScount)))
             nFPScount = 0
          END IF

       ELSE
'         --------------------------------------------------------------------
'         //Start drawing the ViewMeter's LED directly onto the main window DC
          LOCAL OkL, OkR, K, C, hDC, nCell, CellW, CellH, x, y AS LONG
          LOCAL rc AS RECT

          nLevel = BassChannelGetLevel()

          nLpeak = SolvePeak(LO(WORD, nLevel), 128)
          nRpeak = SolvePeak(HI(WORD, nLevel), 128)

          CALL DrawOscillo(hOscillo, BassChannelGetWimData())

'         // Compute both channel colors
          OkL = 0: OkR = 0
          nLpeak = nLpeak \ 320: nRpeak = nRpeak \ 320
          FOR K = 1 TO 100
              IF K <= nLpeak THEN
                 C = K \ 3: gPeak(K,1) = gColor(C)
              ELSE
                 IF gPeak(K,1) AND OkL = 0 THEN
                    gPeak(K,1) = SetRGB(gPeak(K,1)): IF OkL = 0 AND gPeak(K,1) = 0 THEN OkL = K
                 ELSE
                    gPeak(K,1) = 0
                 END IF
              END IF
              IF K <= nRpeak THEN
                 C = K \ 3: gPeak(K,2) = gColor(C)
              ELSE
                 IF gPeak(K,2) AND OkR = 0 THEN
                    gPeak(K,2) = SetRGB(gPeak(K,2)): IF OkR = 0 AND gPeak(K,2) = 0 THEN OkR = K
                 ELSE
                    gPeak(K,2) = 0
                 END IF
              END IF
          NEXT

'         // Draw both channels directly onto main window DC
          hDC = GetDC(zMainWindow(0))

             CALL GetClientRect(zMainWindow(0), rc)
             'nCell = 13: CellH = 3: CellW = 32: x = rc.nRight - 133: Y = 50
             IF hOscillo = 0 THEN
                nCell = 16: CellH = 3: CellW = 16: x = rc.nRight - 133 + 16: Y = 50
             ELSE
                nCell = 16: CellH = 3: CellW = 8: x = rc.nRight - (163 + 9): Y = 50
             END IF
             CALL GdipCreateFromHDC(hDC, graphics)

             'IF zGetCheckButtonStatus(zGetMainItem(%ID_AEROBLUR)) OR _
             '   zGetCheckButtonStatus(zGetMainItem(%ID_AEROCRYSTAL)) THEN
             '   InDWMmode = -1
             'ELSE
             '   InDWMmode = 0
             'END IF
             FOR K = nCell TO 1 STEP -1
                 C = SolvePeak(K, nCell)
                 'IF InDWMmode THEN
                    CALL zPaintBrushBitmap(hDC, x, y, CellW, CellH, zColorARGB(255, gPeak(C,1)))
                    IF hOscillo = 0 THEN
                       CALL zPaintBrushBitmap(hDC, x + CellW + CellH , y, CellW, CellH, zColorARGB(255, gPeak(C,2)))
                    ELSE
                       CALL zPaintBrushBitmap(hDC, x + 128 + 10 , y, CellW, CellH, zColorARGB(255, gPeak(C,2)))
                    END IF
                 'ELSE
                 '   CALL zsGdipFillRect(graphics&, x, y, CellW, CellH, zColorARGB(255, gPeak(C,1)) )
                 '   CALL zsGdipFillRect(graphics&, x + 128 + 10 , y, CellW, CellH, zColorARGB(255, gPeak(C,2)) )
                 'END IF
                 y = y + CellH + 1
             NEXT
             CALL GdipDeleteGraphics(graphics&)
'            // End ViewMeter section

             IF hOscillo = 0 THEN
                LOCAL p AS POINTAPI
                STATIC xPos AS LONG, stepX AS LONG
                CALL GetWindowRect(glCtrl, rc)
                p.X = rc.nLeft: p.Y = rc.nTop
                CALL ScreenToClient(GetParent(glCtrl), p)
                x = p.X: y = p.Y + rc.nBottom - rc.nTop
                CellW = rc.nRight - rc.nLeft
                xPos = xPos + stepX
                CellW = CellW - 69 ' 30 + 2 + 20 + 2 + 15
                IF stepX = 0 THEN stepX = 1
                IF xPos > CellW THEN xPos = cellW: stepX = - stepX
                IF xPos < 0 THEN xPos = 0: stepX = - stepX

'               // Select active or inactive color
                IF nLpeak OR nRpeak THEN
                   C1 = CG1: C2 = CG2: C3 = CG3
                ELSE
                   C1 = CB1: C2 = CB2: C3 = CB3
                END IF

                IF stepX > 0 THEN
                   CALL zPaintBrushBitmap(hDC, x, y, xPos, 2, C0)
                   CALL zPaintBrushBitmap(hDC, x + xPos, y, 30, 1, C1)
                   CALL zPaintBrushBitmap(hDC, x + xPos + 30 + 2, y, 20, 1, C2)
                   CALL zPaintBrushBitmap(hDC, x + xPos + 50 + 4, y, 15, 1, C3)
                ELSE
                   CALL zPaintBrushBitmap(hDC, x + xPos, y, 15, 1, C3)
                   CALL zPaintBrushBitmap(hDC, x + xPos + 15 + 2, y, 20, 1, C2)
                   CALL zPaintBrushBitmap(hDC, x + xPos + 35 + 4, y, 30, 1, C1)
                END IF
                CALL zPaintBrushBitmap(hDC, x + xPos + 50 + 4 + 15, y, CellW - xPos, 2, C0)
             END IF

          CALL ReleaseDC(zMainWindow(0), hDC)
'         --------------------------------------------------------------------

'         // Update the trackbar location
          IF gnAudioChannel THEN
             'IF TickCount < GetTickCount() + 1000 THEN
             'TickCount = GetTickCount() + 1000
             INCR TickCount
             IF TickCount = 100 THEN
                gnMediaPos = BassChannelGetPos()
                CALL zSetTrackValue(zGetMainItem(%ID_TRACK_SEARCH), gnMediaPos)
                CALL zSetCTLText(zGetMainItem(%ID_ELLAPSED), BassAudioToTime(gnMediaPos))
                TickCount = 0
             END IF
          END IF
       END IF
    END IF
    CALL ReleaseDC(glCtrl, glDC)

END SUB


The source code has been edited because left and right view meters were not redrawn anymore, this has been fixed, please cut and paste again in case you did it already.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Emil Weiss

#473
i have replace it ..
has no effect by me can not compile BassBox with no PowerBasic

wait for you has update the Archive

thanks

greets Emil

Patrice Terrier

You can get the latest public version there (compiled)

...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Jordi Vallès

Hi Patrice.
After apply your new code to reduce the CPU usage I can see perfectly the BassBox in my PC with Vista. The FPS indicates 33.

Thanks.
Jordi

Jordi Vallès

Hi Patrice.
Using the lastest compiled code that have FPS 66, the old problem with Windows Vista on my PC appears again. Seems that the problem is directly related with the amount of FPS.

Regards
Jordi 

Patrice Terrier

Jordi,

Then this is clearly related to the power (or underpower) of the graphic card being used.
Anyway, 34 FPS would be quite sufficient, because it is almost the same than for playing a movie (see MovieBox).

Thank you for sharing your feedback.

...


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Emil Weiss

Question..

Please can you make in the future when you have time ;)
Change BBP.Title to PluginFile

and added new
BBP.Title for SongFile

then make a great SongFile Animation like Milkdrop or other that can show in the Visualization
when change the FileTitle ?

greets Emil

Patrice Terrier

#479
The Phoenix

UnZip it in the BassBox BBPlugin folder, and enjoy.




...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com