-1

I have an audio format conversion from an scientific audio filetype that existed prior to the internet (called TFD v1) an uncompressed uncomplicated simple raw array of sample values... In the get_signal() function on this page, i don't know how the sample values are formatted and why i need the sample rate to read 256 points from the array?

  fscanf (filepointer         , "%d\n%lg\n" , sig_length,  fsam         );
  fscanf (raw_audio_array_file,     ??      ,     256   ,  SRate_Float  );


    /*******************************************************
    * function get_signal reads signal data into sig_re from
    * the file pointed to by filepointer. If the file is a
    * type 2 TFD file then the imaginary part is set too.
    * If the signal is type 1, its hilbert transform is
    * returned in the imaginary part (sig_im).
    ********************************************************/


    void    get_signal (filepointer, sig_re, sig_im, fsam, sig_length)
        FILE   *filepointer;
        double  sig_re[],
                sig_im[],
               *fsam;
        int    *sig_length;

    {
        register int i; /* counter variable */
        int     sigtype; /* data file type */
        double  dummy1,
                dummy2; /* dummy temporary variables */


        fscanf (filepointer, "%d\n", &sigtype);
        if (sigtype == 1) { /* Type one TFD file */
     fscanf (filepointer, "%d\n%lg\n", sig_length, fsam);
     for (i = 0; i < *sig_length; i++) {
         fscanf (filepointer, "%lg\n", &sig_re[i]);
     }
     analytic (sig_re, sig_im, *sig_length);
        }
        else {
     if (sigtype == 2) { /* Type 2 TFD file */
         fprintf(stderr,"Complex signal.\n");    
         fscanf (filepointer, "%d\n%lg\n", sig_length, fsam);
         for (i = 0; i < *sig_length; i++) {
     fscanf (filepointer, "(%lg,%lg)\n", &sig_re[i], &sig_im[i]);
     printf("%lg\n",sig_re[i]);     
         }
     }
     else {
         fprintf (stderr, "ccg : incorrect input format.\n");
         exit (7);
     }
     fclose (filepointer);
        }
    } /* END OF FUNCTION get_signal */
bandybabboon
  • 2,210
  • 1
  • 23
  • 33
  • Hi Peter K, of the 1000 lines of that complex code, that is the only line which i am having trouble with... It is a verbatim copy paste from the original code, minus the condition for another file-type. Why deny it is your code as if wasn't :)... I just relabeled fsam to SRate_float to simplify the question and illustrate that fsam is float sample rate. Surely you recognize and understand your fscanf function? Previously i was asked to include the code for a question in DSP forum, and now i am told DSP forum isn't for DSP code... i don't fret if you can take a minute to enlighten me. – bandybabboon Apr 17 '16 at 15:18
  • Sorry for misunderstanding. I previously tried this question on stack exchange: what is ...... fscanf (filepointer, "%d\n%lg\n", sig_length, fsam); and the respondants said that the code was not interpretable and that they didn't know what a raw audio or a TFD1 files is and that i should find out, else they could not help(what is a raw audio file? jeez thanks stack buddies). Seeing as you studied TFD and wrote the fscanf clauses, would be so kind as to illustrate in numerical terms what array the fscanf returns? – bandybabboon Apr 17 '16 at 15:25
  • Avoid condescention, you would be surprised at the limitations of your specialized studies compared to someone who is a generalist. The previous C authority to opine on your code said: K&R function declarations are gone for more than a quarter century and three ISO C Standards. Plus, not testing the fscanf return value is a sure recipe for surprises. – Jens... and he couldnt answer my noob question. – bandybabboon Apr 17 '16 at 16:02
  • :-) good that the code was written over 27 years ago then. – Peter K. Apr 17 '16 at 19:10
  • The reason why i thought that there was a problem with the sample rate and the fsam function is that i am getting impressive graphs from your code, although the 22kHz (sample[i]=sin(i/2); ) signals are only peaking at 1/6th of the highest values of of the graph, as if it was based on a 192k sample rate, while the frequencies of under 1khz arrive on and under the lowest value of the returned graph, which is why i though i must have an error with the sample rates. – bandybabboon Apr 17 '16 at 19:24

1 Answers1

2

fscanf (filepointer, "%d\n%lg\n", sig_length, fsam); calls the C function fscanf, which reads formatted data from a file according to a format string.

The format string in this case is "%d\n%lg\n" which breaks down as %d (an integer), a newline, %lg (a double), and another newline. So, basically, it's reading two lines off the file, the first of which should contain an integer with the sample length, and the second which contains the sample rate.

As an example, with a modern sample rate:

1
256
44100.0
1.0
0.98
0.96
...

where the first line is the sigtype, the second and third lines are the signal length (in samples) and the sample rate, and the remaining lines are the signal values.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • That is a problem for me, because the user inputs the sample rate as a run execution argument to run the code from a command prompt, and that value is used as a variable to read the audio file. Converseley, the above example supplies a sample rate specified by the file, which makes the original command line arguement for the sample rate redundant? ... oh ok i get it, that is the contents of the array after it was read using the fscanf clauses. Thanks! that still leaves me with the trouble that the audio array is then sent to an FFT and it doesn't have any headers of the type 1,256,44100.0 ?!? – bandybabboon Apr 17 '16 at 15:54