Rev 28 |
|
Rev 29 |
Line 15... |
|
Line 15... |
15 |
#include <fftw3.h> |
|
15 |
#include <fftw3.h> |
16 |
|
|
16 |
|
17 |
static char *device = "plughw:0,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 = 24000; /* stream rate */ |
|
19 |
static unsigned int rate = 24000; /* stream rate */ |
20 |
static unsigned int buffer_time = 200000; /* ring buffer length in us */ |
|
20 |
//static unsigned int buffer_size = 200000; /* ring buffer length in us */ |
21 |
static unsigned int period_time = 10000; /* period time in us */ |
|
21 |
//static unsigned int period_size = 10000; /* period time in us */ |
22 |
static int verbose = 0; /* verbose flag */ |
|
22 |
static int verbose = 0; /* verbose flag */ |
23 |
static int resample = 1; /* enable alsa-lib resampling */ |
|
23 |
static int resample = 1; /* enable alsa-lib resampling */ |
24 |
static int period_event = 0; /* produce poll event after each period */ |
|
24 |
static int period_event = 0; /* produce poll event after each period */ |
25 |
|
|
25 |
|
26 |
static snd_pcm_sframes_t buffer_size; // size of buffer at sound card |
|
26 |
static snd_pcm_sframes_t buffer_size=7008; // size of buffer at sound card |
27 |
static snd_pcm_sframes_t period_size; //samples per frame |
|
27 |
static snd_pcm_sframes_t period_size=3504; //samples per frame |
28 |
static snd_output_t *output = NULL; |
|
28 |
static snd_output_t *output = NULL; |
29 |
|
|
29 |
|
30 |
FILE *out; |
|
30 |
FILE *out; |
31 |
|
|
31 |
|
32 |
double df; //frequency resolution |
|
32 |
double df; //frequency resolution |
Line 84... |
|
Line 84... |
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; |
88 |
} |
|
88 |
} |
89 |
else printf("Rate set to %i Hz\n", rate, err); |
|
89 |
else printf("Sampling rate set to %i Hz\n", rate, err); |
- |
|
|
90 |
|
90 |
/* set the buffer time */ |
|
91 |
/* set the buffer size */ |
- |
|
|
92 |
size = buffer_size; |
91 |
err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir); |
|
93 |
err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &size); |
92 |
if (err < 0) { |
|
94 |
if (err < 0) { |
93 |
printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); |
|
95 |
printf("Unable to set buffer size %i for capture: %s\n", (int) buffer_size, snd_strerror(err)); |
94 |
return err; |
|
96 |
return err; |
95 |
} |
|
97 |
} |
96 |
err = snd_pcm_hw_params_get_buffer_size(params, &size); |
|
- |
|
97 |
if (err < 0) { |
|
98 |
if (size != buffer_size) { |
98 |
printf("Unable to get buffer size for playback: %s\n", snd_strerror(err)); |
|
99 |
printf("Buffer size doesn't match (requested %i , get %i )\n", (int) buffer_size, (int) size); |
99 |
return err; |
|
100 |
return -EINVAL; |
100 |
} |
|
101 |
} |
101 |
buffer_size = size; |
|
102 |
else printf("Buffer size set to %i \n", (int) size); |
- |
|
|
103 |
|
102 |
/* set the period time */ |
|
104 |
/* set the period size */ |
- |
|
|
105 |
size = period_size; |
103 |
err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, &dir); |
|
106 |
err = snd_pcm_hw_params_set_period_size_near(handle, params, &size, &dir); |
104 |
if (err < 0) { |
|
107 |
if (err < 0) { |
105 |
printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); |
|
108 |
printf("Unable to set period size %i for capture: %s\n", (int) period_size, snd_strerror(err)); |
106 |
return err; |
|
109 |
return err; |
107 |
} |
|
110 |
} |
108 |
err = snd_pcm_hw_params_get_period_size(params, &size, &dir); |
|
- |
|
109 |
if (err < 0) { |
|
111 |
if (size != period_size) { |
110 |
printf("Unable to get period size for playback: %s\n", snd_strerror(err)); |
|
112 |
printf("Period size doesn't match (requested %i, get %i)\n", (int) period_size, (int) size); |
111 |
return err; |
|
113 |
return -EINVAL; |
112 |
} |
|
114 |
} |
113 |
period_size = size; |
|
115 |
else printf("Period size set to %i \n", (int) size); |
- |
|
|
116 |
|
114 |
/* write the parameters to device */ |
|
117 |
/* write the parameters to device */ |
115 |
err = snd_pcm_hw_params(handle, params); |
|
118 |
err = snd_pcm_hw_params(handle, params); |
116 |
if (err < 0) { |
|
119 |
if (err < 0) { |
117 |
printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); |
|
120 |
printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); |
118 |
return err; |
|
121 |
return err; |