From a2026ace683480fb9827bf77dafbb712e305275e Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 1 Sep 2000 16:24:12 +0000 Subject: [PATCH] Added FM (OPL2/OPL3) instrument support by Uros Bizjak . --- include/instr.h | 17 ++++++- src/instr/Makefile.am | 2 +- src/instr/fm.c | 102 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/instr/fm.c diff --git a/include/instr.h b/include/instr.h index b071e616..a9922d76 100644 --- a/include/instr.h +++ b/include/instr.h @@ -5,6 +5,22 @@ * * ****************************************************************************/ +/* FM instrument support */ + +typedef void snd_instr_fm_t; + +#ifdef __cplusplus +extern "C" { +#endif + +int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm, const char *name, snd_seq_instr_put_t **put, size_t *size); +int snd_instr_fm_convert_from_stream(snd_seq_instr_get_t *data, size_t size, snd_instr_fm_t **fm); +int snd_instr_fm_free(snd_instr_fm_t *fm); + +#ifdef __cplusplus +} +#endif + /* Simple Wave support */ typedef void snd_instr_simple_t; @@ -42,4 +58,3 @@ int snd_instr_iwffff_free(snd_instr_iwffff_t *iwffff); #ifdef __cplusplus } #endif - diff --git a/src/instr/Makefile.am b/src/instr/Makefile.am index 5d42fbeb..f5f1dee3 100644 --- a/src/instr/Makefile.am +++ b/src/instr/Makefile.am @@ -1,6 +1,6 @@ EXTRA_LTLIBRARIES=libinstr.la -libinstr_la_SOURCES = simple.c iwffff.c +libinstr_la_SOURCES = fm.c simple.c iwffff.c all: libinstr.la diff --git a/src/instr/fm.c b/src/instr/fm.c new file mode 100644 index 00000000..e012158e --- /dev/null +++ b/src/instr/fm.c @@ -0,0 +1,102 @@ +/* + * FM (OPL2/3) Instrument Format Support + * Copyright (c) 2000 Uros Bizjak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include "asoundlib.h" +#include +#include + +int snd_instr_fm_free(snd_instr_simple_t *fm) +{ + if (fm == NULL) + return 0; + free(fm); + return 0; +} + +int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm, + const char *name, + snd_seq_instr_put_t **__data, + size_t *__size) +{ + snd_seq_instr_put_t *put; + snd_seq_instr_data_t *data; + 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; + put = (snd_seq_instr_put_t *)malloc(sizeof(*put) + sizeof(fm_xinstrument_t)); + if (put == NULL) + return -ENOMEM; + /* build header */ + bzero(put, sizeof(*put)); + data = &put->data; + if (name) + strncpy(data->name, name, sizeof(data->name)-1); + data->type = SND_SEQ_INSTR_ATYPE_DATA; + strcpy(data->data.format, SND_SEQ_INSTR_ID_OPL3); + /* build data section */ + xinstr = (fm_xinstrument_t *)(data + 1); + 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]); + 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; +} + +int snd_instr_fm_convert_from_stream(snd_seq_instr_get_t *__data ATTRIBUTE_UNUSED, + size_t size ATTRIBUTE_UNUSED, + snd_instr_fm_t **simple ATTRIBUTE_UNUSED) +{ + /* TODO */ + return -ENXIO; +} -- 2.47.1