Nun habe ich aber ein Problem, zu dem ich nichts finden konnte:
Vor ein paar Monaten habe ich (aus dem englischen Forum) einen Codeschnipsel gefunden und daraus so etwas wie eine Visualiesierung programmiert. Diese Funktioniert auch Prima, wie ich finde. Jedoch... Es handelt sich um Prozeduren, die, mit Hilfe von WinAPI-Befehlen, auf das Mikrofon zugreifen. Also funktioniert meine Visualisierung zwar mit jedem mediaplayer, aber eben nur über das Mikrofon... wenn ich nun über das Headset Musik höre, geht das leider nicht. Meine Frage: Könnte sich Jemand, der sich mit WinAPI auskennt, den Code der Procedures anschauen und mir sagen, ob das nicht auch mit dem "AudioOut" funktionieren könnte? Achja! Erschwerend kommt noch dazu, dass ich diese Procedures nicht verstehe ich habe mir nur einen Wert davon abgegriffen, der die Lautstärke, der Geräusche, die durch das Mikrofon empfangen werden, in eine Zahl verwandelt..
Wenn es gewünscht wird, kann ich den kompletten Code irgendwo hochladen.
hier die Procedures:
Code: Alles auswählen
#SAMPLE_RATE = 44100
#N_SAMPLES = 8192 ;NUMBER OF SAMPLES
#WINDOW_WIDTH = 1920 ;+ 300 ; full scale (5000) / resolution
#WINDOW_HEIGHT = 1080
#TRACE_COLOR = $20DA42
#BACK_COLOR = $004720
#GRID_COLOR = 0
#Canvas = 0
#Graticule = 0 ; image
Structure MYWAVEFORMATEX
wFormatTag.u ;UNSIGNED FOR COMPATIBILITY WITH MICROSOFT FLAG VALUES
nChannels.w
nSamplesPerSec.l
nAvgBytesPerSec.l
nBlockAlign.w
wBitsPerSample.w
cbSize.w
EndStructure
Global FFTWnd, smoothing, initSmoothing = #True
Structure CONFIG
hWindow.i ; Window handle
size.i ; Wave buffer size
buffer.i ; Wave buffer pointer
wave.i ; Address of waveform-audio input device
format.MYWAVEFORMATEX ; Capturing WaveFormatEx
lBuf.i ; Capturing Buffer size
nBuf.i ; Capturing Buffer number
nDev.i ; Capturing Device identifier
nBit.i ; Capturing Resolution (8/16)
nHertz.i ; Capturing Frequency (Hertz)
nChannel.i ; Capturing Channels number (Mono/Stereo)
EndStructure
Global Config.CONFIG
Global Dim inHdr.WAVEHDR(16)
Config\format\wFormatTag = #WAVE_FORMAT_PCM
Procedure CAPTURE_START()
Config\format\nChannels=1
Config\format\wBitsPerSample = 16
Config\format\nSamplesPerSec = #SAMPLE_RATE
Config\nDev = 0 ; (default MS Sound Mapper device)
Config\lBuf = #N_SAMPLES
Config\nBuf = 8
Config\nBit = 1
Config\format\nBlockAlign = (Config\format\nChannels * Config\format\wBitsPerSample)/8
Config\format\nAvgBytesPerSec = Config\format\nSamplesPerSec * Config\format\nBlockAlign
If #MMSYSERR_NOERROR = waveInOpen_(@Config\wave, #WAVE_MAPPER+Config\nDev, @Config\format,Config\hWindow, #Null, #CALLBACK_WINDOW | #WAVE_FORMAT_DIRECT)
For i=0 To Config\nBuf-1
inHdr(i)\lpData=AllocateMemory(Config\lBuf)
inHdr(i)\dwBufferLength=Config\lBuf
waveInPrepareHeader_(Config\wave, inHdr(i), SizeOf(WAVEHDR))
waveInAddBuffer_(Config\wave, inHdr(i), SizeOf(WAVEHDR))
Next
waveInStart_(Config\wave)
EndIf
EndProcedure
EnableExplicit
Procedure COMPLEX_FFT()
; http://paulbourke.net/miscellaneous/dft/
; Appendix B. FFT (Fast Fourier Transform)
; This computes an in-place complex-To-complex FFT
; Real And Imag are the real And imaginary arrays of 2^m points.
Static Dim Real.d(#N_SAMPLES)
Static Dim Imag.d(#N_SAMPLES)
Static Dim SmSum(#WINDOW_WIDTH-1)
Static Dim Sm_Buff(#WINDOW_WIDTH-1,31) ; max smoothing = 32
Static SmIDX = 0
Static NM1 = #N_SAMPLES - 1
Static ND2 = #N_SAMPLES >> 1
Static Hscale.f = 0.0 + (#SAMPLE_RATE / #N_SAMPLES)
Global Ergebnis.f
Protected mask = smoothing - 1
;Protected M = Int(Log(#N_SAMPLES) / Log(2))
Protected.i M = Int(Log(#N_SAMPLES) / 0.69314718055994529)
Protected.i i, IP, j, k, n, LE2, LE, Imax, y, Ly, peak_Y, peak_X
Protected.d C1, C2, TR, TI, UR, UI, ZZ
If initSmoothing : initSmoothing = #False
i = 0 ; init smoothing buffers
While i < #WINDOW_WIDTH : k = 0
While k < smoothing : Sm_Buff(i,k) = #WINDOW_HEIGHT : k + 1 : Wend
SmSum(i) = #WINDOW_HEIGHT * smoothing
i + 1
Wend
EndIf
; -------- Clear and Fill array values for analyzing --------
i = 0 : j = ND2 : k = 0
While k < Config\size
Real(i) = PeekW(Config\buffer + k) ; 0 to SAMPLES/2 - 1
Imag(i) = 0 ; 0 to SAMPLES/2 - 1
Real(j) = 0 ; SAMPLES/2 to SAMPLES
Imag(j) = 0 ; SAMPLES/2 to SAMPLES
i + 1 : j + 1 : k + 2
Wend
j = 0
Imax = #N_SAMPLES - 2
For i = 0 To Imax ; Gold-Rader bit reversal algorithm
If i < j
Swap Real(i),Real(j)
;Swap Imag(i), Imag(j) ; both are zero
EndIf
k = ND2
While k <= j
j = j - k
k = k >> 1
Wend
j = j + k
Next
; Compute the FFT
C1 = -1.0
C2 = 0.0
LE = 1
For n = 1 To M
LE2 = LE
LE << 1
UR = 1.0
UI = 0.0
k = 0
While k < LE2 : i = k
While i < #N_SAMPLES ; Loop for each butterfly calculation
IP = i + LE2
TR = Real(IP) * UR - Imag(IP) * UI
TI = Imag(IP) * UR + Real(IP) * UI
Real(IP) = Real(i) - TR
Imag(IP) = Imag(i) - TI
Real(i) + TR
Imag(i) + TI
i + LE
Wend
ZZ = UR * c1 - UI * C2
UI = UR * c2 + UI * C1
UR = ZZ
k + 1
Wend
C2 = Sqr((1.0 - C1) / 2.0)
C1 = Sqr((1.0 + C1) / 2.0)
Next n
For i = 0 To NM1 ; Scaling For forward transform
Real(i) = Abs(Real(i) / #N_SAMPLES)
;Imag(i) = Abs(Imag(i) / #N_SAMPLES) ; we don't use this
Next
Ly = #WINDOW_HEIGHT
i = 0 : peak_Y = #WINDOW_HEIGHT
While i < #WINDOW_WIDTH
y = #WINDOW_HEIGHT - Log(Real(i)+1) * 64 ; 64 is arbitrary
If smoothing
SmSum(i) - Sm_Buff(i,SmIDX)
Sm_Buff(i,SmIDX) = y
SmSum(i) + y
y = SmSum(i) / smoothing ; this is the moving average
EndIf
; LineXY(i-1,Ly,i,y,#TRACE_COLOR) : Ly = y
If y < peak_Y : peak_Y = y : peak_X = i : EndIf
i + 1
Wend
; Circle(peak_X, peak_Y, 3, #Red)
Ergebnis = peak_X * Hscale;+" Hz"
If smoothing : SmIDX = (SmIDX + 1) & mask : EndIf
; StopDrawing()
ProcedureReturn #True
EndProcedure
DisableExplicit
Procedure CAPTURE_CALLBACK(hWnd.i, Msg.i, wParam.i, lParam.i)
If Msg = #MM_WIM_DATA
*hWave.WAVEHDR = lParam
Config\buffer = *hWave\lpData
Config\size = *hWave\dwBytesRecorded
waveInAddBuffer_(wParam, *hWave, SizeOf(WAVEHDR))
COMPLEX_FFT()
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure