sftest.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ** GNU General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #if HAVE_UNISTD_H
  21. #include <unistd.h>
  22. #endif
  23. #include <sndfile.h>
  24. #define BUFFER_SIZE (1024)
  25. static short buffer [BUFFER_SIZE] ;
  26. int
  27. main (int argc, char *argv [])
  28. { SNDFILE *file ;
  29. SF_INFO sfinfo ;
  30. int k, count, max = 0, total = 0 ;
  31. if (argc < 2)
  32. { printf ("Expecting input file name.\n") ;
  33. return 0 ;
  34. } ;
  35. if (! (file = sf_open (argv [1], SFM_READ, &sfinfo)))
  36. { printf ("sf_open_read failed with error : ") ;
  37. puts (sf_strerror (NULL)) ;
  38. exit (1) ;
  39. } ;
  40. while ((count = sf_read_short (file, buffer, BUFFER_SIZE)))
  41. { for (k = 0 ; k < count ; k++)
  42. if (abs (buffer [k]) > max)
  43. max = abs (buffer [k]) ;
  44. total += count ;
  45. } ;
  46. printf ("Total : %d\n", total) ;
  47. printf ("Maximun value : %d\n", max) ;
  48. sf_close (file) ;
  49. return 0 ;
  50. } /* main */