2001-07-11 14:09:01 +00:00
|
|
|
/**
|
|
|
|
|
* \file src/instr/fm.c
|
2001-07-18 12:17:11 +00:00
|
|
|
* \brief FM (OPL2/3) Instrument Format Support
|
2001-07-11 14:09:01 +00:00
|
|
|
* \author Uros Bizjak <uros@kss-loka.si>
|
|
|
|
|
* \date 2000-2001
|
|
|
|
|
*/
|
2000-09-01 16:24:12 +00:00
|
|
|
/*
|
|
|
|
|
* FM (OPL2/3) Instrument Format Support
|
|
|
|
|
* Copyright (c) 2000 Uros Bizjak <uros@kss-loka.si>
|
|
|
|
|
*
|
2001-09-13 10:16:50 +00:00
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
2001-09-13 10:16:50 +00:00
|
|
|
* the License, or (at your option) any later version.
|
2000-09-01 16:24:12 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2000-09-01 16:24:12 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2001-09-13 10:16:50 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2001-12-30 09:22:54 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-09-01 16:24:12 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <stdio.h>
|
2001-01-31 17:26:56 +00:00
|
|
|
#include "local.h"
|
2001-05-14 06:20:13 +00:00
|
|
|
#include <sound/ainstr_fm.h>
|
2000-09-01 16:24:12 +00:00
|
|
|
|
2001-07-11 14:09:01 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Free the FM instrument handle
|
|
|
|
|
* \param fm FM instrument handle
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-07-04 13:54:13 +00:00
|
|
|
int snd_instr_fm_free(snd_instr_fm_t *fm)
|
2000-09-01 16:24:12 +00:00
|
|
|
{
|
|
|
|
|
if (fm == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
free(fm);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-11 14:09:01 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Convert the FM instrument to byte stream
|
|
|
|
|
* \param fm FM instrument handle
|
|
|
|
|
* \param name FM instrument name
|
|
|
|
|
* \param __data Result - allocated byte stream
|
|
|
|
|
* \param __size Result - size of allocated byte stream
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-09-01 16:24:12 +00:00
|
|
|
int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm,
|
|
|
|
|
const char *name,
|
2001-07-04 13:54:13 +00:00
|
|
|
snd_instr_header_t **__data,
|
2000-09-01 16:24:12 +00:00
|
|
|
size_t *__size)
|
|
|
|
|
{
|
2001-07-04 13:54:13 +00:00
|
|
|
snd_instr_header_t *put;
|
2000-09-01 16:24:12 +00:00
|
|
|
fm_instrument_t *instr;
|
|
|
|
|
fm_xinstrument_t *xinstr;
|
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
|
|
if (fm == NULL || __data == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
instr = (fm_instrument_t *)fm;
|
|
|
|
|
*__data = NULL;
|
|
|
|
|
*__size = 0;
|
2001-07-04 13:54:13 +00:00
|
|
|
if (snd_instr_header_malloc(&put, sizeof(fm_xinstrument_t)) < 0)
|
2000-09-01 16:24:12 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
/* build header */
|
|
|
|
|
if (name)
|
2001-07-04 13:54:13 +00:00
|
|
|
snd_instr_header_set_name(put, name);
|
|
|
|
|
snd_instr_header_set_type(put, SND_SEQ_INSTR_ATYPE_DATA);
|
|
|
|
|
snd_instr_header_set_format(put, SND_SEQ_INSTR_ID_OPL2_3);
|
2000-09-01 16:24:12 +00:00
|
|
|
/* build data section */
|
2001-07-04 13:54:13 +00:00
|
|
|
xinstr = (fm_xinstrument_t *)snd_instr_header_get_data(put);
|
2000-09-01 16:24:12 +00:00
|
|
|
xinstr->stype = FM_STRU_INSTR;
|
|
|
|
|
xinstr->share_id[0] = __cpu_to_le32(instr->share_id[0]);
|
|
|
|
|
xinstr->share_id[1] = __cpu_to_le32(instr->share_id[1]);
|
|
|
|
|
xinstr->share_id[2] = __cpu_to_le32(instr->share_id[2]);
|
|
|
|
|
xinstr->share_id[3] = __cpu_to_le32(instr->share_id[3]);
|
2001-01-18 08:35:57 +00:00
|
|
|
xinstr->type = instr->type;
|
2000-09-01 16:24:12 +00:00
|
|
|
for (idx = 0; idx < 4; idx++) {
|
|
|
|
|
xinstr->op[idx].am_vib = instr->op[idx].am_vib;
|
|
|
|
|
xinstr->op[idx].ksl_level = instr->op[idx].ksl_level;
|
|
|
|
|
xinstr->op[idx].attack_decay = instr->op[idx].attack_decay;
|
|
|
|
|
xinstr->op[idx].sustain_release = instr->op[idx].sustain_release;
|
|
|
|
|
xinstr->op[idx].wave_select = instr->op[idx].wave_select;
|
|
|
|
|
}
|
|
|
|
|
for (idx = 0; idx < 2; idx++) {
|
|
|
|
|
xinstr->feedback_connection[idx] = instr->feedback_connection[idx];
|
|
|
|
|
}
|
|
|
|
|
xinstr->echo_delay = instr->echo_delay;
|
|
|
|
|
xinstr->echo_atten = instr->echo_atten;
|
|
|
|
|
xinstr->chorus_spread = instr->chorus_spread;
|
|
|
|
|
xinstr->trnsps = instr->trnsps;
|
|
|
|
|
xinstr->fix_dur = instr->fix_dur;
|
|
|
|
|
xinstr->modes = instr->modes;
|
|
|
|
|
xinstr->fix_key = instr->fix_key;
|
|
|
|
|
|
|
|
|
|
/* write result */
|
|
|
|
|
*__data = put;
|
|
|
|
|
*__size = sizeof(*put) + sizeof(fm_xinstrument_t);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-11 14:09:01 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Convert the byte stream to FM instrument
|
|
|
|
|
* \param __data Input - byte stream containing FM instrument definition
|
|
|
|
|
* \param size Input - size of byte stream
|
|
|
|
|
* \param simple Result - allocated FM instrument handle
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2002-02-04 11:18:39 +00:00
|
|
|
#ifndef DOXYGEN
|
2001-07-04 13:54:13 +00:00
|
|
|
int snd_instr_fm_convert_from_stream(snd_instr_header_t *__data ATTRIBUTE_UNUSED,
|
2000-09-01 16:24:12 +00:00
|
|
|
size_t size ATTRIBUTE_UNUSED,
|
|
|
|
|
snd_instr_fm_t **simple ATTRIBUTE_UNUSED)
|
2002-02-04 11:18:39 +00:00
|
|
|
#else
|
|
|
|
|
int snd_instr_fm_convert_from_stream(snd_instr_header_t *__data,
|
|
|
|
|
size_t size,
|
|
|
|
|
snd_instr_fm_t **simple)
|
|
|
|
|
#endif
|
2000-09-01 16:24:12 +00:00
|
|
|
{
|
|
|
|
|
/* TODO */
|
|
|
|
|
return -ENXIO;
|
|
|
|
|
}
|