3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <sound/audio.h>
24 snd_audio_t snd_audio_list
;
26 /* find audio structure by specified device */
27 snd_audio_t
*audio_find (dev_t
*dev
)
30 for (aud
= snd_audio_list
.next
; aud
!= &snd_audio_list
; aud
= aud
->next
) {
38 /* open audio sound system (prepare sound card to play) */
39 snd_audio_t
*audio_open (snd_cfg_t
*cfg
)
41 if (!cfg
->dev
|| !cfg
->rate
|| !cfg
->format
)
44 dev_t
*dev
= dev_find (cfg
->dev
);
49 if (!(dev
->attrib
& DEV_ATTR_SOUND
))
52 /* we dont accept multiple device using yet */
56 /* alloc and init context */
57 snd_audio_t
*aud
= (snd_audio_t
*) kmalloc (sizeof (snd_audio_t
));
63 aud
->rate
= cfg
->rate
;
64 aud
->format
= cfg
->format
;
65 aud
->channels
= cfg
->channels
;
66 aud
->flags
= cfg
->flags
;
68 printf ("rate: %d f: %d, ch: %d\n", aud
->rate
, aud
->format
, aud
->channels
);
71 aud
->next
= &snd_audio_list
;
72 aud
->prev
= snd_audio_list
.prev
;
73 aud
->prev
->next
= aud
;
74 aud
->next
->prev
= aud
;
76 /* setup sound card */
77 dev
->handler (DEV_ACT_UPDATE
, (void *) aud
, sizeof (snd_audio_t
));
82 /* write data into device buffer */
83 int audio_write (snd_audio_t
*aud
, char *buf
, unsigned len
)
85 if (!aud
|| !buf
|| !len
)
88 aud
->dev
->handler (DEV_ACT_WRITE
, buf
, len
);
93 int audio_close (snd_audio_t
*aud
)
98 aud
->next
->prev
= aud
->prev
;
99 aud
->prev
->next
= aud
->next
;
106 aud
->dev
->handler (DEV_ACT_UPDATE
, (void *) aud
, sizeof (snd_audio_t
));
113 /* init function of sound system */
114 unsigned int init_audio ()
116 snd_audio_list
.next
= &snd_audio_list
;
117 snd_audio_list
.prev
= &snd_audio_list
;