why I cannot write a procedure in the loop event

Just starting out? Need help? Post your questions and find answers here.
det_uio
User
User
Posts: 14
Joined: Wed Jul 30, 2025 8:16 am

why I cannot write a procedure in the loop event

Post by det_uio »

Hello,

why I cannot write a procedure in the loop event (it crashes after 5-10 second). I have to write all the code from procedure in the loop.

It is just a procedure which takes the number of a gadget...

Crash code

Code: Select all

Procedure dessine(canva.l, x.l, Array moyennes.d(1)); 1 pOUR VECTEUR !!!
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(x+i, #h, x+i, #h-30, RGB(0, 0, 0))
  Next i
  StopDrawing()
  ProcedureReturn 0
EndProcedure
...


Global lastTime = ElapsedMilliseconds()
Repeat
  Event = WaitWindowEvent(10)
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0 ; Canvas gauche
          If EventType() = #PB_EventType_LeftClick
            x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
            y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
            ...
            
            
          EndIf
      EndSelect
  EndSelect
  
  ...
 res.i=dessine(0, pos, moyennes());
  
Until Event = #PB_Event_CloseWindow  ; If the user has pressed on the window close button
// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
Last edited by det_uio on Mon Aug 11, 2025 12:15 pm, edited 1 time in total.
Axolotl
Addict
Addict
Posts: 813
Joined: Wed Dec 31, 2008 3:36 pm

Re: why I cannot write a procedure in the loop event

Post by Axolotl »

Sorry, I can't test your code. It's incomplete. The code should at least be compilable.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
det_uio
User
User
Posts: 14
Joined: Wed Jul 30, 2025 8:16 am

Re: why I cannot write a procedure in the loop event

Post by det_uio »

here the code for windows

Bug code (from line 293).
Lib path are on lines 12 and 77
Wav path is in line 137

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sndfile ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; --- Constantes libsndfile ---
#SFM_READ = $10 ; Mode lecture pour sf_open (0x10)
#SFM_WRITE = $20
#SFM_RDWR = $30

#SEEK_SET = 0
#SEEK_CUR = 1
#SEEK_END = 2

; --- Importation des fonctions libsndfile ---
ImportC "sndfile.lib"
  sf_open(filename.p-utf8, mode.l, *sfinfo)
  ;   sf_open(filename.s, mode.l, *sfinfo)  ; filename.s = PureBasic String
  sf_strerror(*sndfile)
  sf_close(*sndfile)
  sf_read_float(*sndfile, *ptr_float, frames.q)
  sf_readf_float(*sndfile, *ptr_float, frames.q)
  sf_seek(*sndfile, pos.i, style.i);sf_count_t  sf_seek  (SNDFILE *sndfile, sf_count_t frames, int whence) ;
EndImport

; --- Structure SF_INFO de libsndfile ---
Structure SF_INFO Align #PB_Structure_AlignC
  frames.i       ; sf_count_t (nombre de frames) 8
  samplerate.l   ; int (fréquence d'échantillonnage) 4
  channels.l     ; int (nombre de canaux) 4
  format.l       ; int (format du fichier, ex: WAV, FLAC, etc.) 4
  sections.l     ; int (nombre de sections) 4
  seekable.l     ; int (indique si le fichier est seekable) 4
EndStructure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; portaudio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ==== Constantes ====
#paContinue = 0
#SampleRate = 44100
#FramesPerBuffer = 64
#TwoPi = 2 * #PI
#paFloat32 = $1
#paInt16   = $8
#paComplete = 1


Enumeration
  #paNoError = 0
  
  #paNotInitialized = -10000
  #paUnanticipatedHostError
  #paInvalidChannelCount
  #paInvalidSampleRate
  #paInvalidDevice
  #paInvalidFlag
  #paSampleFormatNotSupported
  #paBadIODeviceCombination
  #paInsufficientMemory
  #paBufferTooBig
  #paBufferTooSmall
  #paNullCallback
  #paBadStreamPtr
  #paTimedOut
  #paInternalError
  #paDeviceUnavailable
  #paIncompatibleHostApiSpecificStreamInfo
  #paStreamIsStopped
  #paStreamIsNotStopped
  #paInputOverflowed
  #paOutputUnderflowed
  #paHostApiNotFound
  #paInvalidHostApi
  #paCanNotReadFromACallbackStream
  #paCanNotWriteToACallbackStream
  #paCanNotReadFromAnOutputOnlyStream
  #paCanNotWriteToAnInputOnlyStream
  #paIncompatibleStreamHostApi
  #paBadBufferPtr
EndEnumeration

ImportC "portaudio_x64.lib"
  Pa_Initialize()
  Pa_Terminate()
  Pa_GetDeviceCount()
  Pa_GetDeviceInfo(i) ;const PaDeviceInfo * Pa_GetDeviceInfo (PaDeviceIndex device)
  Pa_GetHostApiInfo(q);const PaHostApiInfo * Pa_GetHostApiInfo (PaHostApiIndex hostApi)
  Pa_GetErrorText(i)  ;const char * Pa_GetErrorText (PaError errorCode)
  Pa_StartStream(*stream)
  Pa_StopStream(*stream)
  Pa_CloseStream(*stream)
  Pa_IsStreamActive(*stream)
  
  ;   typedef unsigned long PaSampleFormat;
  ;   PaError Pa_OpenDefaultStream (PaStream **stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData)
  Pa_OpenDefaultStream(*stream, inputChannels, outputChannels.l, sampleFormat.q, sampleRate.d, framesPerBuffer.q, *callback, *userData)
  
  Pa_Sleep(ms)
EndImport

Structure PaDeviceInfo Align #PB_Structure_AlignC
  structVersion.l               ;4 bytes
  *name                         ; 8 bytes
  hostApi.l                     ;4 bytes. int
  maxInputChannels.l            ;4 bytes
  maxOutputChannels.l           ;4 bytes
  defaultLowInputLatency.d      ; 8 bytes
  defaultLowOutputLatency.d     ; 8 bytes
  defaultHighInputLatency.d     ; 8 bytes
  defaultHighOutputLatency.d    ; 8 bytes
  defaultSampleRate.d           ; 8 bytes
EndStructure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#FRAMES_PER_BUFFER = 512

Structure PaData
  file.i         ; SNDFILE* (pointeur vers la structure SF_SNDFILE, un handle de fichier)
  info.SF_INFO   ; Informations sur le fichier audio
EndStructure

; === Callback audio ===
ProcedureC.l audio_callback(*inputBuffer, *outputBuffer, framesPerBuffer.q, *timeInfo, statusFlags.q, *userData)
  Protected *audioData.PaData = *userData
  Protected *audioOut.FLOAT = *outputBuffer
  Protected num_read.q
  Protected i.l, totalSamples.l, filtre.f, input.f
  
  totalSamples = framesPerBuffer * *audioData\info\channels
  
  num_read = sf_read_float(*audioData\file, *audioOut, totalSamples)
  
  ProcedureReturn #paContinue
EndProcedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; --- Déclaration des variables ---
Define audioData.PaData

Define filename.s = "_.wav" ; Chemin du fichier WAV

; --- Ouverture du fichier WAV ---
audioData\info\format = 0 ; Initialise le format à 0 comme requis par sf_open
audioData\file = sf_open(filename, #SFM_READ, @audioData\info) ; Passe l'adresse de la structure SF_INFO

; OpenConsole()

If audioData\file = 0
  ; Récupère le message d'erreur de libsndfile
  ; #Null est la constante PureBasic pour un pointeur nul, équivalent à NULL en C.
  Define *error_str.Ascii = sf_strerror(#Null)
  ;   PrintN("Erreur lors de l'ouverture du fichier WAV : " + PeekS(*error_str, -1, #PB_Ascii))
  Debug("Erreur lors de l'ouverture du fichier WAV : " + PeekS(*error_str, -1, #PB_Ascii))
  End
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

nbreEchantillonCanalGauche = audioData\info\frames
#w = 1000
#h = 200
nbFrameParPixel = nbreEchantillonCanalGauche / #w
; Debug("nbFrameParPixel : " + Str(nbFrameParPixel))
nAlire.i = nbFrameParPixel*2; stéréo
Dim tamp.f(nAlire)
Dim moyennes.d(#w)
uneMoyenne.d
*p = @tamp(0)
i.i=0
k.i
k = sf_read_float(audioData\file, *p, nAlire); on a lu les 2 canaux gauches et droits
While k=nAlire
  ;     Debug Str(i)+"   "+Str(nAlire)+"   "+Str(k)
  uneMoyenne=0
  For m = 0 To nAlire - 1
    uneMoyenne + Abs(PeekF(*p + (m) * SizeOf(Float)))
  Next m
  uneMoyenne/nAlire
  moyennes(i)=uneMoyenne
  k = sf_read_float(audioData\file, *p, nAlire)
  i+1
Wend

; trouver le max
max.d=moyennes(0)
For i = 0 To #w-1
  If max < moyennes(i)
    max = moyennes(i)
  EndIf
Next i
;normaliser
For i = 0 To #w-1
  moyennes(i) / max
  moyennes(i) * #h
Next i


OpenWindow(0, 100, 100, #w, #h, "2D Drawing Test")
CanvasGadget(0, 0, 0, DesktopScaledX(#w), DesktopScaledY(#h))

Procedure dessine(canva.l, x.l, Array moyennes.d(1)); 1 pOUR VECTEUR !!!
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(x+i, #h, x+i, #h-30, RGB(0, 0, 0))
  Next i
  StopDrawing()
  ProcedureReturn 0
EndProcedure

dessine(0, 10, moyennes())

sf_seek(audioData\file, 0, #SEEK_SET);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


If Pa_Initialize() <> 0
  MessageRequester("Erreur", "Erreur initialisation PortAudio")
  sf_close(audioData\file)
  End
EndIf

Define *stream

If Pa_OpenDefaultStream(@*stream, 0, audioData\info\channels, #paFloat32, audioData\info\samplerate, #FRAMES_PER_BUFFER, @audio_callback(), @audioData) <> 0
  MessageRequester("Erreur", "Erreur ouverture flux audio")
  Pa_Terminate()
  sf_close(audioData\file)
  End
EndIf

If Pa_StartStream(*stream) <> 0
  MessageRequester("Erreur", "Erreur démarrage flux")
  Pa_CloseStream(*stream)
  Pa_Terminate()
  sf_close(audioData\file)
  End
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Debug("Fichier WAV '" + GetFilePart(filename) + "' ouvert avec succès.")
; Debug("Fréquence d'échantillonnage : " + Str(audioData\info\samplerate) + " Hz")
; Debug("Canaux : " + Str(audioData\info\channels))
; Debug("Nombre total de frames : " + Str(audioData\info\frames))

; Structure Fenetre
;   w.l
;   h.l
;   *go
; EndStructure

; Procedure Parler_Chat(*this.Fenetre)
;   ;   Debug *this\nom + " : Miaou !"
;   
; EndProcedure
; 
; fen.Fenetre
; fen\w=1000
; fen\h=200

; AddWindowTimer(0, 0, 100) ; Timeout = 10 ms

Global lastTime = ElapsedMilliseconds()
Repeat
  Event = WaitWindowEvent(10)
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0 ; Canvas gauche
          If EventType() = #PB_EventType_LeftClick
            x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
            y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
            pourc.f = x / #w
            pourc.f * audioData\info\frames
            pos.i = Int(pourc)
            sf_seek(audioData\file, pos, #SEEK_SET)
;             Debug pourc
            Debug "Clic sur gauche: X=" + Str(x) + " Y=" + Str(y)
            
          EndIf 
      EndSelect
  EndSelect
  
  pos.i = sf_seek(audioData\file, 0, #SEEK_CUR);
  pourc.f = pos / audioData\info\frames * 1.0
  pos=Int(pourc*#w)
  
  res.i=dessine(0, pos, moyennes()); bug avec 10 donc en bas
  
;   ; refaire le graphique
;   StartDrawing(CanvasOutput(canva))
;   Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
;   For i = 0 To #w-1
;     LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
;   Next i
;   
;   ; tracer la barre de position
;   For i = 0 To 5
;     LineXY(pos+i, #h, pos+i, 0, RGB(0, 0, 0))
;   Next i
;   StopDrawing()
  
  If ElapsedMilliseconds() - lastTime >= 1000
    lastTime = ElapsedMilliseconds()
    ;     Debug "Événement déclenché à " + FormatDate("%hh:%ii:%ss", Date())
    ;     Debug even
    ;     Debug #PB_Event_CloseWindow
  EndIf
Until Event = #PB_Event_CloseWindow  ; If the user has pressed on the window close button



; === Boucle lecture audio ===
; Repeat
;   Pa_Sleep(10)
; ForEver

; === Nettoyage ===
Pa_StopStream(*stream)
Pa_CloseStream(*stream)
Pa_Terminate()
sf_close(audioData\file)

; Debug("Fichier WAV fermé.")


; Else
;   MessageRequester("Erreur", "Impossible d'ouvrir la console.")

; CloseConsole()

End


The code without bug (not using procedure in event loop):

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sndfile ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; --- Constantes libsndfile ---
#SFM_READ = $10 ; Mode lecture pour sf_open (0x10)
#SFM_WRITE = $20
#SFM_RDWR = $30

#SEEK_SET = 0
#SEEK_CUR = 1
#SEEK_END = 2

; --- Importation des fonctions libsndfile ---
ImportC "sndfile.lib"
  sf_open(filename.p-utf8, mode.l, *sfinfo)
  ;   sf_open(filename.s, mode.l, *sfinfo)  ; filename.s = PureBasic String
  sf_strerror(*sndfile)
  sf_close(*sndfile)
  sf_read_float(*sndfile, *ptr_float, frames.q)
  sf_readf_float(*sndfile, *ptr_float, frames.q)
  sf_seek(*sndfile, pos.i, style.i);sf_count_t  sf_seek  (SNDFILE *sndfile, sf_count_t frames, int whence) ;
EndImport

; --- Structure SF_INFO de libsndfile ---
Structure SF_INFO Align #PB_Structure_AlignC
  frames.i       ; sf_count_t (nombre de frames) 8
  samplerate.l   ; int (fréquence d'échantillonnage) 4
  channels.l     ; int (nombre de canaux) 4
  format.l       ; int (format du fichier, ex: WAV, FLAC, etc.) 4
  sections.l     ; int (nombre de sections) 4
  seekable.l     ; int (indique si le fichier est seekable) 4
EndStructure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; portaudio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ==== Constantes ====
#paContinue = 0
#SampleRate = 44100
#FramesPerBuffer = 64
#TwoPi = 2 * #PI
#paFloat32 = $1
#paInt16   = $8
#paComplete = 1


Enumeration
  #paNoError = 0
  
  #paNotInitialized = -10000
  #paUnanticipatedHostError
  #paInvalidChannelCount
  #paInvalidSampleRate
  #paInvalidDevice
  #paInvalidFlag
  #paSampleFormatNotSupported
  #paBadIODeviceCombination
  #paInsufficientMemory
  #paBufferTooBig
  #paBufferTooSmall
  #paNullCallback
  #paBadStreamPtr
  #paTimedOut
  #paInternalError
  #paDeviceUnavailable
  #paIncompatibleHostApiSpecificStreamInfo
  #paStreamIsStopped
  #paStreamIsNotStopped
  #paInputOverflowed
  #paOutputUnderflowed
  #paHostApiNotFound
  #paInvalidHostApi
  #paCanNotReadFromACallbackStream
  #paCanNotWriteToACallbackStream
  #paCanNotReadFromAnOutputOnlyStream
  #paCanNotWriteToAnInputOnlyStream
  #paIncompatibleStreamHostApi
  #paBadBufferPtr
EndEnumeration

ImportC "portaudio_x64.lib"
  Pa_Initialize()
  Pa_Terminate()
  Pa_GetDeviceCount()
  Pa_GetDeviceInfo(i) ;const PaDeviceInfo * Pa_GetDeviceInfo (PaDeviceIndex device)
  Pa_GetHostApiInfo(q);const PaHostApiInfo * Pa_GetHostApiInfo (PaHostApiIndex hostApi)
  Pa_GetErrorText(i)  ;const char * Pa_GetErrorText (PaError errorCode)
  Pa_StartStream(*stream)
  Pa_StopStream(*stream)
  Pa_CloseStream(*stream)
  Pa_IsStreamActive(*stream)
  
  ;   typedef unsigned long PaSampleFormat;
  ;   PaError Pa_OpenDefaultStream (PaStream **stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData)
  Pa_OpenDefaultStream(*stream, inputChannels, outputChannels.l, sampleFormat.q, sampleRate.d, framesPerBuffer.q, *callback, *userData)
  
  Pa_Sleep(ms)
EndImport

Structure PaDeviceInfo Align #PB_Structure_AlignC
  structVersion.l               ;4 bytes
  *name                         ; 8 bytes
  hostApi.l                     ;4 bytes. int
  maxInputChannels.l            ;4 bytes
  maxOutputChannels.l           ;4 bytes
  defaultLowInputLatency.d      ; 8 bytes
  defaultLowOutputLatency.d     ; 8 bytes
  defaultHighInputLatency.d     ; 8 bytes
  defaultHighOutputLatency.d    ; 8 bytes
  defaultSampleRate.d           ; 8 bytes
EndStructure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#FRAMES_PER_BUFFER = 512

Structure PaData
  file.i         ; SNDFILE* (pointeur vers la structure SF_SNDFILE, un handle de fichier)
  info.SF_INFO   ; Informations sur le fichier audio
EndStructure

; === Callback audio ===
ProcedureC.l audio_callback(*inputBuffer, *outputBuffer, framesPerBuffer.q, *timeInfo, statusFlags.q, *userData)
  Protected *audioData.PaData = *userData
  Protected *audioOut.FLOAT = *outputBuffer
  Protected num_read.q
  Protected i.l, totalSamples.l, filtre.f, input.f
  
  totalSamples = framesPerBuffer * *audioData\info\channels
  
  num_read = sf_read_float(*audioData\file, *audioOut, totalSamples)
  
  ProcedureReturn #paContinue
EndProcedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; --- Déclaration des variables ---
Define audioData.PaData

Define filename.s = "_.wav" ; Chemin du fichier WAV

; --- Ouverture du fichier WAV ---
audioData\info\format = 0 ; Initialise le format à 0 comme requis par sf_open
audioData\file = sf_open(filename, #SFM_READ, @audioData\info) ; Passe l'adresse de la structure SF_INFO

; OpenConsole()

If audioData\file = 0
  ; Récupère le message d'erreur de libsndfile
  ; #Null est la constante PureBasic pour un pointeur nul, équivalent à NULL en C.
  Define *error_str.Ascii = sf_strerror(#Null)
  ;   PrintN("Erreur lors de l'ouverture du fichier WAV : " + PeekS(*error_str, -1, #PB_Ascii))
  Debug("Erreur lors de l'ouverture du fichier WAV : " + PeekS(*error_str, -1, #PB_Ascii))
  End
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

nbreEchantillonCanalGauche = audioData\info\frames
#w = 1000
#h = 200
nbFrameParPixel = nbreEchantillonCanalGauche / #w
; Debug("nbFrameParPixel : " + Str(nbFrameParPixel))
nAlire.i = nbFrameParPixel*2; stéréo
Dim tamp.f(nAlire)
Dim moyennes.d(#w)
uneMoyenne.d
*p = @tamp(0)
i.i=0
k.i
k = sf_read_float(audioData\file, *p, nAlire); on a lu les 2 canaux gauches et droits
While k=nAlire
  ;     Debug Str(i)+"   "+Str(nAlire)+"   "+Str(k)
  uneMoyenne=0
  For m = 0 To nAlire - 1
    uneMoyenne + Abs(PeekF(*p + (m) * SizeOf(Float)))
  Next m
  uneMoyenne/nAlire
  moyennes(i)=uneMoyenne
  k = sf_read_float(audioData\file, *p, nAlire)
  i+1
Wend

; trouver le max
max.d=moyennes(0)
For i = 0 To #w-1
  If max < moyennes(i)
    max = moyennes(i)
  EndIf
Next i
;normaliser
For i = 0 To #w-1
  moyennes(i) / max
  moyennes(i) * #h
Next i


OpenWindow(0, 100, 100, #w, #h, "2D Drawing Test")
CanvasGadget(0, 0, 0, DesktopScaledX(#w), DesktopScaledY(#h))

Procedure dessine(canva.l, x.l, Array moyennes.d(1)); 1 pOUR VECTEUR !!!
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(x+i, #h, x+i, #h-30, RGB(0, 0, 0))
  Next i
  StopDrawing()
  ProcedureReturn 0
EndProcedure

dessine(0, 10, moyennes())

sf_seek(audioData\file, 0, #SEEK_SET);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


If Pa_Initialize() <> 0
  MessageRequester("Erreur", "Erreur initialisation PortAudio")
  sf_close(audioData\file)
  End
EndIf

Define *stream

If Pa_OpenDefaultStream(@*stream, 0, audioData\info\channels, #paFloat32, audioData\info\samplerate, #FRAMES_PER_BUFFER, @audio_callback(), @audioData) <> 0
  MessageRequester("Erreur", "Erreur ouverture flux audio")
  Pa_Terminate()
  sf_close(audioData\file)
  End
EndIf

If Pa_StartStream(*stream) <> 0
  MessageRequester("Erreur", "Erreur démarrage flux")
  Pa_CloseStream(*stream)
  Pa_Terminate()
  sf_close(audioData\file)
  End
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Debug("Fichier WAV '" + GetFilePart(filename) + "' ouvert avec succès.")
; Debug("Fréquence d'échantillonnage : " + Str(audioData\info\samplerate) + " Hz")
; Debug("Canaux : " + Str(audioData\info\channels))
; Debug("Nombre total de frames : " + Str(audioData\info\frames))

; Structure Fenetre
;   w.l
;   h.l
;   *go
; EndStructure

; Procedure Parler_Chat(*this.Fenetre)
;   ;   Debug *this\nom + " : Miaou !"
;   
; EndProcedure
; 
; fen.Fenetre
; fen\w=1000
; fen\h=200

; AddWindowTimer(0, 0, 100) ; Timeout = 10 ms

Global lastTime = ElapsedMilliseconds()
Repeat
  Event = WaitWindowEvent(10)
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0 ; Canvas gauche
          If EventType() = #PB_EventType_LeftClick
            x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
            y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
            pourc.f = x / #w
            pourc.f * audioData\info\frames
            pos.i = Int(pourc)
            sf_seek(audioData\file, pos, #SEEK_SET)
;             Debug pourc
            Debug "Clic sur gauche: X=" + Str(x) + " Y=" + Str(y)
            
          EndIf 
      EndSelect
  EndSelect
  
  pos.i = sf_seek(audioData\file, 0, #SEEK_CUR);
  pourc.f = pos / audioData\info\frames * 1.0
  pos=Int(pourc*#w)
  
;       res.i=dessine(0, pos, moyennes()); bug avec 10 donc en bas
  
  ; refaire le graphique
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(pos+i, #h, pos+i, 0, RGB(0, 0, 0))
  Next i
  StopDrawing()
  
  If ElapsedMilliseconds() - lastTime >= 1000
    lastTime = ElapsedMilliseconds()
    ;     Debug "Événement déclenché à " + FormatDate("%hh:%ii:%ss", Date())
    ;     Debug even
    ;     Debug #PB_Event_CloseWindow
  EndIf
Until Event = #PB_Event_CloseWindow  ; If the user has pressed on the window close button



; === Boucle lecture audio ===
; Repeat
;   Pa_Sleep(10)
; ForEver

; === Nettoyage ===
Pa_StopStream(*stream)
Pa_CloseStream(*stream)
Pa_Terminate()
sf_close(audioData\file)

; Debug("Fichier WAV fermé.")


; Else
;   MessageRequester("Erreur", "Impossible d'ouvrir la console.")

; CloseConsole()

End
User avatar
NicTheQuick
Addict
Addict
Posts: 1510
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: why I cannot write a procedure in the loop event

Post by NicTheQuick »

If you change the content of any gadget it usually generates multiple new window events that have to be handled by the event loop. And when you change the gadget in each loop it will continue to create more events that you are able to handle which results in visible issues.

So better only call your `dessine()` procedure if there are no events at all (meaning Event = 0) or using a `AddWindowTimer()`.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
IceSoft
Addict
Addict
Posts: 1692
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: why I cannot write a procedure in the loop event

Post by IceSoft »

---------------------------
PureBasic - Linker error
---------------------------
error: could not open 'sndfile.lib': no such file or directory

lld-link: error: could not open 'portaudio_x64.lib': no such file or directory
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
det_uio
User
User
Posts: 14
Joined: Wed Jul 30, 2025 8:16 am

Re: why I cannot write a procedure in the loop event

Post by det_uio »

here the Mac code if you want. Just install port audio and libsndfile with brew.
Else compile portaudio with visual studio. I got the dll and .lib.and If you want I give the lib on GitHub. Tell me...

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sndfile ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; --- Constantes libsndfile ---
#SFM_READ = $10 ; Mode lecture pour sf_open (0x10)
#SFM_WRITE = $20
#SFM_RDWR = $30

#SEEK_SET = 0
#SEEK_CUR = 1
#SEEK_END = 2

; --- Importation des fonctions libsndfile ---
ImportC "/opt/homebrew/Cellar/libsndfile/1.2.2_1/lib/libsndfile.1.0.37.dylib"
  sf_open(filename.p-utf8, mode.l, *sfinfo)
  ;   sf_open(filename.s, mode.l, *sfinfo)  ; filename.s = PureBasic String
  sf_strerror(*sndfile)
  sf_close(*sndfile)
  sf_read_float(*sndfile, *ptr_float, frames.q)
  sf_readf_float(*sndfile, *ptr_float, frames.q)
  sf_seek(*sndfile, pos.i, style.i);sf_count_t  sf_seek  (SNDFILE *sndfile, sf_count_t frames, int whence) ;
EndImport

; --- Structure SF_INFO de libsndfile ---
Structure SF_INFO Align #PB_Structure_AlignC
  frames.i       ; sf_count_t (nombre de frames) 8
  samplerate.l   ; int (fréquence d'échantillonnage) 4
  channels.l     ; int (nombre de canaux) 4
  format.l       ; int (format du fichier, ex: WAV, FLAC, etc.) 4
  sections.l     ; int (nombre de sections) 4
  seekable.l     ; int (indique si le fichier est seekable) 4
EndStructure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; portaudio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ==== Constantes ====
#paContinue = 0
#SampleRate = 44100
#FramesPerBuffer = 64
#TwoPi = 2 * #PI
#paFloat32 = $1
#paInt16   = $8
#paComplete = 1


Enumeration
  #paNoError = 0
  
  #paNotInitialized = -10000
  #paUnanticipatedHostError
  #paInvalidChannelCount
  #paInvalidSampleRate
  #paInvalidDevice
  #paInvalidFlag
  #paSampleFormatNotSupported
  #paBadIODeviceCombination
  #paInsufficientMemory
  #paBufferTooBig
  #paBufferTooSmall
  #paNullCallback
  #paBadStreamPtr
  #paTimedOut
  #paInternalError
  #paDeviceUnavailable
  #paIncompatibleHostApiSpecificStreamInfo
  #paStreamIsStopped
  #paStreamIsNotStopped
  #paInputOverflowed
  #paOutputUnderflowed
  #paHostApiNotFound
  #paInvalidHostApi
  #paCanNotReadFromACallbackStream
  #paCanNotWriteToACallbackStream
  #paCanNotReadFromAnOutputOnlyStream
  #paCanNotWriteToAnInputOnlyStream
  #paIncompatibleStreamHostApi
  #paBadBufferPtr
EndEnumeration

ImportC "/opt/homebrew/Cellar/portaudio/19.7.0/lib/libportaudio.dylib"
  Pa_Initialize()
  Pa_Terminate()
  Pa_GetDeviceCount()
  Pa_GetDeviceInfo(i) ;const PaDeviceInfo * Pa_GetDeviceInfo (PaDeviceIndex device)
  Pa_GetHostApiInfo(q);const PaHostApiInfo * Pa_GetHostApiInfo (PaHostApiIndex hostApi)
  Pa_GetErrorText(i)  ;const char * Pa_GetErrorText (PaError errorCode)
  Pa_StartStream(*stream)
  Pa_StopStream(*stream)
  Pa_CloseStream(*stream)
  Pa_IsStreamActive(*stream)
  
  ;   typedef unsigned long PaSampleFormat;
  ;   PaError Pa_OpenDefaultStream (PaStream **stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData)
  Pa_OpenDefaultStream(*stream, inputChannels, outputChannels.l, sampleFormat.q, sampleRate.d, framesPerBuffer.q, *callback, *userData)
  
  Pa_Sleep(ms)
EndImport

Structure PaDeviceInfo Align #PB_Structure_AlignC
  structVersion.l               ;4 bytes
  *name                         ; 8 bytes
  hostApi.l                     ;4 bytes. int
  maxInputChannels.l            ;4 bytes
  maxOutputChannels.l           ;4 bytes
  defaultLowInputLatency.d      ; 8 bytes
  defaultLowOutputLatency.d     ; 8 bytes
  defaultHighInputLatency.d     ; 8 bytes
  defaultHighOutputLatency.d    ; 8 bytes
  defaultSampleRate.d           ; 8 bytes
EndStructure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#FRAMES_PER_BUFFER = 512

Structure PaData
  file.i         ; SNDFILE* (pointeur vers la structure SF_SNDFILE, un handle de fichier)
  info.SF_INFO   ; Informations sur le fichier audio
EndStructure

; === Callback audio ===
ProcedureC.l audio_callback(*inputBuffer, *outputBuffer, framesPerBuffer.q, *timeInfo, statusFlags.q, *userData)
  Protected *audioData.PaData = *userData
  Protected *audioOut.FLOAT = *outputBuffer
  Protected num_read.q
  Protected i.l, totalSamples.l, filtre.f, input.f
  
  totalSamples = framesPerBuffer * *audioData\info\channels
  
  num_read = sf_read_float(*audioData\file, *audioOut, totalSamples)
  
  ProcedureReturn #paContinue
EndProcedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; --- Déclaration des variables ---
Define audioData.PaData

Define filename.s = "/Users/uio/Music/test.wav" ; Chemin du fichier WAV

; --- Ouverture du fichier WAV ---
audioData\info\format = 0 ; Initialise le format à 0 comme requis par sf_open
audioData\file = sf_open(filename, #SFM_READ, @audioData\info) ; Passe l'adresse de la structure SF_INFO

; OpenConsole()

If audioData\file = 0
  ; Récupère le message d'erreur de libsndfile
  ; #Null est la constante PureBasic pour un pointeur nul, équivalent à NULL en C.
  Define *error_str.Ascii = sf_strerror(#Null)
  ;   PrintN("Erreur lors de l'ouverture du fichier WAV : " + PeekS(*error_str, -1, #PB_Ascii))
  Debug("Erreur lors de l'ouverture du fichier WAV : " + PeekS(*error_str, -1, #PB_Ascii))
  End
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

nbreEchantillonCanalGauche = audioData\info\frames
#w = 1000
#h = 200
nbFrameParPixel = nbreEchantillonCanalGauche / #w
; Debug("nbFrameParPixel : " + Str(nbFrameParPixel))
nAlire.i = nbFrameParPixel*2; stéréo
Dim tamp.f(nAlire)
Dim moyennes.d(#w)
uneMoyenne.d
*p = @tamp(0)
i.i=0
k.i
k = sf_read_float(audioData\file, *p, nAlire); on a lu les 2 canaux gauches et droits
While k=nAlire
  ;     Debug Str(i)+"   "+Str(nAlire)+"   "+Str(k)
  uneMoyenne=0
  For m = 0 To nAlire - 1
    uneMoyenne + Abs(PeekF(*p + (m) * SizeOf(Float)))
  Next m
  uneMoyenne/nAlire
  moyennes(i)=uneMoyenne
  k = sf_read_float(audioData\file, *p, nAlire)
  i+1
Wend

; trouver le max
max.d=moyennes(0)
For i = 0 To #w-1
  If max < moyennes(i)
    max = moyennes(i)
  EndIf
Next i
;normaliser
For i = 0 To #w-1
  moyennes(i) / max
  moyennes(i) * #h
Next i


OpenWindow(0, 100, 100, #w, #h, "2D Drawing Test")
CanvasGadget(0, 0, 0, DesktopScaledX(#w), DesktopScaledY(#h))

Procedure dessine(canva.l, x.l, Array moyennes.d(1)); 1 pOUR VECTEUR !!!
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(x+i, #h, x+i, #h-30, RGB(0, 0, 0))
  Next i
  StopDrawing()
  ProcedureReturn 0
EndProcedure

dessine(0, 10, moyennes())

sf_seek(audioData\file, 0, #SEEK_SET);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


If Pa_Initialize() <> 0
  MessageRequester("Erreur", "Erreur initialisation PortAudio")
  sf_close(audioData\file)
  End
EndIf

Define *stream

If Pa_OpenDefaultStream(@*stream, 0, audioData\info\channels, #paFloat32, audioData\info\samplerate, #FRAMES_PER_BUFFER, @audio_callback(), @audioData) <> 0
  MessageRequester("Erreur", "Erreur ouverture flux audio")
  Pa_Terminate()
  sf_close(audioData\file)
  End
EndIf

If Pa_StartStream(*stream) <> 0
  MessageRequester("Erreur", "Erreur démarrage flux")
  Pa_CloseStream(*stream)
  Pa_Terminate()
  sf_close(audioData\file)
  End
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Debug("Fichier WAV '" + GetFilePart(filename) + "' ouvert avec succès.")
; Debug("Fréquence d'échantillonnage : " + Str(audioData\info\samplerate) + " Hz")
; Debug("Canaux : " + Str(audioData\info\channels))
; Debug("Nombre total de frames : " + Str(audioData\info\frames))

; Structure Fenetre
;   w.l
;   h.l
;   *go
; EndStructure

; Procedure Parler_Chat(*this.Fenetre)
;   ;   Debug *this\nom + " : Miaou !"
;   
; EndProcedure
; 
; fen.Fenetre
; fen\w=1000
; fen\h=200

; AddWindowTimer(0, 0, 100) ; Timeout = 10 ms

Global lastTime = ElapsedMilliseconds()
Repeat
  Event = WaitWindowEvent(10)
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0 ; Canvas gauche
          If EventType() = #PB_EventType_LeftClick
            x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
            y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
            pourc.f = x / #w
            pourc.f * audioData\info\frames
            pos.i = Int(pourc)
            sf_seek(audioData\file, pos, #SEEK_SET)
;             Debug pourc
;             Debug "Clic sur gauche: X=" + Str(x) + " Y=" + Str(y)
            
          EndIf
      EndSelect
  EndSelect
  
  pos.i = sf_seek(audioData\file, 0, #SEEK_CUR);
  pourc.f = pos / audioData\info\frames * 1.0
  pos=Int(pourc*#w)
  
  ;     res.i=dessine(0, pos, moyennes()); bug avec 10 donc en bas
  
  ; refaire le graphique
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(pos+i, #h, pos+i, 0, RGB(0, 0, 0))
  Next i
  StopDrawing()
  
  If ElapsedMilliseconds() - lastTime >= 1000
    lastTime = ElapsedMilliseconds()
    ;     Debug "Événement déclenché à " + FormatDate("%hh:%ii:%ss", Date())
    ;     Debug even
    ;     Debug #PB_Event_CloseWindow
  EndIf
Until Event = #PB_Event_CloseWindow  ; If the user has pressed on the window close button



; === Boucle lecture audio ===
; Repeat
;   Pa_Sleep(10)
; ForEver

; === Nettoyage ===
Pa_StopStream(*stream)
Pa_CloseStream(*stream)
Pa_Terminate()
sf_close(audioData\file)

; Debug("Fichier WAV fermé.")


; Else
;   MessageRequester("Erreur", "Impossible d'ouvrir la console.")

; CloseConsole()

End
Axolotl
Addict
Addict
Posts: 813
Joined: Wed Dec 31, 2008 3:36 pm

Re: why I cannot write a procedure in the loop event

Post by Axolotl »

Still not compilable. Missing libs.

My observations after a quick read (without knowledge of French):
I cannot see huge differences, only different types pos.i and x.l (should not be a problem)
1. You should boil it down to the essentials.
2. Use return values on procedure calls
3. Debug some variables (e.g. different tiypes pos.i -> x.l)
4. Event Loop (not my style), but works (mostly?)
5. IMHO your code is very unstructured, hard to read.

I'm sorry, but I can't help you any further by now.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Axolotl
Addict
Addict
Posts: 813
Joined: Wed Dec 31, 2008 3:36 pm

Re: why I cannot write a procedure in the loop event

Post by Axolotl »

Ohh, well I am on windows ....
And then we are definitely in the wrong section.

Have you tried this instead of calling the proc always (on every event, not only every 10ms)?

Code: Select all


AddWindowTimer(0, 0, 10) ; 10ms is min possible time out value on windows. 
; ... 
    Case #PB_Event_Timer 
      Select EventTimer() 
        Case 0 ; Timer Number 
          pos.i   = sf_seek(audioData\file, 0, #SEEK_CUR);
          pourc.f = pos / audioData\info\frames * 1.0
          pos     = Int(pourc*#w)
  
          res.i = dessine(0, pos, moyennes()); bug avec 10 donc en bas
      EndSelect 
; ... 
RemoveWindowTimer(0, 0) 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
det_uio
User
User
Posts: 14
Joined: Wed Jul 30, 2025 8:16 am

Re: why I cannot write a procedure in the loop event

Post by det_uio »

Yes, I have tried but without success. 100 value seems ok ...
User avatar
spikey
Enthusiast
Enthusiast
Posts: 756
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: why I cannot write a procedure in the loop event

Post by spikey »

I can't test for certain because I can't run the code, as others have already observed, but looking at it I would expect that you are overflowing the event queue because your drawing activity is taking up too much time.

When something occurs in an application, an event is added to the queue. When an event is processed by the application, it is removed from the queue. On Windows the queue can hold 10000 events (by default). The queue length must be limited because otherwise a faulty program would consume all the system RAM and cause the whole system to fail out of memory.

If an application is only just keeping up with processing incoming events the queue will max out and the application will lag behind the user's actions. If it can't keep up with processing events the queue will fill up and new events will stop being queued until the queue length drops below maximum again.

If the operating system spots that an application's queue is stuck around maximum for more than a few seconds and it doesn't appear to be removing events from the queue the OS will deem the application to be unresponsive and will react accordingly.

In your case you are redrawing every single time an event occurs regardless of whether or not this is event is meaningful and requires a redraw. Drawing is "slow" in microprocessor timescales - it's a human timescale activity and you are not taking into account the difference between timescales.

As has been suggested you need to redraw less often - your application will need to be more intelligent about when you redraw. For example only redraw when data is known to have altered, or if you are following a stream, update in a human timescale.
det_uio
User
User
Posts: 14
Joined: Wed Jul 30, 2025 8:16 am

Re: why I cannot write a procedure in the loop event

Post by det_uio »

To be more precise, it blocks in the return of the function. It's like it doesn't like the context of the procedure in the loop.

During execution it put in red the line:
ProcedureReturn 0

from this code:

Code: Select all

Debug "monCanva  : "+Str(monCanva) 
Procedure dessine(canva.i, x.l, Array moyennes.d(1)); 1 pOUR VECTEUR !!!
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(x+i, #h, x+i, #h-30, RGB(0, 0, 0))
  Next i
  StopDrawing()
  ProcedureReturn 0
EndProcedure
User avatar
mk-soft
Always Here
Always Here
Posts: 6224
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: why I cannot write a procedure in the loop event

Post by mk-soft »

@det_uio

Please do not immediately write everything in the bug reports.

If something doesn't work yet, first ask in the forum "Code Questions". Then we check if it is a bug of PureBasic

Thanks so much
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
det_uio
User
User
Posts: 14
Joined: Wed Jul 30, 2025 8:16 am

Re: why I cannot write a procedure in the loop event

Post by det_uio »

I have posted in "Coding questions". viewtopic.php?t=87295

Here the GitHub project :
https://github.com/AudioNiceMicroContro ... -show-play
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: why I cannot write a procedure in the loop event

Post by RASHAD »

Can't test it ,it's a miss :)

Change ProcedureReturn 0 to ProcedureReturn 1
I hope it will be OK

Code: Select all

Procedure dessine(canva.i, x.l, Array moyennes.d(1)); 1 pOUR VECTEUR !!!
  StartDrawing(CanvasOutput(canva))
  Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF) ; efface en blanc
  For i = 0 To #w-1
    LineXY(i, #h, i, #h-moyennes(i), RGB(0, 152, 0))
  Next i
  
  ; tracer la barre de position
  For i = 0 To 5
    LineXY(x+i, #h, x+i, #h-30, RGB(0, 0, 0))
  Next i
  StopDrawing()
  ProcedureReturn 1
EndProcedure
Egypt my love
dcr3
Enthusiast
Enthusiast
Posts: 183
Joined: Fri Aug 04, 2017 11:03 pm

Re: why I cannot write a procedure in the loop event

Post by dcr3 »

det_uio wrote: Mon Aug 11, 2025 11:42 am (it crashes after 5-10 second)
One observation , different .wav size,the crash happens at different intervals.
Post Reply