static void setAxisNumbers(MYFLT *min, MYFLT *max, char *cmin, char *cmax) { double bmin, bmax, big; int i; /** * Get most significant digit */ bmin = 0.0000001; if (fabs(*min) > bmin) { while ((int)(fabs(*min) / bmin)) bmin = bmin * 10.0; } bmax = 0.0000001; if (fabs((double)*max) > bmax) { while ((i = (int)(FABS(*max) / bmax))) bmax = bmax * 10.0; } if (fabs(bmin) > fabs(bmax)) big = fabs(bmin); else big = fabs(bmax); /** * Set max and minimm to nearest 2nd sig digit */ if (*max == FL(0.0)) i = 0; else i = (int)((*max / big) * 100.0) + 1; *max = (MYFLT) (i * big * 0.01); if (*min == FL(0.0)) i = 0; else i = (int)((*min / big) * 100.0) - 1; *min = (MYFLT) (i * big * 0.01); if (fabs(*max - *min) < 0.0000001) *max = *min + FL(1.0); /* No zero divide */ /** * Write characters */ CS_SPRINTF(cmin, "%g", *min); CS_SPRINTF(cmax, "%g", *max); }
static void fltout(CSOUND *csound, MYFLT n, CORFIL *sco) { char *c, buffer[1024]; CS_SPRINTF(buffer, "%a", (double)n); /* corfile_puts(buffer, sco); */ for (c = buffer; *c != '\0'; c++) corfile_putc(csound, *c, sco); }
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; } }
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; } }
static void nkdump(CSOUND *csound, MYFLT *kp, FILE *ofd, int32_t format, int32_t nk, void *p) { char buf1[256], outbuf[256]; int32_t len = 0; switch(format) { /* place formatted kvals into outbuf */ case 1: { int8_t *bp = (int8_t*) outbuf; len = nk; while (nk--) *bp++ = (int8_t) *kp++; break; } case 4: { int16_t *bp = (int16_t*) outbuf; len = nk * 2; while (nk--) *bp++ = (int16_t) *kp++; break; } case 5: { int32_t *bp = (int32_t*) outbuf; len = nk * 4; while (nk--) *bp++ = (int32_t) *kp++; break; } case 6: { float *bp = (float*) outbuf; len = nk * sizeof(float); while (nk--) *bp++ = (float) *kp++; break; } case 7: outbuf[0] = '\0'; while (--nk) { snprintf(buf1, 256, "%" PRId64 "\t", (int64_t)*kp++); strlcat(outbuf, buf1, 256); } snprintf(buf1, 256, "%" PRId64 "\n", (int64_t)*kp); strlcat(outbuf, buf1, 256); len = strlen(outbuf); break; case 8: *outbuf = '\0'; while (--nk) { CS_SPRINTF(buf1, "%6.4f\t", *kp++); strlcat(outbuf, buf1, 256); } CS_SPRINTF(buf1, "%6.4f\n", *kp); strlcat(outbuf, buf1, 256); len = strlen(outbuf); break; default: csound->PerfError(csound,&(((KDUMP *)p)->h), Str("unknown kdump format")); } if (UNLIKELY(fwrite(outbuf, len, 1, ofd)!=1)) { /* now write the buffer */ csound->PerfError(csound, &(((KDUMP *)p)->h), Str("write failure in dumpk")); } }
void swritestr(CSOUND *csound, CORFIL *sco, int first) { SRTBLK *bp; char *p, c, isntAfunc; int lincnt, pcnt=0; if (UNLIKELY((bp = csound->frstbp) == NULL)) return; lincnt = 0; if ((c = bp->text[0]) != 'w' && c != 's' && c != 'e') { /* if no warp stmnt but real data, */ /* create warp-format indicator */ if (first) corfile_puts(csound, "w 0 60\n", sco); lincnt++; } nxtlin: lincnt++; /* now for each line: */ p = bp->text; c = *p++; isntAfunc = 1; switch ((int) c) { case 'z': printf("skip z\n"); //corfile_putc('\n', sco); break; case 'f': isntAfunc = 0; /* fall through */ case 'q': case 'i': case 'd': case 'a': corfile_putc(csound, c, sco); corfile_putc(csound, *p++, sco); while ((c = *p++) != SP && c != LF) corfile_putc(csound, c, sco); /* put p1 */ corfile_putc(csound, c, sco); if (c == LF) break; fltout(csound, bp->p2val, sco); /* put p2val, */ corfile_putc(csound, SP, sco); if (first) fltout(csound, bp->newp2, sco); /* newp2, */ while ((c = *p++) != SP && c != LF) ; corfile_putc(csound, c, sco); /* and delim */ if (c == LF) break; if (isntAfunc) { fltout(csound, bp->p3val, sco); /* put p3val, */ corfile_putc(csound, SP, sco); if (first) fltout(csound, bp->newp3, sco); /* newp3, */ while ((c = *p++) != SP && c != LF) ; } else { /*make sure p3s (table length) are ints */ char temp[256]; snprintf(temp,256,"%d ",(int32)bp->p3val); /* put p3val */ fpnum(csound,temp, lincnt, pcnt, sco); corfile_putc(csound, SP, sco); if (first) { snprintf(temp,256,"%d ",(int32)bp->newp3); /* put newp3 */ fpnum(csound,temp, lincnt, pcnt, sco); } while ((c = *p++) != SP && c != LF) ; } pcnt = 3; while (c != LF) { pcnt++; corfile_putc(csound, SP, sco); p = pfout(csound,bp,p,lincnt,pcnt, sco); /* now put each pfield */ c = *p++; } corfile_putc(csound, '\n', sco); break; case 's': case 'e': if (bp->pcnt > 0) { char buffer[80]; CS_SPRINTF(buffer, "f 0 %f %f\n", bp->p2val, bp->newp2); corfile_puts(csound, buffer, sco); } corfile_putc(csound, c, sco); corfile_putc(csound, LF, sco); break; case 'w': case 't': corfile_putc(csound, c, sco); while ((c = *p++) != LF) /* put entire line */ corfile_putc(csound, c, sco); corfile_putc(csound, LF, sco); break; case 'x': case 'y': case -1: break; default: csound->Message(csound, Str("swrite: unexpected opcode %c, section %d line %d\n"), c, csound->sectcnt, lincnt); break; } if ((bp = bp->nxtblk) != NULL) goto nxtlin; }
//--------------------------------------------------------- //--------------------------------------------------------- std::string ToString(s32 in_value) { s8 buffer[16]; u32 size = CS_SPRINTF(buffer, "%d", in_value); return std::string(buffer, buffer + size); }