Ho tolto l'allegato ed Inserisco il codice aperto a tutti, precisando che esso ha ormai solo un valore
, da museo.
Private handle As Pointer
Library "libasound:2"
Const SND_PCM_STREAM_PLAYBACK As Integer = 0
Const SND_PCM_FORMAT_U8 As Integer = 1
Const SND_PCM_ACCESS_RW_INTERLEAVED As Integer = 3
' int snd_pcm_open (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)
' Opens a PCM.
Private Extern snd_pcm_open(pcm As Pointer, name As String, stream As Integer, mode As Integer) As Integer
' int snd_pcm_set_params(snd_pcm_t * pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned Int latency)
' Set the hardware and software parameters in a simple way.
Private Extern snd_pcm_set_params(pcm As Pointer, formatInt As Integer, accesso As Integer, channels As Integer, rate As Integer, soft_resample As Integer, latency As Integer) As Integer
' snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
' Write interleaved frames to a PCM.
Private Extern snd_pcm_writei(pcm As Pointer, buffP As Pointer, sInt As Integer) As Integer
' const char* snd_strerror (int errnum)
' Returns the message for an error code.
Private Extern snd_strerror(err As Integer) As Pointer
' snd_pcm_close(snd_pcm_t *pcm)
' Close PCM handle.
Private Extern snd_pcm_close(pcm As Pointer)
Public Sub Form_Open()
Dim err As Integer
ValueBox1.Value = 1
ValueBox3.Value = 1
SpinBox1.Value = 10000
Message.Info("<FONT color=blue><I>Provaudio </i></font> è stato il mio \"primo\" progetto sperimentale per la gestione " &
"dell'audio con le sole funzioni del API di Alsa.\nIl programma emette in sequenza ascendente 200 frequenze audio.\n" &
"Modificando i valori delle due manopole è possibile ottenere alcune variazioni nell'esecuzione sonora" &
"<P><Font size=2>da Vuott - 2012-2016")
err = snd_pcm_open(VarPtr(handle), "default", SND_PCM_STREAM_PLAYBACK, 0)
If err < 0 Then Error.Raise(printerr("Apertura = ", err))
Print "Apertura del sistema ALSA: Regolare."
err = snd_pcm_set_params(handle, SND_PCM_FORMAT_U8, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SpinBox1.Value, 1, 200000)
If err < 0 Then Error.Raise(printerr("Funzione parametri = ", err))
Print "Invio parametri: Regolare.\n"
End
Public Sub Button1_Click()
Dim err, i, j As Integer
Dim sizep As Pointer
For j = 200 To 1 Step - 1
sizep = Alloc(Dial1.Value)
For i = 0 To ValueBox3.Value
err = snd_pcm_writei(handle, sizep, j)
If err < 0 Then Error.Raise(printerr("Writei = ", err))
Wait 0.001
Next
Free(sizep)
Next
Chiudi_Programma()
End
Private Sub printerr(operation As String, err As Integer) '' Gestione dell'errore
If err < 0 Then Print operation; ": err="; err; " ("; String@(snd_strerror(err)); ")"
End
Private Procedure Chiudi_Programma()
snd_pcm_close(handle)
End
''''''''''''''''''''''''''''''''
Public Sub Form_Close()
Chiudi_Programma()
End
Public Sub Dial1_Change()
ValueBox1.Value = Dial1.Value
End
Public Sub Dial3_Change()
ValueBox3.Value = Dial3.Value
End