bibliothèque portaudio "accès mémoire invalide"
Publié : lun. 16/juin/2025 23:59
Bonsoir ,
Bibliothèque portaudio "accès mémoire invalide".
Le programme affiche bien le nombre de périphérique mais il bloque à cette ligne :
Debug "Périphérique " + Str(i) + " : " + PeekS(*deviceInfo\name, -1, #PB_Ascii)
J'ai vérifié la structure transposée à PureBasic et elle me semble correcte.
Voici le programme
Bibliothèque portaudio "accès mémoire invalide".
Le programme affiche bien le nombre de périphérique mais il bloque à cette ligne :
Debug "Périphérique " + Str(i) + " : " + PeekS(*deviceInfo\name, -1, #PB_Ascii)
J'ai vérifié la structure transposée à PureBasic et elle me semble correcte.
Voici le programme
Code : Tout sélectionner
; Nécessite PortAudio installé (libportaudio.dylib accessible)
EnableExplicit
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(device.l) ;typedef int PaDeviceIndex;
Pa_GetHostApiInfo(hostApi.l) ;typedef int PaHostApiIndex;
Pa_GetErrorText(errorCode.l) ; typedef int PaError;
EndImport
Debug "test d'erreur n° " + #paBadBufferPtr
; Obtenir le texte d'erreur pour une constante
Define *errorText = Pa_GetErrorText(#paBadBufferPtr)
Debug PeekS(*errorText, -1, #PB_Ascii)
;End
Structure PaDeviceInfo
structVersion.l ;int structVersion
name.i ; ✅ pointeur vers chaîne ASCII (correct pour PeekS)
hostApi.l ;typedef int PaHostApiIndex;
maxInputChannels.l ;int maxInputChannels
maxOutputChannels.l;int maxOutputChannels
defaultLowInputLatency.d ; typedef double PaTime;
defaultLowOutputLatency.d; typedef double PaTime;
defaultHighInputLatency.d; typedef double PaTime;
defaultHighOutputLatency.d ; typedef double PaTime;
defaultSampleRate.d ;double defaultSampleRate
EndStructure
Structure PaHostApiInfo
structVersion.l;int structVersion
type.i ; typedef enum PaHostApiTypeId
name.i ;const char * name
deviceCount.l ;int deviceCount
defaultInputDevice.l;typedef int PaDeviceIndex;
defaultOutputDevice.l;typedef int PaDeviceIndex;
EndStructure
Define.i err, numDevices, i
Define *deviceInfo.PaDeviceInfo
Define *hostApiInfo.PaHostApiInfo
err = Pa_Initialize()
If err <> 0
MessageRequester("Erreur", "Erreur lors de l'initialisation : " + PeekS(Pa_GetErrorText(err), -1, #PB_Ascii))
End
EndIf
numDevices = Pa_GetDeviceCount()
If numDevices < 0
MessageRequester("Erreur", "Erreur lors de la récupération des périphériques : " + PeekS(Pa_GetErrorText(numDevices), -1, #PB_Ascii))
Pa_Terminate()
End
EndIf
Debug "Nombre de périphériques audio trouvés : " + Str(numDevices)
Debug ""
Procedure DebugMemory(*addr, size.l)
Debug Str(size.l) + " "
Protected i, hex$, ascii$, byte.b, N.i
N = 16
For i = 0 To size - 1
If i % N = 0
If i > 0
;Debug " i : " + Str(i)
Debug hex$ + " " + ascii$
EndIf
hex$ = RSet(Hex(*addr + i), 12, "0") + " : "; écrire sur 12 et remplir de 0 à gauche
ascii$ = ""
EndIf
byte = PeekB(*addr + i)
hex$ + RSet(Hex(byte & $FF), 2, "0") + " "
If byte >= 32 And byte <= 126
ascii$ + Chr(byte)
Else
ascii$ + "."
EndIf
Next
If size > 0
Debug "fin"
Debug hex$ + " " + ascii$
EndIf
EndProcedure
For i = 0 To numDevices - 1
*deviceInfo.PaDeviceInfo = Pa_GetDeviceInfo(i)
If *deviceInfo = #Null
Debug "Erreur: deviceInfo null pour l'appareil " + Str(i)
Continue
EndIf
; Vérification supplémentaire pour le nom du périphérique
If *deviceInfo\name = #Null
Debug "Périphérique " + Str(i) + " : [Nom non disponible]"
Else
Debug "Périphérique " + Str(i) + " : " + PeekS(*deviceInfo\name, -1, #PB_Ascii)
EndIf
; Debug de la structure complète
;Debug "=== Dump mémoire deviceInfo ==="
;DebugMemory(*deviceInfo, SizeOf(PaDeviceInfo))
Next
Pa_Terminate()