1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| CONSTANT
BassDLL = "Bass"
AudioCap = "Audiocap"
GDI32 = "GDI32"
END
BITMAPINFOHEADER is structure
biSize is int //Type C : DWORD
biWidth is int //Type C : LONG
biHeight is int //Type C : LONG
biPlanes is 2-byte int //Type C : WORD
biBitCount is 2-byte int //Type C : WORD
biCompression is int //Type C : DWORD
biSizeImage is int //Type C : DWORD
biXPelsPerMeter is int //Type C : LONG
biYPelsPerMeter is int //Type C : LONG
biClrUsed is int //Type C : DWORD
biClrImportant is int //Type C : DWORD
END
RGBQUAD is structure
B is character //Type C : BYTE
G is character //Type C : BYTE
R is character //Type C : BYTE
rgbReserved is character //Type C : BYTE
END
BITMAPINFO is structure
bmiHeader is BITMAPINFOHEADER //BITMAPINFOHEADER est une autre structure
bmiColors is RGBQUAD //RGBQUAD est une autre structure
END
FUNCTION LevelColr(LOCAL nLevel is int)
COLORBYTES is structure
B is 1-byte unsigned int
G is 1-byte unsigned int
R is 1-byte unsigned int
Alpha is 1-byte unsigned int
END
nC is COLORBYTES
nColor is int = 0
nLevel += 1; IF nLevel > 33 THEN nLevel =33
IF nLevel > 0 THEN
SWITCH nLevel
CASE 1: nC.R = 32; nC.G = 32; nC.B = 32
CASE 2: nC.R = 0; nC.G = 44; nC.B = 233
CASE 3: nC.R = 0; nC.G = 67; nC.B = 210
CASE 4: nC.R = 0; nC.G = 89; nC.B = 187
CASE 5: nC.R = 0; nC.G = 112; nC.B = 164
CASE 6: nC.R = 0; nC.G = 135; nC.B = 142
CASE 7: nC.R = 0; nC.G = 159; nC.B = 117
CASE 8: nC.R = 0; nC.G = 183; nC.B = 88
CASE 9: nC.R = 0; nC.G = 207; nC.B = 58
CASE 10: nC.R = 0; nC.G = 231; nC.B = 29
CASE 11: nC.R = 26; nC.G = 234; nC.B = 26
CASE 12: nC.R = 52; nC.G = 237; nC.B = 23
CASE 13: nC.R = 79; nC.G = 240; nC.B = 20
CASE 14: nC.R = 105; nC.G = 243; nC.B = 17
CASE 15: nC.R = 126; nC.G = 245; nC.B = 14
CASE 16: nC.R = 147; nC.G = 248; nC.B = 11
CASE 17: nC.R = 168; nC.G = 250; nC.B = 8
CASE 18: nC.R = 189; nC.G = 253; nC.B = 5
CASE 19: nC.R = 210; nC.G = 255; nC.B = 2
CASE 20: nC.R = 233; nC.G = 255; nC.B = 0
CASE 21: nC.R = 255; nC.G = 255; nC.B = 0
CASE 22: nC.R = 255; nC.G = 251; nC.B = 0
CASE 23: nC.R = 255; nC.G = 235; nC.B = 0
CASE 24: nC.R = 255; nC.G = 215; nC.B = 0
CASE 25: nC.R = 255; nC.G = 196; nC.B = 0
CASE 26: nC.R = 255; nC.G = 176; nC.B = 0
CASE 27: nC.R = 255; nC.G = 156; nC.B = 0
CASE 28: nC.R = 253; nC.G = 137; nC.B = 0
CASE 29: nC.R = 255; nC.G = 117; nC.B = 0
CASE 30: nC.R = 255; nC.G = 97; nC.B = 0
CASE 31: nC.R = 255; nC.G = 78; nC.B = 0
CASE 32: nC.R = 255; nC.G = 58; nC.B = 0
OTHER CASE
nC.R = 255; nC.B = 0; nC.B = 0
END
nC.Alpha = 255
Transfer(&nColor, &nC, 4)
END
RESULT nColor
PROCEDURE ScanPeaks(LOCAL sAudioFile is string)
nScanChannel is unsigned int = BASS_StreamCreateFile(False, sAudioFile, 0, 0, BASS_STREAM_DECODE)
hIC is int
bi is MYBITMAPINFO
nX, nY, nXpos, nLevel, nLpeak, nRpeak, nBpp, nHalfHeight, nL, nR, nLP, nRP are int
rCoef is 4-byte real
SCANWIDTH is int = SoundMap..Width
SCANHEIGHT is int = SoundMap..Height
bi.bmiHeader.biSize = Dimension(bi.bmiHeader)
bi.bmiHeader.biWidth = SCANWIDTH
bi.bmiHeader.biHeight = - SCANHEIGHT // Put top IN TOP instead on bottom!
bi.bmiHeader.biPlanes = 1
bi.bmiHeader.biBitCount = 32
bi.bmiHeader.biCompression = 0 // BI_RGB
nBpp = API(BassDLL, "BASS_ChannelGetLength", nScanChannel, BASS_POS_BYTE) / SCANWIDTH // bytes per pixel
nHalfHeight = SCANHEIGHT / 2
IF ghScanDC = 0 THEN
hIC = API(GDI32, "CreateICA", "DISPLAY", 0, 0, 0)
ghScanDC = API(GDI32, "CreateCompatibleDC", hIC)
ghScanDIB = API(GDI32, "CreateDIBSection", ghScanDC, &bi, 0, 0, 0, 0)
API(GDI32, "SelectObject", ghScanDC, ghScanDIB)
API(GDI32, "DeleteDC", hIC)
END
PixelArray is array of SCANHEIGHT by SCANWIDTH int
rCoef = 33 / nHalfHeight
LOOP
nLevel = API(BassDLL, "BASS_ChannelGetLevel", nScanChannel) // scan peaks
nLP = LoWord(nLevel)
nRP = HiWord(nLevel)
IF nLpeak < nLP THEN nLpeak = nLP // set Left peak
IF nRpeak < nRP THEN nRpeak = nRP // set Right peak
IF API(BassDLL, "BASS_ChannelIsActive", nScanChannel) = 0 THEN
nX = -1 // reached the END
ELSE
nX = BASS_ChannelGetPosition(nScanChannel, BASS_POS_BYTE) / nBpp
END
IF nX > nXpos THEN
nL = (nLpeak * nHalfHeight / 32768) - 1
nR = (nRpeak * nHalfHeight / 32768) - 1
nMax is int = Max(nL, nR)
FOR nY = 0 TO nMax
IF nY < nL + 1 THEN PixelArray[nHalfHeight - nY, nX] = LevelColr(rCoef * nY)
IF nY < nR + 1 THEN PixelArray[nHalfHeight + nY + 1, nX] = LevelColr(rCoef * nY)
Multitask(-1)
END
IF nX >= SCANWIDTH - 1 THEN BREAK // gone off end of display
nXpos = nX
nLpeak = 0; nRpeak = 0
END
END
API(GDI32, "SetDIBits", ghScanDC, ghScanDIB, 0, SCANHEIGHT, &PixelArray, &bi, 0)
API(GDI32, "BitBlt", dStartDrawing(SoundMap), 0, 0, SCANWIDTH, SCANHEIGHT, ghScanDC, 0, 0, 0x00CC0020)
UpdateWindow(Handle(SoundMap)) // Champ image WinDev
API(BassDLL, "BASS_StreamFree", nScanChannel) // free the decoder |
Partager