pdisplay.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
  3. * http://www.trevorwishart.co.uk
  4. * http://www.composersdesktop.com
  5. *
  6. This file is part of the CDP System.
  7. The CDP System is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The CDP System is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the CDP System; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA
  19. *
  20. */
  21. /* PDISPLAY
  22. *
  23. * Open pitch data file (we already know the properties)
  24. * and send pitch data to output stream
  25. * Close file.
  26. */
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <osbind.h>
  31. #include <math.h>
  32. #include <float.h>
  33. #include <float.h>
  34. #include <sfsys.h>
  35. #include <cdplib.h>
  36. const char* cdp_version = "7.1.0";
  37. int main(int argc,char *argv[])
  38. {
  39. size_t buflen,n;
  40. int samps_read;
  41. float *bigfbuf;
  42. int ifd;
  43. if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
  44. fprintf(stdout,"%s\n",cdp_version);
  45. fflush(stdout);
  46. return 0;
  47. }
  48. if(argc != 2) {
  49. fprintf(stdout,"ERROR: Wrong number of arguments: pdisplay sndfilename.\n");
  50. fflush(stdout);
  51. return 1;
  52. }
  53. /* initialise SFSYS */
  54. if( sflinit("pdisplay") < 0 ) {
  55. fprintf(stdout,"ERROR: Cannot initialise soundfile system.\n");
  56. fflush(stdout);
  57. return 1;
  58. }
  59. buflen = (size_t) Malloc(-1);
  60. if((bigfbuf=(float*)Malloc(buflen+sizeof(float))) == NULL) {
  61. fprintf(stdout,"ERROR: Failed to allocate float buffer.\n");
  62. fflush(stdout);
  63. // sffinish();
  64. return 1;
  65. }
  66. n = ((size_t)bigfbuf+sizeof(float)-1)/sizeof(float) * sizeof(float); /* align bigbuf to word boundary */
  67. bigfbuf = (float*)n;
  68. buflen /= sizeof(float);
  69. /* open input file */
  70. if( (ifd = sndopenEx(argv[1],0,CDP_OPEN_RDONLY)) < 0 ) {
  71. fprintf(stdout,"INFO: Cannot open file: %s\n\t",argv[1]);
  72. fflush(stdout);
  73. Mfree(bigfbuf);
  74. // sffinish();
  75. return 1;
  76. }
  77. while((samps_read = fgetfbufEx(bigfbuf,(int) buflen,ifd,0)) > 0) {
  78. for(n = 0; n < samps_read; n++) {
  79. fprintf(stdout,"INFO: %lf\n",bigfbuf[n]);
  80. fflush(stdout);
  81. }
  82. }
  83. Mfree(bigfbuf);
  84. sndcloseEx(ifd);
  85. // sffinish();
  86. return 1;
  87. }