2 Copyright © 2015, The AROS Development Team. All rights reserved.
6 #include "alsa_hostlib.h"
9 #define CARDNAME "default"
10 #define VOLUMENAME "Master"
14 return ALSA_HostLib_Init();
19 ALSA_HostLib_Cleanup();
22 VOID
ALSA_MixerInit(APTR
* handle
, APTR
* elem
, LONG
* min
, LONG
* max
)
24 snd_mixer_t
* _handle
;
25 snd_mixer_selem_id_t
* _sid
;
26 snd_mixer_elem_t
* _elem
;
31 ALSACALL(snd_mixer_open
,&_handle
, 0);
32 ALSACALL(snd_mixer_attach
,_handle
, CARDNAME
);
33 ALSACALL(snd_mixer_selem_register
,_handle
, NULL
, NULL
);
34 ALSACALL(snd_mixer_load
,_handle
);
36 ALSACALL(snd_mixer_selem_id_malloc
,&_sid
);
37 ALSACALL(snd_mixer_selem_id_set_index
,_sid
, 0);
38 ALSACALL(snd_mixer_selem_id_set_name
,_sid
, VOLUMENAME
);
39 _elem
= ALSACALL(snd_mixer_find_selem
,_handle
, _sid
);
44 ALSACALL(snd_mixer_selem_get_playback_volume_range
,_elem
, &a
, &b
);
52 ALSACALL(snd_mixer_selem_id_free
,_sid
);
55 VOID
ALSA_MixerCleanup(APTR handle
)
57 ALSACALL(snd_mixer_close
,handle
);
60 LONG
ALSA_MixerGetVolume(APTR elem
)
64 ALSACALL(snd_mixer_selem_get_playback_volume
, elem
,
65 SND_MIXER_SCHN_FRONT_LEFT
, &_ret
);
69 VOID
ALSA_MixerSetVolume(APTR elem
, LONG volume
)
71 ALSACALL(snd_mixer_selem_set_playback_volume_all
, elem
, volume
);
76 snd_pcm_t
* handle
= NULL
;
79 if (ALSACALL(snd_pcm_open
, &handle
, CARDNAME
,
80 SND_PCM_STREAM_PLAYBACK
, 0) < 0)
86 VOID
ALSA_DropAndClose(APTR handle
)
90 ALSACALL(snd_pcm_drop
, handle
);
91 ALSACALL(snd_pcm_close
, handle
);
95 BOOL
ALSA_SetHWParams(APTR handle
, ULONG
* rate
)
97 snd_pcm_hw_params_t
* hw_params
;
98 LONG dir
= 0; int r
= 0;
100 ALSACALL(snd_pcm_hw_params_malloc
, &hw_params
);
101 ALSACALL(snd_pcm_hw_params_any
, handle
, hw_params
);
102 ALSACALL(snd_pcm_hw_params_set_access
, handle
, hw_params
,
103 SND_PCM_ACCESS_RW_INTERLEAVED
);
104 ALSACALL(snd_pcm_hw_params_set_format
, handle
, hw_params
,
105 SND_PCM_FORMAT_S16_LE
);
106 ALSACALL(snd_pcm_hw_params_set_channels
, handle
, hw_params
, 2);
107 r
= ALSACALL(snd_pcm_hw_params_set_rate_near
, handle
, hw_params
, rate
, &dir
);
108 ALSACALL(snd_pcm_hw_params_set_buffer_size
, handle
, hw_params
, 2048);
110 ALSACALL(snd_pcm_hw_params
, handle
, hw_params
);
111 ALSACALL(snd_pcm_hw_params_free
, hw_params
);
116 LONG
ALSA_Write(APTR handle
, APTR buffer
, ULONG size
)
118 LONG rc
= ALSACALL(snd_pcm_writei
, handle
, buffer
, (snd_pcm_uframes_t
)size
);
126 VOID
ALSA_Prepare(APTR handle
)
128 ALSACALL(snd_pcm_prepare
, handle
);
131 LONG
ALSA_Avail(APTR handle
)
133 LONG rc
= ALSACALL(snd_pcm_avail_update
, handle
);