void set_up_snd_io(chan_info *cp, int i, int fd, const char *filename, file_info *hdr, bool post_close) { snd_io *io; snd_file_open_descriptors(fd, filename, hdr->format, hdr->data_location, hdr->chans, hdr->type); io = make_file_state(fd, hdr, i, 0, (post_close) ? MAX_BUFFER_SIZE : MIX_FILE_BUFFER_SIZE); cp->sounds[0] = make_snd_data_file(filename, io, copy_header(hdr->name, hdr), DONT_DELETE_ME, cp->edit_ctr, i); if (post_close) { snd_data *sd; sd = cp->sounds[0]; sd->open = FD_CLOSED; io->fd = -1; if (mus_file_close(fd) != 0) snd_error("can't close file %s: %s", filename, snd_io_strerror()); } /* this is not as crazy as it looks -- we've read in the first 64K (or whatever) samples, * and may need this file channel for other opens, so this file can be closed until reposition_file_state_buffers */ }
void mus_error_to_snd(int type, char *msg) { /* it's possible to get here outside any catch, and in Guile a throw in that case * kills the main program! */ if (!ss) { fprintf(stderr, msg); return; } if (!(ignore_mus_error(type, msg))) { if (ss->catch_exists) { if (msg == NULL) XEN_ERROR(XEN_ERROR_TYPE("mus-error"), XEN_LIST_1(C_TO_XEN_STRING((char *)mus_error_type_to_string(type)))); else XEN_ERROR(XEN_ERROR_TYPE("mus-error"), XEN_LIST_1(C_TO_XEN_STRING(msg))); } else { snd_error("%s: %s", mus_error_type_to_string(type), msg); #if HAVE_SETJMP_H ss->jump_ok = true; top_level_catch(1); /* sigh -- try to keep going */ #endif } } }
int snd_open_read(const char *arg) { int fd; fd = OPEN(arg, O_RDONLY, 0); if ((fd == -1) && (errno == EMFILE)) /* there's also ENFILE = file table overflow (/usr/include/asm/errno.h) */ { fd = too_many_files_cleanup(); if (fd != -1) fd = OPEN(arg, O_RDONLY, 0); if (fd == -1) snd_error("%s: %s", arg, snd_io_strerror()); } return(fd); }
int snd_reopen_write(const char *arg) { int fd; fd = OPEN(arg, O_RDWR, 0); if ((fd == -1) && (errno == EMFILE)) { fd = too_many_files_cleanup(); if (fd != -1) fd = OPEN(arg, O_RDWR, 0); if (fd == -1) snd_error("%s: %s", arg, snd_io_strerror()); } return(fd); }
static void reposition_file_buffers(snd_data *sd, mus_long_t index) { int fd = 0; bool reclose = false; if (index < 0) index = 0; /* if reading in reverse, don't fall off the start of the buffer */ if (sd->open == FD_CLOSED) { file_info *hdr; /* try to open it with sndlib descriptors */ fd = mus_file_open_read(sd->filename); if (fd == -1) { /* our file has disappeared?!? */ snd_error("%s is unreadable: %s?", sd->filename, snd_io_strerror()); return; } hdr = sd->hdr; /* these need to flush active data before hidden close and fixup the io indices */ snd_file_open_descriptors(fd, sd->filename, hdr->format, hdr->data_location, hdr->chans, hdr->type); during_open(fd, sd->filename, SND_REOPEN_CLOSED_FILE); /* fix up io->fd and whatever else is clobbered by mus_file_close */ sd->io->fd = fd; sd->open = FD_OPEN; reclose = true; } reposition_file_buffers_1(index, sd->io); if (reclose) { sd->open = FD_CLOSED; sd->io->fd = -1; mus_file_close(fd); } }