Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / core / sound / audio.c
blob8787b5610942fcecc60a3ce6642d52f379da73ad
1 /*
2 * ZeX/OS
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/>.
20 #include <system.h>
21 #include <sound/audio.h>
22 #include <dev.h>
24 snd_audio_t snd_audio_list;
26 /* find audio structure by specified device */
27 snd_audio_t *audio_find (dev_t *dev)
29 snd_audio_t *aud;
30 for (aud = snd_audio_list.next; aud != &snd_audio_list; aud = aud->next) {
31 if (aud->dev == dev)
32 return aud;
35 return 0;
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)
42 return 0;
44 dev_t *dev = dev_find (cfg->dev);
46 if (!dev)
47 return 0;
49 if (!(dev->attrib & DEV_ATTR_SOUND))
50 return 0;
52 /* we dont accept multiple device using yet */
53 if (audio_find (dev))
54 return 0;
56 /* alloc and init context */
57 snd_audio_t *aud = (snd_audio_t *) kmalloc (sizeof (snd_audio_t));
59 if (!aud)
60 return 0;
62 aud->dev = dev;
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);
70 /* add into list */
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));
79 return aud;
82 /* write data into device buffer */
83 int audio_write (snd_audio_t *aud, char *buf, unsigned len)
85 if (!aud || !buf || !len)
86 return -1;
88 aud->dev->handler (DEV_ACT_WRITE, buf, len);
90 return 0;
93 int audio_close (snd_audio_t *aud)
95 if (!aud)
96 return -1;
98 aud->next->prev = aud->prev;
99 aud->prev->next = aud->next;
101 aud->rate = 0;
102 aud->format = 0;
103 aud->channels = 0;
104 aud->flags = 0;
106 aud->dev->handler (DEV_ACT_UPDATE, (void *) aud, sizeof (snd_audio_t));
108 kfree (aud);
110 return 0;
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;
119 return 1;