sftest.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. ** Copyright (C) 1999-2011 Erik de Castro Lopo <[email protected]>
  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. #else
  23. #include "sf_unistd.h"
  24. #endif
  25. #include <sndfile.h>
  26. #define BUFFER_SIZE (1024)
  27. static short buffer [BUFFER_SIZE] ;
  28. int
  29. main (int argc, char *argv [])
  30. { SNDFILE *file ;
  31. SF_INFO sfinfo ;
  32. int k, count, max = 0, total = 0 ;
  33. if (argc < 2)
  34. { printf ("Expecting input file name.\n") ;
  35. return 0 ;
  36. } ;
  37. if (! (file = sf_open (argv [1], SFM_READ, &sfinfo)))
  38. { printf ("sf_open_read failed with error : ") ;
  39. puts (sf_strerror (NULL)) ;
  40. exit (1) ;
  41. } ;
  42. while ((count = sf_read_short (file, buffer, BUFFER_SIZE)))
  43. { for (k = 0 ; k < count ; k++)
  44. if (abs (buffer [k]) > max)
  45. max = abs (buffer [k]) ;
  46. total += count ;
  47. } ;
  48. printf ("Total : %d\n", total) ;
  49. printf ("Maximun value : %d\n", max) ;
  50. sf_close (file) ;
  51. return 0 ;
  52. } /* main */