No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

126 líneas
3.6KB

  1. /* sndinfo describes sounds */
  2. #include "mus-config.h"
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #ifndef _MSC_VER
  7. #include <unistd.h>
  8. #endif
  9. #include <string.h>
  10. #include <errno.h>
  11. #include <time.h>
  12. #include "sndlib.h"
  13. static char *display_maxamps(const char *filename, int chans)
  14. {
  15. char *ampstr;
  16. char fstr[16];
  17. int i, len;
  18. mus_float_t *vals;
  19. mus_long_t *times;
  20. len = chans * 32;
  21. ampstr = (char *)calloc(len, sizeof(char));
  22. vals = (mus_float_t *)calloc(chans, sizeof(mus_float_t));
  23. times = (mus_long_t *)calloc(chans, sizeof(mus_long_t));
  24. snprintf(ampstr, len, "\n max amp%s: ", (chans > 1) ? "s" : "");
  25. mus_sound_maxamps(filename, chans, vals, times);
  26. for (i = 0; i < chans; i++)
  27. {
  28. snprintf(fstr, 16, "%.3f ", vals[i]);
  29. strcat(ampstr, fstr);
  30. }
  31. free(vals);
  32. free(times);
  33. return(ampstr);
  34. }
  35. int main(int argc, char *argv[])
  36. {
  37. int chans, srate, ctr;
  38. mus_sample_t samp_type;
  39. mus_header_t type;
  40. mus_long_t samples;
  41. float length = 0.0;
  42. time_t date;
  43. int *loops = NULL;
  44. char *comment, *header_name;
  45. char *samp_type_info = NULL, *samp_type_name, *ampstr = NULL;
  46. char timestr[64];
  47. if (argc == 1) {printf("usage: sndinfo file\n"); exit(0);}
  48. mus_sound_initialize();
  49. for (ctr = 1; ctr < argc; ctr++)
  50. {
  51. if (mus_file_probe(argv[ctr])) /* see if it exists */
  52. {
  53. date = mus_sound_write_date(argv[ctr]);
  54. srate = mus_sound_srate(argv[ctr]);
  55. if (srate == MUS_ERROR)
  56. {
  57. fprintf(stdout, "%s: not a sound file?\n", argv[ctr]);
  58. continue;
  59. }
  60. chans = mus_sound_chans(argv[ctr]);
  61. samples = mus_sound_samples(argv[ctr]);
  62. comment = mus_sound_comment(argv[ctr]);
  63. if ((chans > 0) && (srate > 0))
  64. length = (float)((double)samples / (double)(chans * srate));
  65. loops = mus_sound_loop_info(argv[ctr]);
  66. type = mus_sound_header_type(argv[ctr]);
  67. header_name = (char *)mus_header_type_name(type);
  68. samp_type = mus_sound_sample_type(argv[ctr]);
  69. if (samp_type != MUS_UNKNOWN_SAMPLE)
  70. samp_type_info = (char *)mus_sample_type_name(samp_type);
  71. else
  72. {
  73. int orig_type;
  74. if (samp_type_info == NULL) samp_type_info = (char *)calloc(64, sizeof(char));
  75. orig_type = mus_sound_original_sample_type(argv[ctr]);
  76. samp_type_name = (char *)mus_header_original_sample_type_name(orig_type, type);
  77. if (samp_type_name)
  78. snprintf(samp_type_info, 64, "%d (%s)", orig_type, samp_type_name);
  79. else snprintf(samp_type_info, 64, "%d", orig_type);
  80. }
  81. fprintf(stdout, "%s:\n srate: %d\n chans: %d\n length: %f",
  82. argv[ctr], srate, chans, length);
  83. if (length < 10.0)
  84. {
  85. int samps;
  86. samps = mus_sound_framples(argv[ctr]);
  87. fprintf(stdout, " (%d sample%s)", samps, (samps != 1) ? "s" : "");
  88. }
  89. fprintf(stdout, "\n");
  90. fprintf(stdout, " header type: %s\n sample type: %s\n ",
  91. header_name,
  92. samp_type_info);
  93. strftime(timestr, 64, "%a %d-%b-%Y %H:%M %Z", localtime(&date));
  94. fprintf(stdout, "written: %s", timestr);
  95. if ((chans > 0) && (mus_sound_maxamp_exists(argv[ctr])))
  96. {
  97. ampstr = display_maxamps(argv[ctr], chans);
  98. if (ampstr) fprintf(stdout, "%s", ampstr);
  99. }
  100. fprintf(stdout, "\n");
  101. if (comment) fprintf(stdout, " comment: %s\n", comment);
  102. if (loops)
  103. {
  104. fprintf(stdout, " loop: %d to %d\n", loops[0], loops[1]);
  105. if (loops[2] != 0)
  106. fprintf(stdout, " loop: %d to %d\n", loops[2], loops[3]);
  107. if (loops[0] != 0)
  108. fprintf(stdout, " base: %d, detune: %d\n", loops[4], loops[5]);
  109. }
  110. }
  111. else
  112. fprintf(stderr, "%s: %s\n", argv[ctr], strerror(errno));
  113. if (ctr < argc - 1) fprintf(stdout, "\n");
  114. }
  115. return(0);
  116. }