Rev 35 |
|
Rev 36 |
Line 11... |
|
Line 11... |
11 |
#include <getopt.h> |
|
11 |
#include <getopt.h> |
12 |
#include <alsa/asoundlib.h> |
|
12 |
#include <alsa/asoundlib.h> |
13 |
#include <sys/time.h> |
|
13 |
#include <sys/time.h> |
14 |
#include <math.h> |
|
14 |
#include <math.h> |
15 |
#include <fftw3.h> |
|
15 |
#include <fftw3.h> |
- |
|
|
16 |
#include <signal.h> |
16 |
|
|
17 |
|
17 |
static char *device = "plughw:0,0"; /* playback device */ |
|
18 |
static char *device = "plughw:0,0"; /* playback device */ |
18 |
static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ |
|
19 |
static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ |
19 |
static unsigned int rate = 98000; /* stream rate */ |
|
20 |
static unsigned int rate = 98000; /* stream rate */ |
20 |
static int resample = 1; /* enable alsa-lib resampling */ |
|
21 |
static int resample = 1; /* enable alsa-lib resampling */ |
21 |
static int period_event = 0; /* produce poll event after each period */ |
|
22 |
static int period_event = 0; /* produce poll event after each period */ |
22 |
|
|
23 |
|
23 |
static snd_pcm_uframes_t buffer_size = 20004; //samples per frame |
|
24 |
static snd_pcm_uframes_t buffer_size = 20004; //samples per frame |
24 |
static snd_pcm_uframes_t period_size = 4000; |
|
25 |
static snd_pcm_uframes_t period_size = 4000; |
25 |
static snd_output_t *output = NULL; |
|
26 |
static snd_output_t *output = NULL; |
- |
|
|
27 |
snd_pcm_t *playback_handle, *capture_handle; |
26 |
|
|
28 |
|
27 |
FILE *out; |
|
29 |
FILE *out; |
28 |
|
|
30 |
|
29 |
double df; //frequency resolution |
|
31 |
double df; //frequency resolution |
30 |
unsigned int frequency_bins; // number of output frequency bins |
|
32 |
unsigned int frequency_bins; // number of output frequency bins |
Line 36... |
|
Line 38... |
36 |
double *spect_avg_left, *spect_avg_right; |
|
38 |
double *spect_avg_left, *spect_avg_right; |
37 |
unsigned int period; |
|
39 |
unsigned int period; |
38 |
|
|
40 |
|
39 |
#define PERIODS 100 // number of periods to average |
|
41 |
#define PERIODS 100 // number of periods to average |
40 |
|
|
42 |
|
- |
|
|
43 |
void leave(int sig); |
41 |
|
|
44 |
|
42 |
static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, unsigned int channels) |
|
45 |
static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, unsigned int channels) |
43 |
{ |
|
46 |
{ |
44 |
unsigned int rrate; |
|
47 |
unsigned int rrate; |
45 |
int err, dir; |
|
48 |
int err, dir; |
Line 216... |
|
Line 219... |
216 |
period=0; |
|
219 |
period=0; |
217 |
} |
|
220 |
} |
218 |
// free(signal); |
|
221 |
// free(signal); |
219 |
} |
|
222 |
} |
220 |
|
|
223 |
|
221 |
|
|
- |
|
222 |
int main(int argc, char *argv[]) |
|
224 |
int main(int argc, char *argv[]) |
223 |
{ |
|
225 |
{ |
224 |
snd_pcm_t *playback_handle, *capture_handle; |
|
- |
|
225 |
int err; |
|
226 |
int err; |
226 |
snd_pcm_hw_params_t *hwparams; |
|
227 |
snd_pcm_hw_params_t *hwparams; |
227 |
snd_pcm_sw_params_t *swparams; |
|
228 |
snd_pcm_sw_params_t *swparams; |
228 |
signed short *frame; // pointer to array of samples |
|
229 |
signed short *frame; // pointer to array of samples |
229 |
unsigned int chn; |
|
230 |
unsigned int chn; |
Line 234... |
|
Line 235... |
234 |
|
|
235 |
|
235 |
snd_pcm_hw_params_alloca(&hwparams); |
|
236 |
snd_pcm_hw_params_alloca(&hwparams); |
236 |
snd_pcm_sw_params_alloca(&swparams); |
|
237 |
snd_pcm_sw_params_alloca(&swparams); |
237 |
|
|
238 |
|
238 |
printf("SID monitor 2.0 starting work.. \n"); |
|
239 |
printf("SID monitor 2.0 starting work.. \n"); |
- |
|
|
240 |
(void) signal(SIGINT,leave); |
239 |
|
|
241 |
|
240 |
//open and set capture device |
|
242 |
//open and set capture device |
241 |
if ((err = snd_pcm_open(&capture_handle, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) { |
|
243 |
if ((err = snd_pcm_open(&capture_handle, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) { |
242 |
printf("Playback open error: %s\n", snd_strerror(err)); |
|
244 |
printf("Playback open error: %s\n", snd_strerror(err)); |
243 |
return 0; |
|
245 |
return 0; |
Line 301... |
|
Line 303... |
301 |
|
|
303 |
|
302 |
snd_pcm_close(capture_handle); |
|
304 |
snd_pcm_close(capture_handle); |
303 |
return 0; |
|
305 |
return 0; |
304 |
} |
|
306 |
} |
305 |
|
|
307 |
|
- |
|
|
308 |
void leave(int sig) |
- |
|
|
309 |
{ |
- |
|
|
310 |
printf("\nTerminating.. \n"); |
- |
|
|
311 |
snd_pcm_close(capture_handle); |
- |
|
|
312 |
// fclose(out); |
- |
|
|
313 |
free(spect_avg_left); |
- |
|
|
314 |
free(spect_avg_right); |
- |
|
|
315 |
free(inl); |
- |
|
|
316 |
free(inr); |
- |
|
|
317 |
free(outl); |
- |
|
|
318 |
free(outr); |
- |
|
|
319 |
exit(sig); |
- |
|
|
320 |
} |