7a8 > #import 13c14 < SNDSoundStruct * snd ; --- > SNDSoundStruct *snd; 33,39c34,41 < UGINIT ; < float sample, sample1, sample2 ; < long nchan, size, offset ; < long last, chan, nsamp ; < FILE * fptr ; < float interpsnd() ; < struct stat buf ; --- > UGINIT; > float sample, sample1, sample2; > long nchan, size, offset; > long last, chan, nsamp; > FILE *fptr; > float interpsnd(); > struct stat buf; > int snderr; 41,47c43,47 < if( STARTNOTE ) { < if ( < ( fptr = FPLOC( FILEPTR ) = fopen( SLOC( FNAME ), "r" ) ) == NULL < ) { < Error++ ; < PROUT( "SNDFILE: Error opening file '%s'", SLOC( FNAME ) ) ; < return ; --- > if(STARTNOTE) { > if((fptr = FPLOC(FILEPTR) = fopen(SLOC(FNAME), "r" )) == NULL) { > Error++; > PROUT("SNDFILE: Error opening file '%s'",SLOC(FNAME)); > return; 49,66c49,53 < snd = ( SNDSoundStruct * ) calloc( 1, sizeof(SNDSoundStruct) ) ; < fread( snd, sizeof(SNDSoundStruct), 1, fptr ) ; < nchan = LVAL(NCHAN) = snd->channelCount ; < /* < for now, DIY: < */ < stat( SLOC( FNAME ), &buf ) ; < LVAL(SAMPS) = ( buf.st_size - sizeof(SNDSoundStruct) ) >> 1 ; < < chan = VAL( CHANNEL ) ; < LVAL(OFFSET) = < snd->dataLocation + ( ( (long) VAL( FSTART )*nchan + chan ) << 1 ) ; < free( snd ) ; < if( VAL( CHANNEL ) + 1 > snd->channelCount ) { < Error++ ; < PROUT( "SNDFILE: File does not contain '%.0f' channels", < VAL( CHANNEL ) + 1. ) ; < return ; --- > if((snderr = SNDReadSoundfile(SLOC(FNAME),&snd)) != SND_ERR_NONE) { > Error++; > PROUT("SNDFILE: %s",SNDSoundError(snderr)); > PROUT("SNDFILE: offending file '%s'",SLOC(FNAME)); > return; 68c55,75 < VAL( FRAME ) = VAL( FSTART ) ; --- > if(snd->dataFormat != SND_FORMAT_LINEAR_16) { > Error++; > PROUT( "SNDFILE: file '%s' not shortsams",SLOC(FNAME)); > return; > } > if((int) (VAL(CHANNEL) + 1) > snd->channelCount) { > Error++; > PROUT("SNDFILE: File does not contain '%.0f' channels",VAL(CHANNEL) + 1.0); > return; > } > chan = (long int) VAL(CHANNEL); > > nchan = LVAL(NCHAN) = snd->channelCount; > > LVAL(SAMPS) = snd->dataSize >> 1; > > LVAL(OFFSET) = snd->dataLocation + (((((long) VAL(FSTART)) * nchan) + chan) << 1); > > VAL(FRAME) = VAL(FSTART); > > SNDFree(snd); 70,79c77,88 < fptr = FPLOC( FILEPTR ) ; < nsamp = LVAL( SAMPS ) ; < chan = VAL( CHANNEL ) ; < nchan = LVAL( NCHAN ) ; < offset = LVAL( OFFSET ) ; < if( VAL( FEND ) < 0. ) < VAL( FEND ) = nsamp/nchan - 1 ; < size = VAL( FEND ) - VAL( FSTART ) + 1 ; < last = VAL( FEND ) ; < { double frame = VAL( FRAME ) ; --- > fptr = FPLOC(FILEPTR); > nsamp = LVAL(SAMPS); > chan = VAL(CHANNEL); > nchan = LVAL(NCHAN); > offset = LVAL(OFFSET); > > if(VAL(FEND) < 0.0) VAL(FEND) = (float) (nsamp/nchan - 1); > > size = (long int) (VAL(FEND) - VAL(FSTART) + 1.0); > last = (long int) VAL(FEND); > > { double frame = VAL(FRAME); 81,88c90,98 < VAL( OUT )++ = VAL( AMP ) * < interpsnd( fptr, frame, size, last, nchan, offset ) ; < frame += VAL( INCR ) ; < while ( frame >= VAL( FEND ) ) < frame -= size ; < while ( frame <= VAL(FSTART) ) < frame += size ; < UGEND(1) ; --- > VAL(OUT)++ = VAL(AMP) * interpsnd(fptr,frame,size,last,nchan,offset); > > frame += VAL(INCR); > > while(frame >= VAL(FEND)) frame -= (double) size; > > while(frame <= VAL(FSTART)) frame += (double) size; > > UGEND(1); 90c100 < VAL( FRAME ) = frame ; --- > VAL( FRAME ) = frame; 92,93c102,103 < if ( ENDNOTE ) { < fclose( fptr ) ; --- > if(ENDNOTE) { > fclose(fptr); 95a106 > 97c108,110 < FILE * fp ; double frame ; long size, last, nchan, offset ; --- > FILE *fp; > double frame; > long size, last, nchan, offset; 99,104c112,117 < long Int ; < static int first = 1 ; < static long P1, P2 ; < static float S1, S2, Frac, Diff, floatsam ; < static FILE * FP = NULL ; < short sample ; --- > long Int; > static int first = 1; > static long P1, P2; > static float S1, S2, Frac, Diff, floatsam; > static FILE * FP = NULL; > short sample; 106,107c119,120 < first = 0 ; < floatsam = 1./32767. ; --- > first = 0; > floatsam = 1./32767.; 110,112c123,125 < FP = fp ; < P1 = -1 ; < P2 = -2 ; --- > FP = fp; > P1 = -1; > P2 = -2; 116,117c129,130 < P1 = P2 ; < S1 = S2 ; --- > P1 = P2; > S1 = S2; 119,122c132,135 < P2 = P1 = Int ; < fseek( fp, offset + ( ( P1*nchan ) << 1 ), 0 ) ; < fread( &sample, sizeof(short), 1, fp ) ; < S1 = sample*floatsam ; --- > P2 = P1 = Int; > fseek( fp, offset + ( ( P1*nchan ) << 1 ), 0 ); > fread( &sample, sizeof(short), 1, fp ); > S1 = sample*floatsam; 125,128c138,141 < P2 -= size ; < fseek( fp, offset + ( ( P2*nchan ) << 1 ), 0 ) ; < fread( &sample, sizeof(short), 1, fp ) ; < Diff = ( S2 = sample*floatsam ) - S1 ; --- > P2 -= size; > fseek( fp, offset + ( ( P2*nchan ) << 1 ), 0 ); > fread( &sample, sizeof(short), 1, fp ); > Diff = ( S2 = sample*floatsam ) - S1; 131c144 < return( S1 ) ; --- > return( S1 ); 133c146 < return( S1 + Frac*Diff ) ; --- > return( S1 + Frac*Diff ); 138,139c151,152 < UGINIT ; < fprintf( stderr," Unimplemented Unit Generator: SNDFILE\n" ) ; --- > UGINIT; > fprintf( stderr," Unimplemented Unit Generator: SNDFILE\n" );