"Fossies" - the Fresh Open Source Software Archive

Member "snd-20.9/sndinfo.c" (11 Apr 2018, 3703 Bytes) of package /linux/misc/snd-20.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sndinfo.c" see the Fossies "Dox" file reference documentation.

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