Csound Csound-dev Csound-tekno Search About

[Cs-dev] Questionable code

Date2012-03-26 17:08
Fromjpff
Subject[Cs-dev] Questionable code
In OOps/dumopfs.c I read

static void nkread(CSOUND *csound, MYFLT *kp, FILE *ifd, int format, int nk)
{
    int   len;
    char  inbuf[256];

    switch(format) {               /* place formatted kvals into outbuf */
    case 1: {
      int8_t *bp = (int8_t*)inbuf;
      len = nk;
      fread(inbuf, 1, len, ifd);        /* now read the buffer */
      while (nk--) {
        *kp++ = (MYFLT)*bp++;
        break;
      }
    }
    case 4: {
      int16_t *bp = (int16_t*)inbuf;
      len = nk * 2;
      fread(inbuf, 1, len, ifd);        /* now read the buffer */
      while (nk--)
        *kp++ = (MYFLT)*bp++;
      break;
    }
....

The code in case 1 looks highly suspect.  First it falls through to
case 4 and secondly it only copies one answer.  OK it seems to be my
code but ...  Is my reading correct that this should be

      fread(inbuf, 1, len, ifd);        /* now read the buffer */
      while (nk--)
        *kp++ = (MYFLT)*bp++;
      break;


??
==John ffitch

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2012-03-26 17:12
FromVictor Lazzarini
SubjectRe: [Cs-dev] Questionable code
what's the opcode?
On 26 Mar 2012, at 17:08, jpff wrote:

> In OOps/dumopfs.c I read
> 
> static void nkread(CSOUND *csound, MYFLT *kp, FILE *ifd, int format, int nk)
> {
>    int   len;
>    char  inbuf[256];
> 
>    switch(format) {               /* place formatted kvals into outbuf */
>    case 1: {
>      int8_t *bp = (int8_t*)inbuf;
>      len = nk;
>      fread(inbuf, 1, len, ifd);        /* now read the buffer */
>      while (nk--) {
>        *kp++ = (MYFLT)*bp++;
>        break;
>      }
>    }
>    case 4: {
>      int16_t *bp = (int16_t*)inbuf;
>      len = nk * 2;
>      fread(inbuf, 1, len, ifd);        /* now read the buffer */
>      while (nk--)
>        *kp++ = (MYFLT)*bp++;
>      break;
>    }
> ....
> 
> The code in case 1 looks highly suspect.  First it falls through to
> case 4 and secondly it only copies one answer.  OK it seems to be my
> code but ...  Is my reading correct that this should be
> 
>      fread(inbuf, 1, len, ifd);        /* now read the buffer */
>      while (nk--)
>        *kp++ = (MYFLT)*bp++;
>      break;
> 
> 
> ??
> ==John ffitch
> 
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here 
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2012-03-26 18:07
FromTito Latini
SubjectRe: [Cs-dev] Questionable code
AttachmentsNone