8magsvn – Diff between revs 31 and 32

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 31 Rev 32
Line 12... Line 12...
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   16  
17 static char *device = "plughw:0,0"; /* playback device */ 17 static char *device = "plughw:1,0"; /* playback device */
18 static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ 18 static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */
19 static unsigned int rate = 48000; /* stream rate */ 19 static unsigned int rate = 24000; /* stream rate */
20 static int resample = 1; /* enable alsa-lib resampling */ 20 static int resample = 1; /* enable alsa-lib resampling */
21 static int period_event = 0; /* produce poll event after each period */ 21 static int period_event = 0; /* produce poll event after each period */
22   22  
23 static snd_pcm_sframes_t buffer_size=7008; // size of buffer at sound card 23 static snd_pcm_sframes_t buffer_size=7007; // size of buffer at sound card
24 static snd_pcm_sframes_t period_size=2336; //samples per frame 24 static snd_pcm_sframes_t period_size=2331; //samples per frame
25 static snd_output_t *output = NULL; 25 static snd_output_t *output = NULL;
26 26
27 FILE *out; 27 FILE *out;
28   28  
29 double df; //frequency resolution 29 double df; //frequency resolution
Line 34... Line 34...
34 fftw_plan fft_plan_left, fft_plan_right; 34 fftw_plan fft_plan_left, fft_plan_right;
35   35  
36 double *spect_avg_left, *spect_avg_right; 36 double *spect_avg_left, *spect_avg_right;
37 unsigned int period; 37 unsigned int period;
38   38  
39 #define PERIODS 50 // number of periods to average 39 #define PERIODS 100 // number of periods to average
40   40  
41   41  
42 static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, unsigned int channels) 42 static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, unsigned int channels)
43 { 43 {
44 unsigned int rrate; 44 unsigned int rrate;
Line 64... Line 64...
64 return err; 64 return err;
65 } 65 }
66 /* set the sample format */ 66 /* set the sample format */
67 err = snd_pcm_hw_params_set_format(handle, params, format); 67 err = snd_pcm_hw_params_set_format(handle, params, format);
68 if (err < 0) { 68 if (err < 0) {
69 printf("Sample format not available for playback: %s\n", snd_strerror(err)); 69 printf("Sample format not available for capture: %s\n", snd_strerror(err));
70 return err; 70 return err;
71 } 71 }
72 /* set the count of channels */ 72 /* set the count of channels */
73 err = snd_pcm_hw_params_set_channels(handle, params, channels); 73 err = snd_pcm_hw_params_set_channels(handle, params, channels);
74 if (err < 0) { 74 if (err < 0) {
75 printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err)); 75 printf("Channels count (%i) not available for capture: %s\n", channels, snd_strerror(err));
76 return err; 76 return err;
77 } 77 }
78 /* set the stream rate */ 78 /* set the stream rate */
79 rrate = rate; 79 rrate = rate;
80 err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0); 80 err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0);
81 if (err < 0) { 81 if (err < 0) {
82 printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); 82 printf("Rate %iHz not available for capture: %s\n", rate, snd_strerror(err));
83 return err; 83 return err;
84 } 84 }
85 if (rrate != rate) { 85 if (rrate != rate) {
86 printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err); 86 printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
87 return -EINVAL; 87 return -EINVAL;
Line 115... Line 115...
115 else printf("Period size set to %i \n", (int) size); 115 else printf("Period size set to %i \n", (int) size);
116   116  
117 /* write the parameters to device */ 117 /* write the parameters to device */
118 err = snd_pcm_hw_params(handle, params); 118 err = snd_pcm_hw_params(handle, params);
119 if (err < 0) { 119 if (err < 0) {
120 printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); 120 printf("Unable to set hw params for capture: %s\n", snd_strerror(err));
121 return err; 121 return err;
122 } 122 }
123 return 0; 123 return 0;
124 } 124 }
125   125