Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10139
Modified Files: Tag: desiredata d_soundfile.c Log Message: fix c++ warnings
Index: d_soundfile.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v retrieving revision 1.4.4.11.2.10.2.5 retrieving revision 1.4.4.11.2.10.2.6 diff -C2 -d -r1.4.4.11.2.10.2.5 -r1.4.4.11.2.10.2.6 *** d_soundfile.c 9 Jan 2007 16:57:47 -0000 1.4.4.11.2.10.2.5 --- d_soundfile.c 28 Jun 2007 08:50:28 -0000 1.4.4.11.2.10.2.6 *************** *** 410,421 **** char *flag = argv->a_w.w_symbol->s_name + 1; if (!strcmp(flag, "skip")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((onset = argv[1].a_w.w_float) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "nframes")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = argv[1].a_w.w_float) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "bytes")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((bytespersamp = argv[1].a_w.w_float) < 2) || ! bytespersamp > 4) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "normalize")) {normalize = 1; argc -= 1; argv += 1; --- 410,420 ---- char *flag = argv->a_w.w_symbol->s_name + 1; if (!strcmp(flag, "skip")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((onset = (long) argv[1].a_w.w_float) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "nframes")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = (long) argv[1].a_w.w_float) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "bytes")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((bytespersamp = (int) argv[1].a_w.w_float) < 2) || bytespersamp > 4) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "normalize")) {normalize = 1; argc -= 1; argv += 1; *************** *** 497,502 **** nexthdr->ns_format = swap4((bytespersamp == 3 ? NS_FORMAT_LINEAR_24 : (bytespersamp == 4 ? NS_FORMAT_FLOAT : NS_FORMAT_LINEAR_16)), swap); ! nexthdr->ns_sr = swap4(samplerate, swap); ! nexthdr->ns_nchans = swap4(nchannels, swap); strcpy(nexthdr->ns_info, "Pd "); swapstring(nexthdr->ns_info, swap); --- 496,501 ---- nexthdr->ns_format = swap4((bytespersamp == 3 ? NS_FORMAT_LINEAR_24 : (bytespersamp == 4 ? NS_FORMAT_FLOAT : NS_FORMAT_LINEAR_16)), swap); ! nexthdr->ns_sr = swap4((size_t)samplerate, swap); ! nexthdr->ns_nchans = swap4((size_t)nchannels, swap); strcpy(nexthdr->ns_info, "Pd "); swapstring(nexthdr->ns_info, swap); *************** *** 534,538 **** wavehdr->w_fmttag = swap2((bytespersamp == 4 ? WAV_FLOAT : WAV_INT), swap); wavehdr->w_nchannels = swap2(nchannels, swap); ! wavehdr->w_samplespersec = swap4(samplerate, swap); wavehdr->w_navgbytespersec = swap4((int)(samplerate * nchannels * bytespersamp), swap); wavehdr->w_nblockalign = swap2(nchannels * bytespersamp, swap); --- 533,537 ---- wavehdr->w_fmttag = swap2((bytespersamp == 4 ? WAV_FLOAT : WAV_INT), swap); wavehdr->w_nchannels = swap2(nchannels, swap); ! wavehdr->w_samplespersec = swap4(size_t(samplerate), swap); wavehdr->w_navgbytespersec = swap4((int)(samplerate * nchannels * bytespersamp), swap); wavehdr->w_nblockalign = swap2(nchannels * bytespersamp, swap); *************** *** 607,624 **** if (bigendian) { for (j = 0, sp2 = sp, fp = vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = 32768. + (*fp * ff); ! xx -= 32768; ! if (xx < -32767) xx = -32767; ! if (xx > +32767) xx = +32767; ! sp2[0] = (xx >> 8); sp2[1] = xx; } } else { for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = 32768. + (*fp * ff); ! xx -= 32768; ! if (xx < -32767) xx = -32767; ! if (xx > +32767) xx = +32767; ! sp2[1] = (xx >> 8); sp2[0] = xx; } --- 606,621 ---- if (bigendian) { for (j = 0, sp2 = sp, fp = vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = int(32768. + (*fp * ff)) - 0x8000; ! if (xx < -0x7fff) xx = -0x7fff; ! if (xx > +0x7fff) xx = +0x7fff; ! sp2[0] = xx>>8; sp2[1] = xx; } } else { for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = int(32768. + (*fp * ff)) - 0x8000; ! if (xx < -0x7fff) xx = -0x7fff; ! if (xx > +0x7fff) xx = +0x7fff; ! sp2[1] = xx>>8; sp2[0] = xx; } *************** *** 628,647 **** if (bigendian) { for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = 8388608. + (*fp * ff); ! xx -= 8388608; ! if (xx < -8388607) xx = -8388607; ! if (xx > +8388607) xx = +8388607; ! sp2[0] = (xx >> 16); ! sp2[1] = (xx >> 8); sp2[2] = xx; } } else { for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = 8388608. + (*fp * ff); ! xx -= 8388608; ! if (xx < -8388607) xx = -8388607; ! if (xx > +8388607) xx = +8388607; ! sp2[2] = (xx >> 16); ! sp2[1] = (xx >> 8); sp2[0] = xx; } --- 625,642 ---- if (bigendian) { for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = int(8388608. + (*fp * ff)) - 0x800000; ! if (xx < -0x7fffff) xx = -0x7fffff; ! if (xx > +0x7fffff) xx = +0x7fffff; ! sp2[0] = xx>>16; ! sp2[1] = xx>>8; sp2[2] = xx; } } else { for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp++) { ! int xx = int(8388608. + (*fp * ff)) - 0x800000; ! if (xx < -0x7fffff) xx = -0x7fffff; ! if (xx > +0x7fffff) xx = +0x7fffff; ! sp2[2] = xx>>16; ! sp2[1] = xx>>8; sp2[0] = xx; } *************** *** 1368,1382 **** char *flag = argv->a_w.w_symbol->s_name + 1; if (!strcmp(flag, "skip")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((skipframes = argv[1].a_w.w_float) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "nframes")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = argv[1].a_w.w_float) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "raw")) { if (argc < 5 || ! argv[1].a_type != A_FLOAT || ((headersize = argv[1].a_w.w_float) < 0) || ! argv[2].a_type != A_FLOAT || ((channels = argv[2].a_w.w_float) < 1) || (channels > MAXSFCHANS) || ! argv[3].a_type != A_FLOAT || ((bytespersamp = argv[3].a_w.w_float) < 2) || (bytespersamp > 4) || argv[4].a_type != A_SYMBOL || --- 1363,1377 ---- char *flag = argv->a_w.w_symbol->s_name + 1; if (!strcmp(flag, "skip")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((skipframes = long(argv[1].a_w.w_float)) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "nframes")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((nframes = long(argv[1].a_w.w_float)) < 0)) goto usage; argc -= 2; argv += 2; } else if (!strcmp(flag, "raw")) { if (argc < 5 || ! argv[1].a_type != A_FLOAT || ((headersize = int(argv[1].a_w.w_float)) < 0) || ! argv[2].a_type != A_FLOAT || ((channels = int(argv[2].a_w.w_float)) < 1) || (channels > MAXSFCHANS) || ! argv[3].a_type != A_FLOAT || ((bytespersamp = int(argv[3].a_w.w_float)) < 2) || (bytespersamp > 4) || argv[4].a_type != A_SYMBOL || *************** *** 1391,1395 **** argc -= 1; argv += 1; } else if (!strcmp(flag, "maxsize")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((maxsize = argv[1].a_w.w_float) < 0)) goto usage; resize = 1; /* maxsize implies resize. */ argc -= 2; argv += 2; --- 1386,1390 ---- argc -= 1; argv += 1; } else if (!strcmp(flag, "maxsize")) { ! if (argc < 2 || argv[1].a_type != A_FLOAT || ((maxsize = long(argv[1].a_w.w_float)) < 0)) goto usage; resize = 1; /* maxsize implies resize. */ argc -= 2; argv += 2; *************** *** 1559,1563 **** close (fd); } ! return ((float)itemswritten); usage: pd_error(obj, "usage: write [flags] filename tablename..."); --- 1554,1558 ---- close (fd); } ! return itemswritten; usage: pd_error(obj, "usage: write [flags] filename tablename..."); *************** *** 1855,1859 **** static void *readsf_new(t_floatarg fnchannels, t_floatarg fbufsize) { t_readsf *x; ! int nchannels = fnchannels, bufsize = fbufsize, i; char *buf; if (nchannels < 1) nchannels = 1; --- 1850,1854 ---- static void *readsf_new(t_floatarg fnchannels, t_floatarg fbufsize) { t_readsf *x; ! int nchannels = int(fnchannels), bufsize = int(fbufsize), i; char *buf; if (nchannels < 1) nchannels = 1; *************** *** 1961,1964 **** --- 1956,1962 ---- }
+ template <class T> T min(T a, T b) {return a<b?a:b;} + template <class T> T max(T a, T b) {return a>b?a:b;} + /* open method. Called as: open filename [skipframes headersize channels bytespersamp endianness] *************** *** 1982,1989 **** else if (*endian->s_name) pd_error(x, "endianness neither 'b' nor 'l'"); else x->x_bigendian = garray_ambigendian(); ! x->x_onsetframes = (onsetframes > 0 ? onsetframes : 0); ! x->x_skipheaderbytes = (headerbytes > 0 ? headerbytes : (headerbytes == 0 ? -1 : 0)); ! x->x_sfchannels = (channels >= 1 ? channels : 1); ! x->x_bytespersample = (bytespersamp > 2 ? bytespersamp : 2); x->x_eof = 0; x->x_fileerror = 0; --- 1980,1987 ---- else if (*endian->s_name) pd_error(x, "endianness neither 'b' nor 'l'"); else x->x_bigendian = garray_ambigendian(); ! x->x_onsetframes = max(long(onsetframes),0L); ! x->x_skipheaderbytes = int(headerbytes > 0 ? headerbytes : headerbytes == 0 ? -1 : 0); ! x->x_sfchannels = max(int(channels),1); ! x->x_bytespersample = max(int(bytespersamp),2); x->x_eof = 0; x->x_fileerror = 0; *************** *** 2173,2181 **** /******** the object proper runs in the calling (parent) thread ****/
- static void writesf_tick(t_writesf *x); - static void *writesf_new(t_floatarg fnchannels, t_floatarg fbufsize) { t_writesf *x; ! int nchannels = fnchannels, bufsize = fbufsize, i; char *buf; if (nchannels < 1) nchannels = 1; --- 2171,2177 ---- /******** the object proper runs in the calling (parent) thread ****/
static void *writesf_new(t_floatarg fnchannels, t_floatarg fbufsize) { t_writesf *x; ! int nchannels = int(fnchannels), bufsize = int(fbufsize), i; char *buf; if (nchannels < 1) nchannels = 1;