ALSA

Spezielle Fragen zu 2D- und 3D-Grafik, Sound und Video
Antworten
Benutzeravatar
gambi
Moderator
Beiträge: 249
Registriert: Mi 8. Mai 2013, 21:46
Kontaktdaten:

ALSA

Beitrag von gambi » So 17. Mai 2015, 19:43

Hallo,
ich versuche seit geraumer Zeit ALSA in ein Gambas-Programm über EXTERN einzubinden. Das Schreiben von PCM-Daten funktioniert leidlich. Ich habe mich dabei an dem von vuott eingestellten Programm orientiert (http://gambas.8142.n7.nabble.com/Genera ... tml#a44764).
Der Sinus ist allerdings etwas verzerrt (Oberwellen) Siehe auch Screenshot.

Mit dem Einlesen komme ich überhaupt nicht voran :(

Gibt es Ideen?
Danke
gg
Dateianhänge
ALSA_01.png
ALSA_01.png (29.79 KiB) 3293 mal betrachtet

vuott
Foriker
Beiträge: 73
Registriert: Fr 16. Jan 2015, 01:27
Kontaktdaten:

Re: ALSA

Beitrag von vuott » Mi 20. Mai 2015, 11:50

gambi hat geschrieben:Der Sinus ist allerdings etwas verzerrt (Oberwellen) Siehe auch Screenshot.


Hello gambi,
...yes, I remember.. that was my mistake... I'm sorry ! :cry:
After I corrected that mistake.
Well, you have to change variable from Float -> Single.

Code: Alles auswählen

Private Const BUFFER_LEN As Integer = 48000
Private Const device As String = "default"


Library "libasound:2" 
     
Private Const SND_PCM_STREAM_PLAYBACK As Byte = 0 
Private Const SND_PCM_FORMAT_FLOAT As Integer = 14
Private Const SND_PCM_ACCESS_RW_INTERLEAVED As Byte = 3 
     
 ' int snd_pcm_open (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)
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)
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)
Private Extern snd_pcm_writei(pcm As Pointer, buffF As Single[], sizeI As Integer) As Integer

' const char * snd_strerror (int errnum)
Private Extern snd_strerror(errnum As Integer) As String
     
' snd_pcm_close(snd_pcm_t *pcm)
Private Extern snd_pcm_close(pcm As Pointer) 
     
     
Public Sub Main()
     
  Dim err, fc, k, j, frames As Integer 
  Dim hz As Short
  Dim handle As Pointer 
  Dim buffer As New Single[]
     
     
    hz = 440            ' Sine wave frequency
    fc = BUFFER_LEN
     
     
    err = snd_pcm_open(VarPtr(handle), device, SND_PCM_STREAM_PLAYBACK, 0) 
    If err < 0 Then Error.Raise("Impossible open ALSA PCM sub-system: " & snd_strerror(err))
     
    err = snd_pcm_set_params(handle, SND_PCM_FORMAT_FLOAT, SND_PCM_ACCESS_RW_INTERLEAVED, 1, fc, 1, 500000)
    If err < 0 Then Error.Raise("Impossible set  ALSA PCM sub-system parameters: " & snd_strerror(err))
   
   
    Print "Sine wave frequency: "; hz; "hz."
   
   
' Generate sine wave values:
    For k = 0 To BUFFER_LEN - 1
      buffer.Add(Sin(2 * Pi * hz / fc * k))
    Next


' Sends sine wave values to ALSA PCM audio device:
    For j = 0 To 2
      frames = snd_pcm_writei(handle, buffer, BUFFER_LEN)
      If frames < 0 Then Error.Raise("Error at 'snd_pcm_writei' function !")
    Next 
     
     
' ....closing:
    snd_pcm_close(handle) 
     
End


Best regards

Benutzeravatar
gambi
Moderator
Beiträge: 249
Registriert: Mi 8. Mai 2013, 21:46
Kontaktdaten:

Re: ALSA

Beitrag von gambi » Mi 20. Mai 2015, 19:38

Hi vuott,
no prob as long as there is a solution :wink: And your solution works fine. Thank you.
Just remains the problem with reading from sound-card. I will give a code-example tomorrow or friday.

gg

vuott
Foriker
Beiträge: 73
Registriert: Fr 16. Jan 2015, 01:27
Kontaktdaten:

Re: ALSA

Beitrag von vuott » Do 21. Mai 2015, 16:06

Hello gambi,

...if you are interested in my little studies on the handling of audio in Gambas:
http://www.gambas-it.org/wiki/index.php ... file_audio

(language: italian)

Benutzeravatar
gambi
Moderator
Beiträge: 249
Registriert: Mi 8. Mai 2013, 21:46
Kontaktdaten:

Re: ALSA

Beitrag von gambi » Do 21. Mai 2015, 21:33

Hi vuott,
thank you for the link. Thats really great. I did some searches on your pages earlier, but now I found the repository of sound with gambas.
Thanks again.

gg

Benutzeravatar
gambi
Moderator
Beiträge: 249
Registriert: Mi 8. Mai 2013, 21:46
Kontaktdaten:

Re: ALSA

Beitrag von gambi » Sa 23. Mai 2015, 10:58

Hi vuott,
your example http://www.gambas-it.org/wiki/index.php ... istrazione is what i was looking for. :D

gg

Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste