aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrtaylor <krtaylor@krtaylor-ThinkPad-T61p.(none)>2012-01-24 17:35:20 -0600
committerkrtaylor <krtaylor@krtaylor-ThinkPad-T61p.(none)>2012-01-24 17:35:20 -0600
commit6b46cdf4f6bc99d635bb70023bbe7021aa4a1ea2 (patch)
treee15ccd850fa1e3dbf7e926298088147ff0684717
parente80f3d70954e9aa5e21cad088dab8c67a4ec48dc (diff)
downloade2eaudiotest-6b46cdf4f6bc99d635bb70023bbe7021aa4a1ea2.tar.gz
Cleanup and drop file handle passing
-rw-r--r--testfreq.c60
-rw-r--r--utils_alsa.c3
2 files changed, 4 insertions, 59 deletions
diff --git a/testfreq.c b/testfreq.c
index ab99887..75e526c 100644
--- a/testfreq.c
+++ b/testfreq.c
@@ -12,7 +12,7 @@
#include <complex.h>
#include <fftw3.h>
-int get_sample(snd_pcm_t *handle, char *device_name, int num_samples, int sample_rate, unsigned short sine_input[]);
+int get_sample(char *device_name, int num_samples, int sample_rate, unsigned short sine_input[]);
int main (int argc, char *argv[])
{
@@ -22,8 +22,6 @@ int main (int argc, char *argv[])
char *device_name = "default"; /* pcm.default */
- snd_pcm_t *handle;
-
unsigned short sine_input[num_samples];
double f_input[num_samples];
double f_output[num_samples];
@@ -37,7 +35,7 @@ int main (int argc, char *argv[])
device_name = argv[1];
}
- if ((rc = get_sample (handle, device_name, num_samples, sample_rate, sine_input)) < 0) {
+ if ((rc = get_sample (device_name, num_samples, sample_rate, sine_input)) < 0) {
fprintf (stderr, "%s: cannot get sample\n", snd_strerror (rc));
exit (1);
}
@@ -73,57 +71,3 @@ int main (int argc, char *argv[])
exit (1);
}
-#ifdef NEVER
-int get_sample(snd_pcm_t *handle, char *device_name, int num_samples, int sample_rate, unsigned short sine_input[])
-{
- int rc;
- snd_pcm_hw_params_t *parms;
-
- /* Open the device */
- if ((rc = snd_pcm_open (&handle, device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
- fprintf (stderr, "%s: cannot open pcm device: %s \n", snd_strerror (rc), device_name);
- return (-1);
- }
- //fprintf (stdout, "Device Opened %s \n", device_name);
-
- /* Configure the device */
- if ((rc = snd_pcm_hw_params_malloc (&parms)) < 0) {
- fprintf (stderr, "%s: cannot malloc parms struct\n", snd_strerror (rc));
- return (-1);
- }
- if ((rc = snd_pcm_hw_params_any (handle, parms)) < 0) {
- fprintf (stderr, "%s: cannot set default parms\n", snd_strerror (rc));
- return (-1);
- }
- if ((rc = snd_pcm_hw_params_set_access (handle, parms, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
- fprintf (stderr, "%s: cannot set interleaved access\n", snd_strerror (rc));
- return (-1);
- }
- if ((rc = snd_pcm_hw_params_set_format (handle, parms, SND_PCM_FORMAT_U8)) < 0) {
- fprintf (stderr, "%s: cannot set format\n", snd_strerror (rc));
- return (-1);
- }
- if ((rc = snd_pcm_hw_params_set_channels (handle, parms, 2)) < 0) {
- fprintf (stderr, "%s: cannot set channels\n", snd_strerror (rc));
- return (-1);
- }
- if ((rc = snd_pcm_hw_params_set_rate_near (handle, parms, &sample_rate, 0)) < 0) {
- fprintf (stderr, "%s: cannot set rate\n", snd_strerror (rc));
- return (-1);
- }
- if ((rc = snd_pcm_hw_params (handle, parms)) < 0) {
- fprintf (stderr, "%s: cannot set parms\n", snd_strerror (rc));
- return (-1);
- }
- snd_pcm_hw_params_free (parms);
-
- /* Get samples of the sine wave */
- if ((rc = snd_pcm_readi (handle, sine_input, num_samples)) != num_samples) {
- fprintf (stderr, "%s: read failed\n", snd_strerror (rc));
- return (-1);
- }
- snd_pcm_close (handle);
-
- return 0;
-}
-#endif
diff --git a/utils_alsa.c b/utils_alsa.c
index e7b2c0c..cabc0a7 100644
--- a/utils_alsa.c
+++ b/utils_alsa.c
@@ -10,10 +10,11 @@
#include <alsa/asoundlib.h>
-int get_sample(snd_pcm_t *handle, char *device_name, int num_samples, int sample_rate, unsigned short sine_input[])
+int get_sample(char *device_name, int num_samples, int sample_rate, unsigned short sine_input[])
{
int rc;
snd_pcm_hw_params_t *parms;
+ snd_pcm_t *handle;
/* Open the device */
if ((rc = snd_pcm_open (&handle, device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0) {