OSDN Git Service

Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz
[android-x86/external-alsa-lib.git] / src / instr / simple.c
1 /**
2  * \file src/instr/simple.c
3  * \brief Simple Wave Format Support
4  * \author Jaroslav Kysela <perex@perex.cz>
5  * \date 1999-2001
6  */
7 /*
8  *  Simple Wave Format Support
9  *  Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
10  *
11  *
12  *   This library is free software; you can redistribute it and/or modify
13  *   it under the terms of the GNU Lesser General Public License as
14  *   published by the Free Software Foundation; either version 2.1 of
15  *   the License, or (at your option) any later version.
16  *
17  *   This program is distributed in the hope that it will be useful,
18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *   GNU Lesser General Public License for more details.
21  *
22  *   You should have received a copy of the GNU Lesser General Public
23  *   License along with this library; if not, write to the Free Software
24  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25  *
26  */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sys/stat.h>
32 #include <stdio.h>
33 #include "local.h"
34 #include <sound/ainstr_simple.h>
35
36 /**
37  * \brief Free simple instrument
38  * \param simple Simple instrument handle
39  * \return 0 on success otherwise a negative error code
40  */
41 int snd_instr_simple_free(snd_instr_simple_t *simple)
42 {
43         if (simple == NULL)
44                 return 0;
45         free(simple);
46         return 0;
47 }
48
49 static long simple_size(simple_instrument_t *instr)
50 {
51         int size;
52
53         size = instr->size;
54         if (instr->format & SIMPLE_WAVE_16BIT)
55                 size <<= 1;
56         if (instr->format & SIMPLE_WAVE_STEREO)
57                 size <<= 1;
58         return size;
59 }
60
61 /**
62  * \brief Convert the simple instrument to byte stream
63  * \param simple Simple instrument handle
64  * \param name Simple instrument name
65  * \param __data Result - allocated byte stream
66  * \param __size Result - size of allocated byte stream
67  * \return 0 on success otherwise a negative error code
68  */
69 int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple,
70                                        const char *name,
71                                        snd_instr_header_t **__data,
72                                        size_t *__size)
73 {
74         snd_instr_header_t *put;
75         int size;
76         char *ptr;
77         simple_instrument_t *instr;
78         simple_xinstrument_t *xinstr;
79         
80         if (simple == NULL || __data == NULL)
81                 return -EINVAL;
82         instr = (simple_instrument_t *)simple;
83         *__data = NULL;
84         *__size = 0;
85         size = simple_size(simple);
86         if (snd_instr_header_malloc(&put, sizeof(simple_xinstrument_t) + size) < 0)
87                 return -ENOMEM;
88         /* build header */
89         if (name)
90                 snd_instr_header_set_name(put, name);
91         snd_instr_header_set_type(put, SND_SEQ_INSTR_ATYPE_DATA);
92         snd_instr_header_set_format(put, SND_SEQ_INSTR_ID_SIMPLE);
93         /* build data section */
94         xinstr = (simple_xinstrument_t *)snd_instr_header_get_data(put);
95         xinstr->stype = SIMPLE_STRU_INSTR;
96         xinstr->share_id[0] = __cpu_to_le32(instr->share_id[0]);
97         xinstr->share_id[1] = __cpu_to_le32(instr->share_id[1]);
98         xinstr->share_id[2] = __cpu_to_le32(instr->share_id[2]);
99         xinstr->share_id[3] = __cpu_to_le32(instr->share_id[3]);
100         xinstr->format = __cpu_to_le32(instr->format);
101         xinstr->size = __cpu_to_le32(instr->size);
102         xinstr->start = __cpu_to_le32(instr->start);
103         xinstr->loop_start = __cpu_to_le32(instr->loop_start);
104         xinstr->loop_end = __cpu_to_le32(instr->loop_end);
105         xinstr->loop_repeat = __cpu_to_le16(instr->loop_repeat);
106         xinstr->effect1 = instr->effect1;
107         xinstr->effect1_depth = instr->effect1_depth;
108         xinstr->effect2 = instr->effect2;
109         xinstr->effect2_depth = instr->effect2_depth;
110         ptr = (char *)(xinstr + 1);
111         memcpy(ptr, instr->address.ptr, size);
112         /* write result */
113         *__data = put;
114         *__size = sizeof(*put) + sizeof(simple_xinstrument_t) + size;
115         return 0;
116 }
117
118 /**
119  * \brief Convert the byte stream to simple instrument
120  * \param __data byte stream
121  * \param size size of byte stream
122  * \param simple Result - simple instrument handle
123  * \return 0 on success otherwise a negative error code
124  */
125 #ifndef DOXYGEN
126 int snd_instr_simple_convert_from_stream(snd_instr_header_t *__data ATTRIBUTE_UNUSED,
127                                          size_t size ATTRIBUTE_UNUSED,
128                                          snd_instr_simple_t **simple ATTRIBUTE_UNUSED)
129 #else
130 int snd_instr_simple_convert_from_stream(snd_instr_header_t *__data,
131                                          size_t size,
132                                          snd_instr_simple_t **simple)
133 #endif
134 {
135         /* TODO */
136         return -ENXIO;
137 }