📄 play_data.c
字号:
/* * This material contains unpublished, proprietary software of * Entropic Research Laboratory, Inc. Any reproduction, distribution, * or publication of this work must be authorized in writing by Entropic * Research Laboratory, Inc., and must bear the notice: * * "Copyright (c) 1987-1990 AT&T, Inc. * "Copyright (c) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-1996 Entropic Research Laboratory, Inc. * All rights reserved" * * The copyright notice above does not evidence any actual or intended * publication of this source code. * * Written by: * Checked by: * Revised by: * * Brief description: * will eventually contain all "standard" methods for signal reconstruction * and synthesis */static char *sccs_id = "@(#)play_data.c 1.21 5/27/97 ERL/ATT";#include <stdio.h>#include <Objects.h>#include <esps/esps.h>#include <esps/sd.h> /* SD file stuff */#include <esps/fea.h>#include <esps/feasd.h>#include <dsp32.h>#define DPR_MAX 1024#define DB_SIZE 4096 /* integral multiple of DPR_MAX */#define DA_START 0#define DA_RUN 1#define DA_END 2#define ALWAYS_LOAD 1#define LOAD_AS_NEEDED 2#ifndef LBIN#define LBIN "/usr/local/bin"#endifint da_done = TRUE, da_location = 0, play_pid = 0;static char loaded[100];short dsp_is_open = -1;extern short *dspmap();extern int use_dsp32;extern int dsp_type;extern char play_program[];extern int debug_level;extern char *registry_name;short *dpr = NULL;static int byt_swap;char *mktemp();int call_external_play_prog_get_pid();/*************************************************************************/ext_play_done(){ da_done = TRUE; if ((play_pid > 0) && (da_location > 0)) move_view_to_loc(get_esps_callback_data(play_pid), da_location); da_location = 0; play_pid = 0;}/*************************************************************************//* * If D/A is in progress and play_pid is > 0, kill the current play process * and disable it's callback. Indicate that D/A is in progress by setting * da_done FALSE. If xwaves is not in server mode, put it into server mode. * Export the environment variables WAVES_PORT and WAVES_HOST so that clever * play programs can set da_location via send_xwaves. The routine * handle_da_interruption() can kill the external play program. When this * child process dies, its callback procedure will then reposition the * display window appropriately if da_location has been set. */call_external_play_prog(command, input, output, n_outputs, do_display, callback) char *command, *input, *output; int n_outputs, (*callback) (), do_display;{ if (play_program && *play_program && (play_pid > 0)) { /* a play program seems to be running */ if (debug_level) fprintf(stderr, "Trying to kill %s (%d)\n", play_program, play_pid); reset_esps_callback(play_pid, NULL); kill(play_pid + 1, SIGINT); /* +1 since it's execv'd from the * fork() */ } da_done = TRUE; da_location = 0; if ((play_pid = run_esps_prog_get_pid(command, input, output, n_outputs, do_display, ext_play_done))) da_done = FALSE; return ((play_pid > 0) ? 0 : -1);}/*************************************************************************/get_estimated_signal_maximum(s) Signal *s;{ double amax = 0.0, amin = 0.0, get_genhd_val_array(); extern int sig_max_override; if (sig_max_override > 0) return (sig_max_override); if (s->header && (s->header->magic == SIGNAL_MAGIC)) { /* get from header */ head_scanf(s->header, "maximum", &amax); head_scanf(s->header, "minimum", &amin); if (amax < (-amin)) amax = -amin; } else if (s->header->magic == ESPS_MAGIC) { if (s->dim == 1) amax = get_genhd_val("max_value", s->header->esps_hdr, 32767.0); else amax = MAX(get_genhd_val_array("max_value", 0, s->header->esps_hdr, 32767.0), get_genhd_val_array("max_value", 1, s->header->esps_hdr, 32767.0)); } return ((int) ((amax > 128) ? amax : 32767)); /* don't take a chance * on small values! */}/*************************************************************************/static Signal *this_play = NULL;Signal *get_playing_signal(){ return(this_play);}/* * This is the routine called by all requests for INTERNAL plays by xwaves. * See call_external_play_prog() to explicitly request play by external * programs. Note that some internal requests are sent to external play * programs when it seems implssible to execute them internally. */play_file(s, start, end) Signal *s; double start, end;{ static int fd; int sam1, nsamps, startsamp; char play_command[256]; /* for ESPS play command */ double end_time, freq; Header *h = NULL; struct header *ehead = NULL; if (debug_level) (void) fprintf(stderr, "xwaves: entered play_file\n"); if (s) { if ((start < SIG_END_TIME(s)) && (end > s->start_time)) { this_play = s; h = s->header; byt_swap = h && (h->magic == RHEADR_MAGIC); /* Limit play request to signal limits. */ if ((sam1 = (start - s->start_time) * s->freq) < 0) { sam1 = 0; start = s->start_time; } if (end > (end_time = s->start_time + ((double) s->file_size) / s->freq)) end = end_time; /* * If there is built-in hardware and the signal can be read and * converted for its use... */ if (use_dsp32 && ereader_can_handle(s, &ehead)) { if (((!s->name) || ((s->file < 0) && (s->file != SIG_CLOSED))) && (s->buff_size != s->file_size)) { (void) fprintf(stderr, "xwaves(play_file): can't play data\n"); return (FALSE); } if (!da_done) stop_da(NULL); /* * If it's all in memory and it's 1-dimensional, just play from * the display buffer. */ if (((type_of_signal(s) & VECTOR_SIGNALS) == P_SHORTS) && (s->dim == 1) && (start >= BUF_START_TIME(s)) && (end <= BUF_END_TIME(s))) { return (play_signal(s, start, end)); } if (s->file == SIG_NEW) put_signal(s); /* It's playable by the built-in hardware. */ return (dac_file(s, ehead, start, end)); } else if (play_program && *play_program) {/* PUNT: TRY TO USE AN EXTERNAL "PLAY" * PROGRAM */ if ((nsamps = (end - start) * s->freq) <= 0) return (FALSE); if ((s->file == SIG_NEW) && (s->dim < 3)) put_signal(s); startsamp = sam1 + 1; /* ESPS numbering starts at 1, not 0 */ (void) sprintf(play_command, "%s -r%d:+%d", play_program, startsamp, nsamps - 1); (void) call_external_play_prog(play_command, s->name, "", 0, NO, NULL); return (TRUE); } else { if (!use_dsp32 && !play_program || ! *play_program) sprintf(notice_msg, "Cannot play %s. No play program is specfied (play_prog is not set)", s->name); else sprintf(notice_msg, "Cannot play %s due to its type", s->name); show_notice(1, notice_msg); } } else { sprintf(notice_msg, "Play region requested not in file %s", s->name); show_notice(1, notice_msg); } } else /* else (NULL signal argument to play_file() */ show_notice(1, "No playable signal passed to play_file"); return (FALSE);}/*************************************************************************/show_play_position(sample) int sample;{ Signal *s; View *v; extern double play_time; extern int show_play_pos;#ifdef LINUXX return;#endif if ((s = this_play) && (v = s->views) && canvas_still_lives(v->canvas)) { if(show_play_pos) { plot_time_bar(v, s, sample); if(show_play_pos > 1) { Signal *so = s; long psample; s = ((Object*)(s->obj))->signals; while(s) { if((s != this_play) && (v = s->views) && canvas_still_lives(v->canvas) && (s->freq > 0.0) && (so->freq > 0.0)) { psample = (s->freq * sample)/so->freq; plot_time_bar(v, s, psample); } s = s->others; } } } else /* set play_time here (instead of in plot_time_bar() */ play_time = s->start_time + (((double)sample)/s->freq); }}/*************************************************************************/void stop_da_view(v) View *v;{ if(!da_done && v && v->sig && (v->sig == this_play)) stop_da(NULL);}/*************************************************************************/play_signal(s, start, end) Signal *s; double start, end;{ int i; double stime, etime, freq; short *data; char play_command[256]; /* for ESPS play command options */ struct header *espshd = NULL; /* SD header for ESPS file */ int nsamps, startsamp; if (debug_level) (void) fprintf(stderr, "xwaves: entered play_signal\n"); if (s && IS_GENERIC(type_of_signal(s)) && ((type_of_signal(s) & VECTOR_SIGNALS) == P_SHORTS) && (s->dim == 1)) { if ((stime = BUF_START_TIME(s)) > start) start = stime; if ((etime = BUF_END_TIME(s)) < end) end = etime; if ((end > start) && use_dsp32) { /* D/A conversion from a memory buffer. */ dac_mem(s, start, end); return (TRUE); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -