static void include(CSOUND *csound, EXTRACT_STATICS* extractStatics, SRTBLK *bp) { if (STA(frstout) == NULL) /* first one is special */ STA(frstout) = bp; else STA(prvout)->nxtblk = bp; /* others just add onto list */ bp->prvblk = STA(prvout); /* maintain the backptr */ STA(prvout) = bp; /* and get ready for next */ }
bool DoHippocratePlacementIfRequired(HDesign& hd, const char* cfgOptName) { HDPGrid grid(hd); if (grid.Design().cfg.ValueOf(cfgOptName, false)) { grid.FindCellsPositions(); HippocratePlacementInit(); bool LogEveryIteration; if(hd.cfg.ValueOf("HippocratePlacement.LogEveryIteration", false)) LogEveryIteration=true; else LogEveryIteration=false; TimingHPWLWatcher thpwlWatcher(hd, LogEveryIteration); StatisticsAnalyser stat; ALERT("STA before Legalization Hippocrate placement:"); STA(hd,true); if (!CheckGridBoundary(grid, 2, true)|| !CheckGridConsistency(grid, 2, 1e-6, true)|| !CheckOverlaps(grid,2, true)) { ALERT("NOT LEGALIZED before hippocrate!!"); Legalization(grid); }else ALERT("Legalized before Hippocrate"); ALERT("STA before Hippocrate placement:"); STA(hd,true); double oldTNS=Utils::TNS(hd); double oldWNS=Utils::WNS(hd); ALERT("HPWL before Hippocrate placement: %f", Utils::CalculateHPWL(hd, true)); DoHippocratePlacement(grid, hd, stat, thpwlWatcher); if (!CheckGridBoundary(grid, 2, true)|| !CheckGridConsistency(grid, 2, 1e-6, true)|| !CheckOverlaps(grid, 2, true)) { ALERT("Not Legalized after!"); } else ALERT("!!!Legalized after!"); hd.Plotter->ShowPlacement(); ALERT("STA after Hippocrate placement:"); STA(hd,true); ALERT("HPWL after Hippocrate placement: %f", Utils::CalculateHPWL(hd, true)); HippocratePlacementFinalize(); stat.doReport(); //DetailedPlacement(grid); //WRITELINE(""); //if (grid.Design().CanDoTiming()) ALERT("STA after detailed placement:"); //STA(grid.Design()); return true; } return false; }
static void alloc_globals(CSOUND *csound, EXTRACT_STATICS* extractStatics) { /* if (csound->extractGlobals == NULL) { */ /* csound->extractGlobals = csound->Calloc(csound, sizeof(EXTRACT_GLOBALS)); */ /* STA(onbeat) = STA(offbeat) = FL(0.0); */ /* STA(ontime) = STA(offtime) = FL(0.0); */ memcpy(&STA(a0), &a0, sizeof(SRTBLK)); memcpy(&STA(f0), &f0, sizeof(SRTBLK)); memcpy(&STA(e), &e, sizeof(SRTBLK)); /* } */ }
static void writesf_dither_8(CSOUND *csound, const MYFLT *outbuf, int nbytes) { OPARMS *O = csound->oparms; int n; int m = nbytes / sizeof(MYFLT); MYFLT *buf = (MYFLT*) outbuf; int dith; if (UNLIKELY(STA(outfile) == NULL)) return; dith = STA(dither); for (n=0; n<m; n++) { int tmp = ((dith * 15625) + 1) & 0xFFFF; int rnd = ((tmp * 15625) + 1) & 0xFFFF; MYFLT result; dith = rnd; rnd = (rnd+tmp)>>1; /* triangular distribution */ result = (MYFLT) (rnd - 0x8000) / ((MYFLT) 0x10000); result /= ((MYFLT) 0x7f); buf[n] += result; } STA(dither) = dith; n = (int) sf_write_MYFLT(STA(outfile), (MYFLT*) outbuf, nbytes / sizeof(MYFLT)) * (int) sizeof(MYFLT); if (UNLIKELY(n < nbytes)) sndwrterr(csound, n, nbytes); if (UNLIKELY(O->rewrt_hdr)) rewriteheader(STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, "%c\010", "|/-\\"[csound->nrecs & 3]); break; case 2: csound->MessageS(csound, CSOUNDMSG_REALTIME, "."); break; case 3: { char s[512]; CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); } } break; case 4: csound->MessageS(csound, CSOUNDMSG_REALTIME, "\a"); break; } }
void sfnopenout(CSOUND *csound) { alloc_globals(csound); csound->Message(csound, Str("not writing to sound disk\n")); /* init counter, though not writing */ STA(outbufrem) = csound->oparms->outbufsamps; }
//--------------------------------メイン-------------------------------------- int main(void){ int seed; //ランダム関数設定 printf("適当に何か入力してreturnを押してください >> "); scanf("%d", &seed); srand(seed); //落ちてくる物体の初期値設定 syoki_buttai(); //画面表示 win=gopen(400, 500); winname(win, "DODGE GAME"); STA();//スタート画面 if(ggetevent(&type, &code, &s, &t)==win){//入力待ち if(code==0x073){// sキーを入力した場合 game(); } else if(code == 0x075){// fキーを押した場合 return 0; } } return 0; }
static void load_xfer01_sta(int loglevel, struct xfer01_wavreq *in, struct edes_req *out) { int i, sindex; static char *fid = "load_xfer01_sta"; if (in->nsta == 1 && strcmp(in->sta[0].name, "*") == 0) { out->nsta = NSTA; util_log(loglevel, "%s: expanding station wildcard, nsta=%d", fid, out->nsta); for (i = 0; i < NSTA; i++) { strcpy(out->sta[i].name, STA(i).name); load_xfer01_chn(loglevel, i, &in->sta[0], &out->sta[i]); } } else { util_log(loglevel, "%s: remapping %d (in->nsta) station requests", fid, in->nsta); for (out->nsta = 0, i = 0; i < in->nsta; i++) { if ((sindex = StationIndex(in->sta[i].name)) != -1) { strcpy(out->sta[out->nsta].name, in->sta[i].name); util_log(loglevel, "%s: name=%s", fid, out->sta[out->nsta].name); load_xfer01_chn(loglevel, sindex, &in->sta[i], &out->sta[out->nsta]); ++out->nsta; } else { util_log(loglevel, "%s: reject unsupported station %s", fid, in->sta[i].name); } } } }
static int StationIndex(char *name) { int i; for (i = 0; i < NSTA; i++) { if (strcasecmp(STA(i).name, name) == 0) return i; } return -1; }
static void sndwrterr(CSOUND *csound, int nret, int nput) { csound->ErrorMsg(csound, Str("soundfile write returned bytecount of %d, not %d"), nret, nput); csound->ErrorMsg(csound, Str("(disk may be full...\n closing the file ...)")); STA(outbufrem) = csound->oparms->outbufsamps; /* consider buf is flushed */ sfcloseout(csound); /* & try to close the file */ csound->Die(csound, Str("\t... closed\n")); }
static inline void sndfilein_(CSOUND *csound, MYFLT scaleFac) { OPARMS *O = csound->oparms; int i, n, nsmps, bufpos; nsmps = csound->nspin; bufpos = (int) O->inbufsamps - (int) STA(inbufrem); for (i = 0; i<nsmps; i++) { if ((int) STA(inbufrem) < 1) { STA(inbufrem) = 0U; do { n = ((int) O->inbufsamps - (int) STA(inbufrem)) * (int) sizeof(MYFLT); n = csound->audrecv(csound, STA(inbuf) + (int) STA(inbufrem), n); STA(inbufrem) += (unsigned int) (n / (int) sizeof(MYFLT)); } while ((int) STA(inbufrem) < (int) O->inbufsamps); bufpos = 0; } csound->spin[i] = STA(inbuf)[bufpos++] * scaleFac; STA(inbufrem)--; } }
void DoSTAIfCan(HDesign& hd) { if (hd.CanDoTiming()) { WRITELINE(""); ALERT("Running STA:"); STA(hd); FindCriticalPaths(hd); PrintTimingReport(hd, hd.cfg.ValueOf("CriticalPaths.countLogReportCriticalPaths", 0)); hd.Plotter->PlotMostCriticalPaths(hd, hd.cfg.ValueOf("CriticalPaths.countPlotCriticalPaths", 0)); } }
static int readsf(CSOUND *csound, MYFLT *inbuf, int inbufsize) { int i, n; (void) csound; n = inbufsize / (int) sizeof(MYFLT); i = (int) sf_read_MYFLT(STA(infile), inbuf, n); if (UNLIKELY(i < 0)) return inbufsize; memset(&inbuf[i], 0, (n-i)*sizeof(MYFLT)); return inbufsize; }
bool DoDetailedPlacementIfRequired(HDPGrid& grid, const char* cfgOptName) { if (grid.Design().cfg.ValueOf(cfgOptName, false)) { DetailedPlacement(grid); WRITELINE(""); if (grid.Design().CanDoTiming()) ALERT("STA after detailed placement:"); STA(grid.Design()); return true; } return false; }
bool DoRandomPlacementIfRequired(HDesign& hd, const char* cfgOptName) { if (hd.cfg.ValueOf(cfgOptName, false)) { RandomPlacement(hd); WRITELINE(""); if (hd.CanDoTiming()) ALERT("STA after random placement:"); STA(hd); return true; } return false; }
bool DoGlobalPlacementIfRequired(HDesign& hd, const char* cfgOptName) { if (hd.cfg.ValueOf(cfgOptName, false)) { GlobalPlacement(hd, hd.cfg.ValueOf("params.objective")); WRITELINE(""); if (hd.CanDoTiming()) ALERT("STA after global placement:"); STA(hd); return true; } return false; }
static void writesf(CSOUND *csound, const MYFLT *outbuf, int nbytes) { OPARMS *O = csound->oparms; int n; if (UNLIKELY(STA(outfile) == NULL)) return; n = (int) sf_write_MYFLT(STA(outfile), (MYFLT*) outbuf, nbytes / sizeof(MYFLT)) * (int) sizeof(MYFLT); if (UNLIKELY(n < nbytes)) sndwrterr(csound, n, nbytes); if (UNLIKELY(O->rewrt_hdr)) rewriteheader((void *)STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, "%c\010", "|/-\\"[csound->nrecs & 3]); break; case 2: csound->MessageS(csound, CSOUNDMSG_REALTIME, "."); break; case 3: { char s[512]; CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); } } break; case 4: csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", "\a"); break; } }
void RTclose(CSOUND *csound) { if (csound->oparms->Linein == 0) return; csound->oparms->Linein = 0; csound->Message(csound, Str("stdmode = %.8x Linefd = %d\n"), STA(stdmode), csound->Linefd); #ifdef PIPES if (csound->oparms->Linename[0] == '|') _pclose(csound->Linepipe); else #endif { if (strcmp(csound->oparms->Linename, "stdin") != 0) close(csound->Linefd); #if !defined(DOSGCC) && !defined(WIN32) else fcntl(csound->Linefd, F_SETFL, STA(stdmode)); #endif } //csound->Free(csound, csound->lineventGlobals); //csound->lineventGlobals = NULL; }
void csoundInputMessageInternal(CSOUND *csound, const char *message) { int32 size = (int32) strlen(message); int n; if ((n=linevent_alloc(csound, 0)) != 0) return; if (!size) return; if (UNLIKELY((STA(Linep) + size) >= STA(Linebufend))) { int extralloc = STA(Linep) + size - STA(Linebufend); if ((n=linevent_alloc(csound, STA(linebufsiz) + extralloc ), 0) != 0) { csoundErrorMsg(csound, Str("LineBuffer Overflow - " "Input Data has been Lost")); return; } } memcpy(STA(Linep), message, size); if (STA(Linep)[size - 1] != (char) '\n') STA(Linep)[size++] = (char) '\n'; STA(Linep) += size; }
bool DoNewBufferingIfRequired(HDesign& hd, const char* cfgOptName) { if (hd.cfg.ValueOf(cfgOptName, false)) { ALERT("NEW BUFFERING STARTED"); ConfigContext ctx(hd.cfg.OpenContext("New_Buffering")); HVGAlgorithm buf(hd); buf.NetlistBuffering(); STA(hd); ALERT("NEW BUFFERING FINISHED"); return true; } return false; }
bool DoLRTimingDrivenPlacementIfRequired(HDesign& hd, const char* cfgOptName) { if (hd.cfg.ValueOf(cfgOptName, false)) { GlobalPlacement(hd, "LR"); WRITELINE(""); if (hd.CanDoTiming()) { //ALERT("No wire STA:"); //NoWireDelaySTA(hd); ALERT("STA after LR placement:"); STA(hd); } return true; } return false; }
bool DoBufferingIfRequired(HDesign& hd, const char* cfgOptName) { //BUFFERING if (hd.cfg.ValueOf(cfgOptName, false)) { ConfigContext ctx(hd.cfg.OpenContext("Buffering")); //ExportDEF(hd, "bb_" + hd.Circuit.Name() + ".def"); if (hd.cfg.ValueOf("Buffering.DoIterative", false)) InsertRepeaters2(hd, hd.cfg.ValueOf("Buffering.Iterations", 40), hd.cfg.ValueOf("Buffering.Percent", 0.70)); else InsertRepeaters2(hd, hd.cfg.ValueOf("Buffering.Percent", 0.70)); STA(hd); return true; } return false; }
bool DoLegalizationIfRequired(HDPGrid& grid, const char* cfgOptName) { if (grid.Design().cfg.ValueOf(cfgOptName, false)) { Legalization(grid); WRITELINE(""); if (grid.Design().CanDoTiming()) { //ALERT("No wire STA:"); //NoWireDelaySTA(grid.Design()); ALERT("STA after legalization:"); STA(grid.Design()); } return true; } return false; }
void sfcloseout(CSOUND *csound) { OPARMS *O = csound->oparms; int nb; alloc_globals(csound); if (!STA(osfopen)) return; if ((nb = (O->outbufsamps - STA(outbufrem)) * sizeof(MYFLT)) > 0) { /* flush outbuffer */ csound->nrecs++; csound->audtran(csound, STA(outbuf), nb); } if (STA(pipdevout) == 2 && (!STA(isfopen) || STA(pipdevin) != 2)) { /* close only if not open for input too */ csound->rtclose_callback(csound); } if (STA(pipdevout) == 2) goto report; if (STA(outfile) != NULL) { if (!STA(pipdevout) && O->outformat != AE_VORBIS) sf_command(STA(outfile), SFC_UPDATE_HEADER_NOW, NULL, 0); sf_close(STA(outfile)); STA(outfile) = NULL; } #ifdef PIPES if (STA(pout) != NULL) { _pclose(STA(pout)); STA(pout) = NULL; } #endif report: if (STA(pipdevout) == 2) { csound->Message(csound, "%"PRIi32" %d %s%lu%s%s\n", csound->nrecs, O->outbufsamps, Str("sample blks of "), (unsigned long)sizeof(MYFLT)*8,Str("-bit floats written to "), STA(sfoutname)); } else { csound->Message(csound, Str("%"PRIi32" %d sample blks of %s written to %s"), O->outbufsamps, O->outbufsamps * O->sfsampsize, getstrformat(O->outformat), STA(sfoutname)); if (O->sfheader == 0) csound->Message(csound, Str(" (raw)\n")); else csound->Message(csound, " (%s)\n", type2string(O->filetyp)); } STA(osfopen) = 0; }
void readxfil(CSOUND *csound, EXTRACT_STATICS* extractStatics, FILE *xfp) /* read the extract control file */ { int flag, all; char s[82]; alloc_globals(csound, extractStatics); all = 1; flag = 'i'; /* default -i flag supplied */ STA(onsect) = 1; STA(onbeat) = FL(0.0); /* other default vals */ STA(offsect) = 999; STA(offbeat) = FL(0.0); // while (fscanf(xfp, s) != EOF) { while (fgets(s, 82, xfp) != NULL) { char *c = s; int i; switch (*c) { case 'i': all = 0; // intended no break here case 'f': case 't': flag = *c++; break; default: switch (flag) { case 'i': sscanf(s, "%d", &i); if (i>=0 && i < INSMAX) STA(inslst)[i] = 1; else csound->Die(csound, Str("instrument number out of range")); all = 0; break; case 'f': #if defined(USE_DOUBLE) CS_SSCANF(s, "%d:%lf", &STA(onsect), &STA(onbeat)); #else CS_SSCANF(s, "%d:%f", &STA(onsect), &STA(onbeat)); #endif break; case 't': STA(offsect) = STA(onsect); /* default offsect */ #if defined(USE_DOUBLE) CS_SSCANF(s, "%d:%lf", &STA(offsect), &STA(offbeat)); #else CS_SSCANF(s, "%d:%f", &STA(offsect), &STA(offbeat)); #endif } } } if (all) { char *ip; for (ip = &STA(inslst)[0]; ip < &STA(inslst)[INSMAX]; *ip++ = 1); } STA(ontime) = STA(a0).newp3 = STA(a0).p3val = STA(onbeat); STA(offtime) = STA(f0).newp2 = STA(f0).p2val = STA(offbeat); }
void iotranset(CSOUND *csound) { OPARMS *O; csound->spinrecv = sndfilein; csound->spoutran = spoutsf; if (!csound->enableHostImplementedAudioIO) return; alloc_globals(csound); O = csound->oparms; csound->audrecv = audrecv_dummy; csound->audtran = audtran_dummy; STA(inbufrem) = (unsigned int) O->inbufsamps; STA(outbufrem) = (unsigned int) O->outbufsamps; if (!csound->hostRequestedBufferSize) { O->sfread = 0; O->sfwrite = 0; STA(osfopen) = 0; return; } STA(inbufsiz) = (unsigned int) (O->inbufsamps * (int) sizeof(MYFLT)); STA(inbuf) = (MYFLT*) csound->Calloc(csound, STA(inbufsiz)); STA(outbufsiz) = (unsigned int) (O->outbufsamps * (int) sizeof(MYFLT)); STA(outbuf) = (MYFLT*) csound->Calloc(csound, STA(outbufsiz)); STA(outbufp) = STA(outbuf); O->sfread = 1; O->sfwrite = 1; STA(osfopen) = 1; }
PUBLIC MYFLT *csoundGetInputBuffer(CSOUND *csound) { return STA(inbuf); }
PUBLIC MYFLT *csoundGetOutputBuffer(CSOUND *csound) { return STA(outbuf); }
void sfopenin(CSOUND *csound) /* init for continuous soundin */ { OPARMS *O = csound->oparms; char *sfname, *fullName; SF_INFO sfinfo; int fileType = (int) TYP_RAW; int isfd = 0; /* stdin */ alloc_globals(csound); STA(inbufrem) = (uint32) 0; /* start with empty buffer */ sfname = O->infilename; if (UNLIKELY(sfname == NULL || sfname[0] == '\0')) csound->Die(csound, Str("error: no input file name")); if (strcmp(sfname, "stdin") == 0) { STA(pipdevin) = 1; } #ifdef PIPES else if (sfname[0] == '|') { STA(pin) = _popen(sfname + 1, "r"); isfd = fileno(STA(pin)); STA(pipdevin) = 1; } #endif else { csRtAudioParams parm; /* check for real time audio input, and get device name/number */ parm.devNum = check_rtaudio_name(sfname, &(parm.devName), 0); if (parm.devNum >= 0) { /* set device parameters */ parm.bufSamp_SW = (unsigned int) O->inbufsamps / (unsigned int) csound->inchnls; parm.bufSamp_HW = O->oMaxLag; parm.nChannels = csound->inchnls; parm.sampleFormat = O->informat; parm.sampleRate = (float) csound->esr; /* open devaudio for input */ if (UNLIKELY(csound->recopen_callback(csound, &parm) != 0)) csoundDie(csound, Str("Failed to initialise real time audio input")); /* & redirect audio gets */ csound->audrecv = csound->rtrecord_callback; STA(pipdevin) = 2; /* no backward seeks ! */ goto inset; /* no header processing */ } } /* open file */ memset(&sfinfo, 0, sizeof(SF_INFO)); if (STA(pipdevin)) { STA(infile) = sf_open_fd(isfd, SFM_READ, &sfinfo, 0); if (UNLIKELY(STA(infile) == NULL)) { /* open failed: possibly raw file, but cannot seek back to try again */ const char *sfError = Str(sf_strerror(NULL)); csoundDie(csound, Str("isfinit: cannot open %s -- %s"), sfname, sfError); } } else { fullName = csoundFindInputFile(csound, sfname, "SFDIR;SSDIR"); if (UNLIKELY(fullName == NULL)) /* if not found */ csoundDie(csound, Str("isfinit: cannot open %s"), sfname); STA(infile) = sf_open(fullName, SFM_READ, &sfinfo); if (STA(infile) == NULL) { /* open failed: maybe raw file ? */ memset(&sfinfo, 0, sizeof(SF_INFO)); sfinfo.samplerate = (int) MYFLT2LRND(csound->esr); sfinfo.channels = csound->nchnls; /* FIXME: assumes input sample format is same as output */ sfinfo.format = TYPE2SF(TYP_RAW) | FORMAT2SF(O->outformat); STA(infile) = sf_open(fullName, SFM_READ, &sfinfo); /* try again */ } if (UNLIKELY(STA(infile) == NULL)) { const char *sfError = Str(sf_strerror(NULL)); csoundDie(csound, Str("isfinit: cannot open %s -- %s"), fullName, sfError); } /* only notify the host if we opened a real file, not stdin or a pipe */ csoundNotifyFileOpened(csound, fullName, sftype2csfiletype(sfinfo.format), 0, 0); sfname = fullName; } /* chk the hdr codes */ if (sfinfo.samplerate != (int) MYFLT2LRND(csound->esr)) { csound->Warning(csound, Str("audio_in %s has sr = %d, orch sr = %d"), sfname, (int) sfinfo.samplerate, (int) MYFLT2LRND(csound->esr)); } if (sfinfo.channels != csound->inchnls) { csound->Warning(csound, Str("audio_in %s has %d chnls, orch %d chnls_i"), sfname, (int) sfinfo.channels, csound->inchnls); } /* Do we care about the format? Can assume float?? */ O->informat = SF2FORMAT(sfinfo.format); fileType = (int) SF2TYPE(sfinfo.format); csound->audrecv = readsf; /* will use standard audio gets */ if ((O->informat == AE_FLOAT || O->informat == AE_DOUBLE) && !(fileType == TYP_WAV || fileType == TYP_AIFF || fileType == TYP_W64)) { /* do not scale "raw" floating point files */ csound->spinrecv = sndfilein_noscale; } inset: /* calc inbufsize reqd */ STA(inbufsiz) = (unsigned) (O->inbufsamps * sizeof(MYFLT)); STA(inbuf) = (MYFLT*) csound->Calloc(csound, STA(inbufsiz)); /* alloc inbuf space */ if (STA(pipdevout) == 2) csound->Message(csound, Str("reading %d sample blks of %lu-bit floats from %s\n"), O->inbufsamps * O->sfsampsize, (unsigned long) sizeof(MYFLT)*8, sfname); else { csound->Message(csound, Str("reading %d-byte blks of %s from %s (%s)\n"), O->inbufsamps * (int) sfsampsize(FORMAT2SF(O->informat)), getstrformat(O->informat), sfname, type2string(fileType)); } STA(isfopen) = 1; }
void sfopenout(CSOUND *csound) /* init for sound out */ { /* (not called if nosound) */ OPARMS *O = csound->oparms; char *s, *fName, *fullName; SF_INFO sfinfo; int osfd = 1; /* stdout */ alloc_globals(csound); if (O->outfilename == NULL) { switch (O->filetyp) { case TYP_WAV: case TYP_W64: case TYP_WAVEX: case TYP_RF64: O->outfilename = "test.wav"; break; case TYP_AIFF: O->outfilename = "test.aif"; break; case TYP_AU: O->outfilename = "test.au"; break; case TYP_PAF: O->outfilename = "test.paf"; break; case TYP_SVX: O->outfilename = "test.svx"; break; case TYP_NIST: O->outfilename = "test.sph"; break; case TYP_VOC: O->outfilename = "test.voc"; break; /* case TYP_IRCAM: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_MAT4: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_MAT5: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_PVF: */ /* O->outfilename = ""; */ /* break; */ case TYP_XI: O->outfilename = "test.xi"; break; /* case TYP_HTK: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_SDS: */ /* O->outfilename = "test.sds"; */ /* break; */ case TYP_AVR: O->outfilename = "test.avr"; break; case TYP_SD2: O->outfilename = "test.sd2"; break; case TYP_FLAC: O->outfilename = "test.flac"; break; case TYP_CAF: O->outfilename = "test.caf"; break; case TYP_OGG: O->outfilename = "test.ogg"; break; /* case TYP_MPC2K: */ /* O->outfilename = ""; */ /* break; */ default: O->outfilename = "test"; break; } } STA(sfoutname) = fName = O->outfilename; if (strcmp(fName, "stdout") == 0) { STA(pipdevout) = 1; } #ifdef PIPES else if (fName[0] == '|') { STA(pout) = _popen(fName+1, "w"); osfd = fileno(STA(pout)); STA(pipdevout) = 1; if (O->filetyp == TYP_AIFF || O->filetyp == TYP_WAV) { char fmt_name[6]; if (O->sfsampsize == 8) { strcpy(fmt_name, "AU"); O->filetyp = TYP_AU; } else { strcpy(fmt_name, "IRCAM"); O->filetyp = TYP_IRCAM; } csound->Message(csound, Str("Output file type changed to %s " "for use in pipe\n"), fmt_name); } } #endif else { csRtAudioParams parm; /* check for real time audio output, and get device name/number */ parm.devNum = check_rtaudio_name(fName, &(parm.devName), 1); if (parm.devNum >= 0) { /* set device parameters */ parm.bufSamp_SW = (unsigned int) O->outbufsamps / csound->nchnls; parm.bufSamp_HW = O->oMaxLag; parm.nChannels = csound->nchnls; parm.sampleFormat = O->outformat; parm.sampleRate = (float) csound->esr; csound->spoutran = spoutsf; /* open devaudio for output */ if (UNLIKELY(csound->playopen_callback(csound, &parm) != 0)) csoundDie(csound, Str("Failed to initialise real time audio output")); /* & redirect audio puts */ csound->audtran = csound->rtplay_callback; STA(outbufrem) = parm.bufSamp_SW * parm.nChannels; STA(pipdevout) = 2; /* no backward seeks ! */ if (O->realtime == 1) /* set realtime priority mode */ csound->realtime_audio_flag = 1; goto outset; /* no header needed */ } else if (strcmp(fName, "null") == 0) { STA(outfile) = NULL; if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT && csound->oparms->outformat!=AE_DOUBLE) { if (csound->oparms->outformat==AE_SHORT) if (csound->dither_output==1) csound->audtran = writesf_dither_16; else csound->audtran = writesf_dither_u16; else if (csound->oparms->outformat==AE_CHAR) if (csound->dither_output==1) csound->audtran = writesf_dither_8; else csound->audtran = writesf_dither_u8; else csound->audtran = writesf; } else csound->audtran = writesf; goto outset; } } /* set format parameters */ memset(&sfinfo, 0, sizeof(SF_INFO)); //sfinfo.frames = 0; sfinfo.samplerate = (int) MYFLT2LRND(csound->esr); sfinfo.channels = csound->nchnls; sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); /* open file */ if (STA(pipdevout)) { STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); #ifdef PIPES if (STA(outfile) == NULL) { char fmt_name[6]; if (O->sfsampsize == 8) { if (UNLIKELY(O->filetyp == TYP_AU)) csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, Str(sf_strerror(NULL))); strcpy(fmt_name, "AU"); O->filetyp = TYP_AU; } else { if (UNLIKELY(O->filetyp == TYP_IRCAM)) csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, Str(sf_strerror(NULL))); strcpy(fmt_name, "IRCAM"); O->filetyp = TYP_IRCAM; } csound->Message(csound, Str("Output file type changed to %s " "for use in pipe\n"), fmt_name); sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); } #endif if (UNLIKELY(STA(outfile) == NULL)) csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, Str(sf_strerror(NULL))); sf_command(STA(outfile), SFC_SET_VBR_ENCODING_QUALITY, &O->quality, sizeof(double)); } else { fullName = csoundFindOutputFile(csound, fName, "SFDIR"); if (UNLIKELY(fullName == NULL)) csoundDie(csound, Str("sfinit: cannot open %s"), fName); STA(sfoutname) = fullName; STA(outfile) = sf_open(fullName, SFM_WRITE, &sfinfo); if (UNLIKELY(STA(outfile) == NULL)) csoundDie(csound, Str("sfinit: cannot open %s\n%s"), fullName, sf_strerror (NULL)); sf_command(STA(outfile), SFC_SET_VBR_ENCODING_QUALITY, &O->quality, sizeof(double)); /* only notify the host if we opened a real file, not stdout or a pipe */ csoundNotifyFileOpened(csound, fullName, type2csfiletype(O->filetyp, O->outformat), 1, 0); } /* IV - Feb 22 2005: clip integer formats */ if (O->outformat != AE_FLOAT && O->outformat != AE_DOUBLE) sf_command(STA(outfile), SFC_SET_CLIPPING, NULL, SF_TRUE); sf_command(STA(outfile), SFC_SET_ADD_PEAK_CHUNK, NULL, (csound->peakchunks ? SF_TRUE : SF_FALSE)); #ifdef SOME_FINE_DAY if (csound->dither_output) { /* This may not be written yet!! */ SF_DITHER_INFO ditherInfo; memset(&ditherInfo, 0, sizeof(SF_DITHER_INFO)); ditherInfo.type = SFD_TRIANGULAR_PDF | SFD_DEFAULT_LEVEL; ditherInfo.level = 1.0; ditherInfo.name = (char*) NULL; sf_command(STA(outfile), SFC_SET_DITHER_ON_WRITE, &ditherInfo, sizeof(SF_DITHER_INFO)); } #endif if (!(O->outformat == AE_FLOAT || O->outformat == AE_DOUBLE) || (O->filetyp == TYP_WAV || O->filetyp == TYP_AIFF || O->filetyp == TYP_W64)) csound->spoutran = spoutsf; /* accumulate output */ else csound->spoutran = spoutsf_noscale; if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT && csound->oparms->outformat!=AE_DOUBLE) { if (csound->oparms->outformat==AE_SHORT) csound->audtran = writesf_dither_16; else if (csound->oparms->outformat==AE_CHAR) csound->audtran = writesf_dither_8; else csound->audtran = writesf; } else csound->audtran = writesf; /* Write any tags. */ if ((s = csound->SF_id_title) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_TITLE, s); if ((s = csound->SF_csd_licence) == NULL || *s == '\0') s = csound->SF_id_copyright; if (s != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_COPYRIGHT, s); else if (csound->SF_id_scopyright>=0) { char buff[256]; time_t tt = time(NULL); strftime(buff, 256, "Copyright %Y: ", gmtime(&tt)); strncat(buff,copyrightcode(csound->SF_id_scopyright), 255); buff[255] = '\0'; sf_set_string(STA(outfile), SF_STR_COPYRIGHT, buff); } if ((s = csound->SF_id_software) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_SOFTWARE, s); if ((s = csound->SF_id_artist) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_ARTIST, s); if ((s = csound->SF_id_comment) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_COMMENT, s); if ((s = csound->SF_id_date) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_DATE, s); /* file is now open */ STA(osfopen) = 1; outset: O->sfsampsize = (int) sfsampsize(FORMAT2SF(O->outformat)); /* calc outbuf size & alloc bufspace */ STA(outbufsiz) = O->outbufsamps * sizeof(MYFLT); STA(outbufp) = STA(outbuf) = csound->Malloc(csound, STA(outbufsiz)); if (STA(pipdevout) == 2) csound->Message(csound, Str("writing %d sample blks of %lu-bit floats to %s\n"), O->outbufsamps, (unsigned long) sizeof(MYFLT)*8, STA(sfoutname)); else { csound->Message(csound, Str("writing %d-byte blks of %s to %s"), O->outbufsamps * O->sfsampsize, getstrformat(O->outformat), STA(sfoutname)); if (O->sfheader == 0) csound->Message(csound, Str(" (raw)\n")); else csound->Message(csound, " (%s)\n", type2string(O->filetyp)); } STA(osfopen) = 1; STA(outbufrem) = O->outbufsamps; }
void sfclosein(CSOUND *csound) { alloc_globals(csound); if (!STA(isfopen)) return; if (STA(pipdevin) == 2 && (!STA(osfopen) || STA(pipdevout) != 2)) { /* close only if not open for output too */ csound->rtclose_callback(csound); } else if (STA(pipdevin) != 2) { if (STA(infile) != NULL) sf_close(STA(infile)); #ifdef PIPES if (STA(pin) != NULL) { _pclose(STA(pin)); STA(pin) = NULL; } #endif STA(infile) = NULL; } STA(isfopen) = 0; }