Generare un'onda sinusoidale con il componente gb.openal: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
(Creata pagina con "Utilizzando le risorse della Classe " ''Alc'' " del Componente ''gb.openal'' di Gambas, è possibile eseguire un'onda sinusoidale, i cui dati saranno realizzati mediante appso...") |
Nessun oggetto della modifica |
||
| Riga 2: | Riga 2: | ||
Vediamo un esempio pratico: | Vediamo un esempio pratico: | ||
Private Const | Private Const AMPIEZZA As Byte = 127 | ||
Private Const | Private Const FREQUENZA As Short = 880 | ||
Private Const | Private Const CAMPIONAMENTO As Integer = 44100 | ||
Private Const | Private Const DURATA As Single = 4.0 | ||
| Riga 34: | Riga 34: | ||
<FONT Color=gray>' ''I dati audio sono caricati nel buffer audio:''</font> | <FONT Color=gray>' ''I dati audio sono caricati nel buffer audio:''</font> | ||
Al.BufferData(buffer[0], Formato_audio, datos.Data, datos.Count, | Al.BufferData(buffer[0], Formato_audio, datos.Data, datos.Count, CAMPIONAMENTO) | ||
<FONT Color=gray>' ''Connette il buffer audio al sorgente audio:''</font> | <FONT Color=gray>' ''Connette il buffer audio al sorgente audio:''</font> | ||
| Riga 43: | Riga 43: | ||
<FONT Color=gray>' ''Consente l'esecuzione per l'intera durata dell'onda sonora:''</font> | <FONT Color=gray>' ''Consente l'esecuzione per l'intera durata dell'onda sonora:''</font> | ||
Sleep | Sleep DURATA | ||
<FONT Color=gray>' ''Libera la memoria:''</font> | <FONT Color=gray>' ''Libera la memoria:''</font> | ||
| Riga 58: | Riga 58: | ||
Dim i As Integer | Dim i As Integer | ||
For i = 0 To ( | For i = 0 To (DURATA * 2 * CAMPIONAMENTO) - 1 | ||
bb.Push(CByte(128 + | bb.Push(CByte(128 + AMPIEZZA * Sin(CFloat(i / CAMPIONAMENTO * FREQUENZA * (2 * Pi))))) | ||
Next | Next | ||
'''End''' | '''End''' | ||
Versione delle 15:47, 28 mar 2018
Utilizzando le risorse della Classe " Alc " del Componente gb.openal di Gambas, è possibile eseguire un'onda sinusoidale, i cui dati saranno realizzati mediante appsota formula matematica.
Vediamo un esempio pratico:
Private Const AMPIEZZA As Byte = 127
Private Const FREQUENZA As Short = 880
Private Const CAMPIONAMENTO As Integer = 44100
Private Const DURATA As Single = 4.0
Public Sub Main()
Dim disp As AlcDevice
Dim cont As AlcContext
Dim src, buffer As Integer[]
Dim err As Boolean
Dim Formato_audio As Integer
Dim datos As New Byte[]
' Configura il dispositivo e il contesto audio con la Clsase "Alc":
disp = Alc.OpenDevice(Null)
cont = Alc.CreateContext(disp)
err = cont.MakeCurrent()
If err = False Then Error.Raise("Impossibile creare il contesto audio !")
src = Al.GenSources(1)
' Configura il buffer audio:
buffer = Al.GenBuffers(1)
Unda(datos)
Formato_audio = 4352
' I dati audio sono caricati nel buffer audio:
Al.BufferData(buffer[0], Formato_audio, datos.Data, datos.Count, CAMPIONAMENTO)
' Connette il buffer audio al sorgente audio:
Al.Sourcei(src[0], Al.BUFFER, buffer[0])
' Esegue il sorgente audio:
Al.SourcePlay(src[0])
' Consente l'esecuzione per l'intera durata dell'onda sonora:
Sleep DURATA
' Libera la memoria:
Al.DeleteBuffers(buffer)
Al.DeleteSources(src)
Alc.DestroyContext(cont)
Alc.CloseDevice(disp)
End
Private Function Unda(bb As Byte[]) ' Crea i dati dell'onda sonora
Dim i As Integer
For i = 0 To (DURATA * 2 * CAMPIONAMENTO) - 1
bb.Push(CByte(128 + AMPIEZZA * Sin(CFloat(i / CAMPIONAMENTO * FREQUENZA * (2 * Pi)))))
Next
End