Skip to content
Snippets Groups Projects
frame.c 29.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •     va_list ap;
        int result;
    
        va_start( ap, format);
        result = vfprintf( stderr, format, ap);
        va_end( ap);
        return result;
    }
    
    
    void __attribute__((format(printf,1,2))) fatalerror( const char *format, ...)
    
    {
        va_list ap;
    
        va_start( ap, format);
        vfprintf( stderr, format, ap);
        va_end( ap);
        myexit(1);
    }
    
    void fatalperror( const char *string)
    {
      perror( string);
      myexit( 1);
    }
    
    
    int __attribute__((format(printf,1,2))) say( const char *format, ...)
    
    {
        va_list ap;
        int result;
    
        va_start( ap, format);
        result = vfprintf( stdout, format, ap);
        va_end( ap);
        return result;
    }
    
    
    char *malloccopy( char *string)
    {
        char *result;
    
        result = malloc( strlen( string) + 1);
        if (result != NULL)
    	strcpy( result, string);
        return result;
    }
    
    
    char *mallocconcat( char *one, char *two)
    {
        char *result;
    
        result = malloc( strlen( one) + strlen( two) + 1);
        if (result != NULL)
          {
    	strcpy( result, one);
    	strcat( result, two);
          }
        return result;
    }
    
    double double2db( double value)
    {
      if (value < 0)
        value = -value;
      return 6.0 * log( value / 32767) / log( 2);
    }
    
    
    void readawaysamples( FILE *input, size_t size)
    
    {
      short *buffer;
      int samplesread, count;
    
      buffer = malloc( sizeof( *buffer) * BUFFSIZE);
      if (buffer == NULL) fatalperror("Couldn't allocate buffer");
    
      while (size > 0)
        {
          if (size > BUFFSIZE)
    	count = BUFFSIZE;
          else
    	count = size;
    
    
          samplesread = fread( buffer, sizeof(*buffer), count, input);
          if (ferror( input) != 0)
    
    	fatalperror("Error reading input file");
          size -= samplesread;
        }
      free( buffer);
    }