[xmp] Add raw file writer

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 14 years ago
parent a88fcb13f7
commit 2020e79100
  1. 7
      src/Makefile
  2. 127
      src/drivers/file.c
  3. 2
      src/sound.c
  4. 85
      src/sound_file.c
  5. 1
      src/sound_wav.c

@ -1,10 +1,11 @@
SRC_OBJS = sound.o sound_null.o terminal.o info.o commands.o \
options.o getopt.o getopt1.o main.o sound_wav.o
options.o getopt.o getopt1.o main.o sound_wav.o sound_file.o
SRC_DFILES = Makefile xmp.1 $(SRC_OBJS:.o=.c) common.h getopt.h list.h \
sound.h sound_alsa.c sound_coreaudio.c sound_oss.c \
sound_sndio.c sound_openbsd.c sound_bsd.c sound_solaris.c \
sound_beos.c
sound_sndio.c sound_netbsd.c sound_bsd.c sound_solaris.c \
sound_beos.c sound_ahi.c sound_dart.c sound_hpux.c \
sound_aix.c
SRC_PATH = src
SRC_OBJS += $(DRIVERS)

@ -1,127 +0,0 @@
/* Extended Module Player
* Copyright (C) 1996-2012 Claudio Matsuoka and Hipolito Carraro Jr
*
* This file is part of the Extended Module Player and is distributed
* under the terms of the GNU General Public License. See doc/COPYING
* for more information.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "driver.h"
#include "convert.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
#define DATA(x) (((struct data *)sound_file.data)->x)
struct data {
int fd;
int endian;
};
static int init(struct context_data *);
static void bufdump(struct context_data *, void *, int);
static void shutdown(struct context_data *);
static void dummy()
{
}
static char *help[] = {
"big-endian", "Generate big-endian 16-bit samples",
"little-endian", "Generate little-endian 16-bit samples",
NULL
};
struct sound_driver sound_file = {
"file", /* driver ID */
"file", /* driver description */
help, /* help */
init, /* init */
shutdown, /* shutdown */
dummy, /* starttimer */
dummy, /* stoptimer */
bufdump, /* bufdump */
};
static int init(struct context_data *ctx)
{
struct xmp_options *o = &ctx->o;
char *buf;
int bsize;
char *token, **parm;
sound_file.data = malloc(sizeof (struct data));
if (sound_file.data == NULL)
return -1;
DATA(endian) = 0;
parm_init();
chkparm0("big-endian", DATA(endian) = 1);
chkparm0("little-endian", DATA(endian) = -1);
parm_end();
if (!o->outfile)
o->outfile = "xmp.out";
if (strcmp(o->outfile, "-")) {
DATA(fd) = open(o->outfile, O_WRONLY | O_CREAT | O_TRUNC
| O_BINARY, 0644);
if (DATA(fd) < 0)
return -1;
} else {
DATA(fd) = 1;
}
if (strcmp(o->outfile, "-")) {
bsize = strlen(sound_file.description) + strlen(o->outfile) + 8;
buf = malloc(bsize);
snprintf(buf, bsize, "%s: %s", sound_file.description,
o->outfile);
sound_file.description = buf;
} else {
sound_file.description = strdup("Output to stdout");
}
return 0;
}
static void bufdump(struct context_data *ctx, void *b, int i)
{
struct xmp_options *o = &ctx->o;
int j;
if ((o->big_endian && DATA(endian) == -1) ||
(!o->big_endian && DATA(endian) == 1)) {
xmp_cvt_sex(i, b);
}
while (i) {
if ((j = write(DATA(fd), b, i)) > 0) {
i -= j;
b = (char *)b + j;
} else
break;
}
}
static void shutdown(struct context_data *ctx)
{
if (DATA(fd) > 0)
close(DATA(fd));
free(sound_file.description);
free(sound_file.data);
}

@ -3,6 +3,7 @@
#include "sound.h"
extern struct sound_driver sound_wav;
extern struct sound_driver sound_file;
extern struct sound_driver sound_oss;
extern struct sound_driver sound_alsa;
extern struct sound_driver sound_win32;
@ -66,6 +67,7 @@ void init_sound_drivers()
register_sound_driver(&sound_alsa);
#endif
register_sound_driver(&sound_wav);
register_sound_driver(&sound_file);
}
struct sound_driver *select_sound_driver(struct options *options)

@ -0,0 +1,85 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "sound.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
static int fd;
static long size;
struct sound_driver sound_file;
static int init(struct options *options)
{
char *buf;
if (options->out_file == NULL) {
options->out_file = "out.raw";
}
if (strcmp(options->out_file, "-")) {
fd = open(options->out_file, O_WRONLY | O_CREAT | O_TRUNC
| O_BINARY, 0644);
if (fd < 0)
return -1;
} else {
fd = 1;
}
if (strcmp(options->out_file, "-")) {
int len = strlen(sound_file.description) +
strlen(options->out_file) + 8;
if ((buf = malloc(len)) == NULL)
return -1;
snprintf(buf, len, "%s: %s", sound_file.description,
options->out_file);
sound_file.description = buf;
} else {
sound_file.description = strdup("stdout");
}
return 0;
}
static void play(void *b, int len)
{
write(fd, b, len);
size += len;
}
static void deinit()
{
free(sound_file.description);
}
static void flush()
{
}
static void onpause()
{
}
static void onresume()
{
}
struct sound_driver sound_file = {
"file",
"Raw file writer",
NULL,
init,
deinit,
play,
flush,
onpause,
onresume
};

@ -4,7 +4,6 @@
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include "sound.h"
#ifndef O_BINARY

Loading…
Cancel
Save