How to use ALSA library ???

Linux specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to use ALSA library ???

Post by mk-soft »

The code must be right.
Description:
The value returned in name is allocated with strdup and should be freed when no longer used.

Perhaps long name not available or card index is wrong

Code: Select all


PrototypeC.l Prototype_snd_card_get_longname(card.l, *pName)
PrototypeC.l Prototype_snd_card_get_name(card.l, *pName)

Global snd_card_get_longname_.Prototype_snd_card_get_longname
Global snd_card_get_name_.Prototype_snd_card_get_name

snd_card_get_longname_ = GetFunction(AlsaLib, "snd_card_get_longname")
snd_card_get_name_ = GetFunction(AlsaLib, "snd_card_get_name")

Procedure.s snd_card_get_longname(card.l)
  
  Protected r1, *pName, Result$
  
  r1 = snd_card_get_longname_(card, @*pName)
  If r1 = 0
    If *pName
      Result$ = PeekS(*pName, -1, #PB_UTF8)
      free_(*pName)
    Else
      Result$ = "Error: No Long Card Name!"
    EndIf
  Else
      Result$ = "Error: Code " + Hex(r1)
  EndIf
  
  ProcedureReturn Result$
  
EndProcedure

Procedure.s snd_card_get_name(card.l)
  
  Protected r1, *pName, Result$
  
  r1 = snd_card_get_name_(card, @*pName)
  If r1 = 0
    If *pName
      Result$ = PeekS(*pName, -1, #PB_UTF8)
      free_(*pName)
    Else
      Result$ = "Error: No Card Name!"
    EndIf
  Else
      Result$ = "Error: Code " + Hex(r1)
  EndIf
  
  ProcedureReturn Result$
  
EndProcedure
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
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: How to use ALSA library ???

Post by Joris »

Still same error.
The code must be right.
Indeed, but I have one hifiberry and a midi interface to that raspberry.
So I think an index of 0 to 2 would still have to give something ?
That is not the case. Always the same error.

The commands aplay, amidi and so are python scripts, isn't it ?
Where can I find the source of those (that can probably lead to a solution : how to use the alsa functions) ?

Thanks
pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 1: vc4hdmi [vc4-hdmi], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0 [HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0

pi@raspberrypi:~ $ amidi -l
Dir Device Name
IO hw:3,0,0 MT4 MIDI 1
IO hw:3,0,1 MT4 MIDI 2
IO hw:3,0,2 MT4 MIDI 3
O hw:3,0,3 MT4 MIDI 4
O hw:3,0,4 MT4 Broadcast
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to use ALSA library ???

Post by mk-soft »

I think you must call snd_card_next(@card)) first
begin with card.l = -1

I found this example on GitHub ...

Link: https://github.com/munshkr/rawmidi-ruby ... portlist.c
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
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: How to use ALSA library ???

Post by Joris »

Hi, infratec, mk-soft,

I got it. It became a combination of both your samples.
Most difficult things to me is to figure out how to transform those variables used in the alsa-functions.
I hope this basis will get me working on the rest.

Thanks both.
.....
If LoadAlsaLib()

card = -1

While snd_card_next(@card)=>0
; Debug card
If card=-1
Break
Else
Debug snd_card_get_longname(card)
Debug snd_card_get_name(card)
EndIf
Wend

EndIf
.....
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply