]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Added FM (OPL2/OPL3) instrument support by Uros Bizjak <uros@kss-loka.si>.
authorTakashi Iwai <tiwai@suse.de>
Fri, 1 Sep 2000 16:24:12 +0000 (16:24 +0000)
committerTakashi Iwai <tiwai@suse.de>
Fri, 1 Sep 2000 16:24:12 +0000 (16:24 +0000)
include/instr.h
src/instr/Makefile.am
src/instr/fm.c [new file with mode: 0644]

index b071e616e55a21df8e419c4f389ef12958414ed2..a9922d76ca14bbd7e945f045875249f27355bfb8 100644 (file)
@@ -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
-
index 5d42fbeb80a956e3c64a355ec5a9c85e47740a88..f5f1dee34983dba47cda375d30311d9e66faf613 100644 (file)
@@ -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 (file)
index 0000000..e012158
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  FM (OPL2/3) Instrument Format Support
+ *  Copyright (c) 2000 Uros Bizjak <uros@kss-loka.si>
+ *
+ *   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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include "asoundlib.h"
+#include <asm/byteorder.h>
+#include <linux/ainstr_fm.h>
+
+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;
+}