Seite 1 von 1

Musik grafisch darstellen ???

Verfasst: 05.02.2005 13:07
von Graffiti
Hallo ich möchte ein Musikstück grafisch darstellen und evtl. Positionen einfügen können
(wie in einem Musikbearbeitungsprogramm)

hat jemand eine Idee oder einen Beispielcode ?

gruß Graffiti

Verfasst: 05.02.2005 17:11
von nicolaus
grafisch darstellen kannst du recht einfach machen und beispiele gibts dazu auch und zwar wenn du dir mal die FMOD.dll anschaust. Such einfach mal hier im forum da finest du einiges dazu.

Verfasst: 06.02.2005 01:44
von Graffiti
also im Forum habe ich diesbezüglich nichts gefunden,
ich möchte auch keine Aussteuerungsanzeige basteln.

die FMod.dll möchte ich eigentlich auch nicht dazunehmen da ich bisher in meinem Proggi alles über MCI Steuerbefehle programiert habe,
aber ich werdemir die DLL mal ansehen vielleicht hilfts ja

Verfasst: 06.02.2005 15:44
von Lukaso
Hab hier nen beispiel von Froggenprogger das hat mir auch geholfen :mrgreen:

Code: Alles auswählen

; FMOD - FFT-example
;
; this small example shows how to use the FFT of FMOD.
;
; this program is written for FMOD 3.74 and needs the FMOD-Wrapper for PureBasic to compile
;
; by Froggerprogger, 23.01.05



;______________ Declarations ::

Declare updateFFT() ; declares the Proc

Structure fftarray ;the structure for the FSOUND_DSP_GetSpectrum()
    value.f[512] 
EndStructure 

If InitSprite() = 0 ; Try to open DirectX
    MessageRequester("","Sorry, problem with InitSprite() - no DirectX 7.0 ?",0):End 
EndIf 

hwnd=OpenWindow(1,0,0,520,264,#PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Mini-FFT-Spectrum Visualization using FMOD") 
OpenWindowedScreen(hwnd,4,60,512,200,0,0,0) ; opens a screen on the window

CreateSprite(1,512,200,0) ; creates a temporarily sprite

FSOUND_SetBufferSize(125) ;in- or decrease, if you want to

;initialize FMOD and create menu + gadgets 
If hwnd <> 0 And FSOUND_Init(44100, 32, 0) And CreateMenu(1,hwnd) And CreateGadgetList(hwnd) 
  MenuItem(1, "open") 
  MenuItem(2, "play") 
  MenuItem(3,"stop") 
  TextGadget(1,5,10,512,20,"Music-File:   " + soundfile.s,0)  
  resume.b=1 
EndIf 

;_____________  Main Prog ::
While resume 
  updateFFT()
  Select WindowEvent() 
    Case #PB_EventMenu ; (select a menu item...)
      Select EventMenuID() 
        Case 1 ;(Open) 
          temp_filename.s = OpenFileRequester("Choose a music-file...","C:\","PCM-MusicFiles (*.mp3, *.wav, *.mp2, *.ogg, *.raw)|*.mp3;*.wav;*.mp2;*.ogg;*.raw|*.*|*.*",0,0) 
          If temp_filename  
              soundfile.s = temp_filename  
              SetGadgetText(1,soundfile)  
          EndIf 
        Case 2 ;(Play) 
         hstream = FSOUND_Stream_Open(soundfile,0,0,0) ;open the soundfile 
         If hstream <> 0 
             FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), #True) ;activate the FastFourierTransformation-DSP-Unit 
             FSOUND_Stream_Play(1,hstream) ;play the stream on channel 1 
         EndIf 
        Case 3 ;(Stop) 
            For i=255 To 0 Step -1 ;a small fast fade-out to prevent a clipping-sound 
              FSOUND_SetVolume(1,i) 
            Next 
            FSOUND_Stream_Stop(hstream) ;stop playing the stream 
            FSOUND_SetVolume(1,255) ;reset volume to max 
      EndSelect 

    Case #PB_Event_CloseWindow ; (systemmenu close...) 
      resume=0 
      FSOUND_Stream_Stop(hstream) ;stop playing the stream 
      FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), #False) ;set the FFT-DSP-Unit inactive 
      FSOUND_Close() ;shut down FSOUND 
   EndSelect 
Wend 

;The following procedure updates and displays the fft-visualisation 
Procedure updateFFT() 
            If FSOUND_DSP_GetActive(FSOUND_DSP_GetFFTUnit()) 
                CopyMemory(FSOUND_DSP_GetSpectrum(), hfft.fftarray, 4*512) 
            EndIf 
            StartDrawing(SpriteOutput(1)) ;Starts Drawing on the sprite
                Box(0,0,512,200,$000000) 
                For i=0 To 511 
                    actfftvalue.f = hfft\value[i]*199 ;linear y-scale
                    Box(i,200,1,-1-actfftvalue, (255-actfftvalue) * $000100 + actfftvalue * $000001) ;Draw a line with various colors, linear x-scale
                    DrawingMode(1) ; sets Text background transparent
                    FrontColor(255,255,255) ;white of course 
                    cpuusage.s="CPU: "+StrF(FSOUND_GetCPUUsage(),1)+" %" ;create CPU-String
                    Locate(508 - TextLength(cpuusage), 4) ;position upper right
                    DrawText(cpuusage) ;draw the text
                Next 
            StopDrawing() ;Stops drawing on the sprite
            FlipBuffers() 
            DisplaySprite(1,0,0) ; display the sprite
EndProcedure
MFG Lukaso