8magsvn – Diff between revs 33 and 35

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 33 Rev 35
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:1,0"; /* playback device */ 17 static char *device = "plughw:0,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 = 98000; /* 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_uframes_t buffer_size = 20004; //samples per frame
24 static snd_pcm_sframes_t period_size=2328; //samples per frame 24 static snd_pcm_uframes_t period_size = 4000;
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 40... Line 40...
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;
45 snd_pcm_uframes_t size; -  
46 int err, dir; 45 int err, dir;
47   46  
48 /* choose all parameters */ 47 /* choose all parameters */
49 err = snd_pcm_hw_params_any(handle, params); 48 err = snd_pcm_hw_params_any(handle, params);
50 if (err < 0) { 49 if (err < 0) {
Line 87... Line 86...
87 return -EINVAL; 86 return -EINVAL;
88 } 87 }
89 else printf("Sampling rate set to %i Hz\n", rate, err); 88 else printf("Sampling rate set to %i Hz\n", rate, err);
90 89
91 /* set the buffer size */ 90 /* set the buffer size */
92 size = buffer_size; -  
93 err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &size); 91 err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_size);
94 if (err < 0) { 92 if (err < 0) {
95 printf("Unable to set buffer size %i for capture: %s\n", (int) buffer_size, snd_strerror(err)); 93 printf("Unable to set maximal buffer size for capture: %s\n", snd_strerror(err));
96 return err; 94 return err;
97 } 95 }
98 if (size != buffer_size) { -  
99 printf("Buffer size doesn't match (requested %i , get %i )\n", (int) buffer_size, (int) size); -  
100 return -EINVAL; -  
101 } -  
102 else printf("Buffer size set to %i \n", (int) size); 96 else printf("Size of capture buffer set to %i\n", (int) buffer_size);
103   97  
104 /* set the period size */ -  
105 size = period_size; -  
106 err = snd_pcm_hw_params_set_period_size_near(handle, params, &size, &dir); 98 snd_pcm_hw_params_set_period_size_near(handle, params, &period_size, &dir);
107 if (err < 0) { 99 if (err < 0) {
108 printf("Unable to set period size %i for capture: %s\n", (int) period_size, snd_strerror(err)); 100 printf("Unable to set maximal period size %i for capture: %s\n", (int) period_size, snd_strerror(err));
109 return err; 101 return err;
110 } 102 }
111 if (size != period_size) { -  
112 printf("Period size doesn't match (requested %i, get %i)\n", (int) period_size, (int) size); -  
113 return -EINVAL; -  
114 } -  
115 else printf("Period size set to %i \n", (int) size); 103 else printf("Size of capture period (FFT width) set to %i\n", (int) period_size);
116   104  
117 /* write the parameters to device */ 105 /* write the parameters to device */
118 err = snd_pcm_hw_params(handle, params); 106 err = snd_pcm_hw_params(handle, params);
119 if (err < 0) { 107 if (err < 0) {
120 printf("Unable to set hw params for capture: %s\n", snd_strerror(err)); 108 printf("Unable to set hw params for capture: %s\n", snd_strerror(err));
Line 175... Line 163...
175 static void async_capture_callback(snd_async_handler_t *ahandler) 163 static void async_capture_callback(snd_async_handler_t *ahandler)
176 { 164 {
177 snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler); 165 snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
178 int err; 166 int err;
179 unsigned int i, n; 167 unsigned int i, n;
180 short signal[30000]; 168 short signal[100000];
181   169  
182 /*signal = calloc( (unsigned int) period_size, sizeof(short) ); 170 /*signal = calloc( (unsigned int) period_size, sizeof(short) );
183 if (signal = NULL) printf("memory allocation failed");*/ 171 if (signal = NULL) printf("memory allocation failed");*/
184   172  
185 while (snd_pcm_avail_update(handle) >= period_size) { // read until data is ready in buffer 173 while (snd_pcm_avail_update(handle) >= period_size) { // read until data is ready in buffer