]>
iEval git - audio-libsamplerate.git/blob - util.c
db4de8aed2ed4e6c44ce4dec9d5df2f370756e24
2 ** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
3 ** All rights reserved.
5 ** This code is released under 2-clause BSD license. Please see the
6 ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
18 #define M_PI 3.14159265358979323846264338
22 gen_windowed_sines (int freq_count
, const double *freqs
, double max
, float *output
, int output_len
)
24 double amplitude
, phase
;
26 amplitude
= max
/ freq_count
;
28 for (k
= 0 ; k
< output_len
; k
++)
31 for (freq
= 0 ; freq
< freq_count
; freq
++)
32 { phase
= 0.9 * M_PI
/ freq_count
;
34 if (freqs
[freq
] <= 0.0 || freqs
[freq
] >= 0.5)
35 { printf ("\n%s : Error : freq [%d] == %g is out of range. Should be < 0.5.\n", __FILE__
, freq
, freqs
[freq
]) ;
39 for (k
= 0 ; k
< output_len
; k
++)
40 output
[k
] += amplitude
* sin (freqs
[freq
] * (2 * k
) * M_PI
+ phase
) ;
43 /* Apply Hanning Window. */
44 for (k
= 0 ; k
< output_len
; k
++)
45 output
[k
] *= 0.5 - 0.5 * cos ((2 * k
) * M_PI
/ (output_len
- 1)) ;
47 /* data [k] *= 0.3635819 - 0.4891775 * cos ((2 * k) * M_PI / (output_len - 1))
48 + 0.1365995 * cos ((4 * k) * M_PI / (output_len - 1))
49 - 0.0106411 * cos ((6 * k) * M_PI / (output_len - 1)) ;
53 } /* gen_windowed_sines */
56 save_oct_float (char *filename
, float *input
, int in_len
, float *output
, int out_len
)
60 printf ("Dumping input and output data to file : %s.\n\n", filename
) ;
62 if (! (file
= fopen (filename
, "w")))
65 fprintf (file
, "# Not created by Octave\n") ;
67 fprintf (file
, "# name: input\n") ;
68 fprintf (file
, "# type: matrix\n") ;
69 fprintf (file
, "# rows: %d\n", in_len
) ;
70 fprintf (file
, "# columns: 1\n") ;
72 for (k
= 0 ; k
< in_len
; k
++)
73 fprintf (file
, "% g\n", input
[k
]) ;
75 fprintf (file
, "# name: output\n") ;
76 fprintf (file
, "# type: matrix\n") ;
77 fprintf (file
, "# rows: %d\n", out_len
) ;
78 fprintf (file
, "# columns: 1\n") ;
80 for (k
= 0 ; k
< out_len
; k
++)
81 fprintf (file
, "% g\n", output
[k
]) ;
85 } /* save_oct_float */
88 save_oct_double (char *filename
, double *input
, int in_len
, double *output
, int out_len
)
92 printf ("Dumping input and output data to file : %s.\n\n", filename
) ;
94 if (! (file
= fopen (filename
, "w")))
97 fprintf (file
, "# Not created by Octave\n") ;
99 fprintf (file
, "# name: input\n") ;
100 fprintf (file
, "# type: matrix\n") ;
101 fprintf (file
, "# rows: %d\n", in_len
) ;
102 fprintf (file
, "# columns: 1\n") ;
104 for (k
= 0 ; k
< in_len
; k
++)
105 fprintf (file
, "% g\n", input
[k
]) ;
107 fprintf (file
, "# name: output\n") ;
108 fprintf (file
, "# type: matrix\n") ;
109 fprintf (file
, "# rows: %d\n", out_len
) ;
110 fprintf (file
, "# columns: 1\n") ;
112 for (k
= 0 ; k
< out_len
; k
++)
113 fprintf (file
, "% g\n", output
[k
]) ;
117 } /* save_oct_double */
120 interleave_data (const float *in
, float *out
, int frames
, int channels
)
123 for (fr
= 0 ; fr
< frames
; fr
++)
124 for (ch
= 0 ; ch
< channels
; ch
++)
125 out
[ch
+ channels
* fr
] = in
[fr
+ frames
* ch
] ;
128 } /* interleave_data */
131 deinterleave_data (const float *in
, float *out
, int frames
, int channels
)
134 for (ch
= 0 ; ch
< channels
; ch
++)
135 for (fr
= 0 ; fr
< frames
; fr
++)
136 out
[fr
+ frames
* ch
] = in
[ch
+ channels
* fr
] ;
139 } /* deinterleave_data */
142 reverse_data (float *data
, int datalen
)
147 right
= datalen
- 1 ;
150 { temp
= data
[left
] ;
151 data
[left
] = data
[right
] ;
152 data
[right
] = temp
;
162 const char *name
= "Unknown", *search
= NULL
;
163 static char buffer
[512] ;
167 #if defined (__linux__)
168 file
= fopen ("/proc/cpuinfo", "r") ;
169 search
= "model name" ;
170 #elif defined (__APPLE__)
171 file
= popen ("/usr/sbin/system_profiler -detailLevel full SPHardwareDataType", "r") ;
172 search
= "Processor Name" ;
174 #elif defined (__FreeBSD__)
175 file
= popen ("sysctl -a", "r") ;
176 search
= "hw.model" ;
186 { printf ("Error : search is NULL in function %s.\n", __func__
) ;
190 while (fgets (buffer
, sizeof (buffer
), file
) != NULL
)
191 if (strstr (buffer
, search
))
194 if ((src
= strchr (buffer
, ':')) != NULL
)
196 while (isspace (src
[0]))
200 /* Remove consecutive spaces. */
202 for (dest
= src
; src
[0] ; src
++)
203 { if (isspace (src
[0]) && isspace (dest
[-1]))
This page took 0.054724 seconds and 3 git commands to generate.