DMO Audio FX using FilterGraph
Posted: Thu Aug 18, 2005 9:20 am
Code updated For 5.20+
I've been playing around with some Audio Effects via FilterGraph. Maybe someone could find it useful and improve it (I'm just a beginner).
Esteban1
I've been playing around with some Audio Effects via FilterGraph. Maybe someone could find it useful and improve it (I'm just a beginner).
Code: Select all
;/ A little example of using DMO Audio FX in a FilterGraph
;/ By Esteban1
;/ 08-18-2005
#CLSCTX_INPROC_SERVER = $1
; #INFINITE = $FFFFFFFF
Structure CAUUID ; this structure is used to retrieve property pages collection
cElems.l ; here goes the number of property pages
*pElems.GUID[10] ; and here is where all the collection is stored
EndStructure
CoInitialize_(0)
If CoCreateInstance_(?CLSID_FilterGraph, #Null,#CLSCTX_INPROC_SERVER,?IID_IGraphBuilder,@GraphBuilder.IGraphBuilder)=0 ; First we create a FilterGraph object
GraphBuilder\QueryInterface(?IID_IMediaControl,@MediaControl.IMediaControl) ; then we get the MediaControl interface
GraphBuilder\QueryInterface(?IID_IMediaEventEx, @MediaEvents.IMediaEventEx) ; and the MediaEvent interface
GraphBuilder\Release()
If CoCreateInstance_(?CLSID_DMOWrapperFilter, #Null, #CLSCTX_INPROC_SERVER,?IID_IBaseFilter,@DMOFilter.IBaseFilter)=0 ; Create a DMOWrapperFilter object
DMOFilter\QueryInterface(?IID_IDMOWrapperFilter,@DMOWrapperFilter.IDMOWrapperFilter) ; get the Wrapper interface
; Here you can put the CLSID corresponding to the DMO Filter you want
; I choose CLSID_Flanger for example, but you can put CLSID_Chorus, CLSID_Compressor, CLSID_Distortion,
; CLSID_Echo, CLSID_Flanger, CLSID_Gargler, CLSID_I3DL2Reverb, CLSID_ParamEq and CLSID_WavesReberv. It's up to you!
DMOWrapperFilter\init(?CLSID_Flanger,?DMOCATEGORY_AUDIO_EFFECT) ; and asign the DMO Filter we want
DMOWrapperFilter\Release();
GraphBuilder\AddFilter(DMOFilter, @"DMOFilter") ; and of course, add it to the FilterGraph
DMOFilter\Release()
EndIf
wav.s= OpenFileRequester("Please choose WAV file", "","Audio files | *.wav; *.wma", 0 ) ; self explained
If wav.s<>""
Dim MyFile.w(Len(wav))
MultiByteToWideChar_(#CP_ACP, 0, wav, -1, MyFile(), Len(wav)) ; just convert from ansi to widechar
MediaControl\RenderFile(PeekS(@myfile(),#PB_Unicode)) ; and let the FilterGraph do the magic! (intelligent connect)
MediaControl\Run() ; play it
; If you want to modify the properties of the effect...
If DMOFilter\QueryInterface(?IID_ISpecifyPropertyPages,@SpecifyProperty.ISpecifyPropertyPages)=0 ; get the Specify Property Pages interface
SpecifyProperty\GetPages(@CAUUID.CAUUID) ; retrieve Property Pages (DMO has only one per filter)
If CAUUID\cElems > 0 ; if there are any Property Pages
title.s="PureBasic DMO Effects" ; let's set the title of the window
Dim title.w(Len(title))
MultiByteToWideChar_(#CP_ACP, 0, title, -1, title(), Len(title))
OleCreatePropertyFrame_(GetDesktopWindow_(), 100, 100,@title(), 1, @DMOFilter, CAUUID\cElems,CAUUID\pElems, 0, 0, #Null ) ; and show it
EndIf
SpecifyProperty\Release()
EndIf
Repeat ; now we must check for the events
MediaEvents\GetEvent(@EventCode, @Param1, @Param2,0) ; self explained too
Delay(10)
MediaEvents\FreeEventParams(EventCode, Param1, lParam2)
Until EventCode=1 ; repeat until the audio finish
MediaControl\Stop()
EndIf
MediaControl\Release() ; and free resources
MediaEvents\Release()
EndIf
CoUninitialize_()
DataSection
CLSID_FilterGraph:
Data.l $E436EBB3
Data.w $524F,$11CE
Data.b $9F,$53,$00,$20,$AF,$0B,$A7,$70
IID_IGraphBuilder:
Data.l $56A868A9
Data.w $0AD4,$11CE
Data.b $B0,$3A,$00,$20,$AF,$0B,$A7,$70
CLSID_Chorus:
Data.l $EFE6629C
Data.w $81F7,$4281
Data.b $BD,$91,$C9,$D6,$4,$A9,$5A,$F6
CLSID_Compressor:
Data.l $EF011F79
Data.w $4000,$406D
Data.b $87,$AF,$BF,$FB,$3F,$C3,$9D,$57
CLSID_Distortion:
Data.l $EF114C90
Data.w $CD1D,$484E
Data.b $96,$E5,$9,$CF,$AF,$91,$2A,$21
CLSID_Echo:
Data.l $EF3E932C
Data.w $D40B,$4F51
Data.b $8C,$CF,$3F,$98,$F1,$B2,$9D,$5D
CLSID_Flanger:
Data.l $EFCA3D92
Data.w $DFD8,$4672
Data.b $A6,$3,$74,$20,$89,$4B,$AD,$98
CLSID_Gargler:
Data.l $DAFD8210
Data.w $5711,$4B91
Data.b $9F,$E3,$F7,$5B,$7A,$E2,$79,$BF
CLSID_I3DL2Reverb:
Data.l $EF985E71
Data.w $D5C7,$42D4
Data.b $BA,$4D,$2D,$7,$3E,$2E,$96,$F4
CLSID_ParamEq:
Data.l $120CED89
Data.w $3BF4,$4173
Data.b $A1,$32,$3C,$B4,$6,$CF,$32,$31
CLSID_WavesReberv:
Data.l $87FC0268
Data.w $9A55,$4360
Data.b $95,$AA,$0,$4A,$1D,$9D,$E2,$6C
CLSID_DMOWrapperFilter:
Data.l $94297043
Data.w $BD82,$4DFD
Data.b $B0,$DE,$81,$77,$73,$9C,$6D,$20
IID_IDMOWrapperFilter:
Data.l $52D6F586
Data.w $9F0F,$4824
Data.b $8F,$C8,$E3,$2C,$A0,$49,$30,$C2
DMOCATEGORY_AUDIO_EFFECT:
Data.l $D990EE14
Data.w $776C,$4723
Data.b $BE,$46,$3D,$A2,$F5,$6F,$10,$B9
IID_IBaseFilter:
Data.l $56A86895
Data.w $0AD4,$11CE
Data.b $B0,$3A,$00,$20,$AF,$0B,$A7,$70
IID_IMediaControl:
Data.l $56A868B1
Data.w $0AD4,$11CE
Data.b $B0,$3A,$00,$20,$AF,$0B,$A7,$70
IID_IMediaEventEx:
Data.l $56A868C0
Data.w $0AD4,$11CE
Data.b $B0,$3A,$00,$20,$AF,$0B,$A7,$70
IID_ISpecifyPropertyPages:
Data.l $B196B28B
Data.w $BAB4,$101A
Data.b $B6,$9C,$0,$AA,$0,$34,$1D,$7
EndDataSection