2 * \file src/instr/simple.c
3 * \brief Simple Wave Format Support
4 * \author Jaroslav Kysela <perex@perex.cz>
8 * Simple Wave Format Support
9 * Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
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.
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.
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
34 #include <sound/ainstr_simple.h>
37 * \brief Free simple instrument
38 * \param simple Simple instrument handle
39 * \return 0 on success otherwise a negative error code
41 int snd_instr_simple_free(snd_instr_simple_t *simple)
49 static long simple_size(simple_instrument_t *instr)
54 if (instr->format & SIMPLE_WAVE_16BIT)
56 if (instr->format & SIMPLE_WAVE_STEREO)
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
69 int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple,
71 snd_instr_header_t **__data,
74 snd_instr_header_t *put;
77 simple_instrument_t *instr;
78 simple_xinstrument_t *xinstr;
80 if (simple == NULL || __data == NULL)
82 instr = (simple_instrument_t *)simple;
85 size = simple_size(simple);
86 if (snd_instr_header_malloc(&put, sizeof(simple_xinstrument_t) + size) < 0)
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);
114 *__size = sizeof(*put) + sizeof(simple_xinstrument_t) + size;
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
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)
130 int snd_instr_simple_convert_from_stream(snd_instr_header_t *__data,
132 snd_instr_simple_t **simple)