]> sigrok.org Git - libsigrok.git/blobdiff - hardware/alsa/protocol.c
Always interleave analog data with all enabled probes.
[libsigrok.git] / hardware / alsa / protocol.c
index 7799d5bef267725c9bfdc9830b52c805f836b4ea..2d95f8cb17565977c08e84451976c5926bb3716a 100644 (file)
@@ -39,8 +39,10 @@ static const unsigned int rates[] = {
        5512,
        8000,
        11025,
+       12000,
        16000,
        22050,
+       24000,
        32000,
        44100,
        48000,
@@ -49,7 +51,8 @@ static const unsigned int rates[] = {
        96000,
        176400,
        192000,
-       384000, /* Yes, there are sound cards that go this high. */
+       384000,
+       768000, /* Yes, there are sound cards that go this high. */
 };
 
 static void alsa_scan_handle_dev(GSList **devices,
@@ -121,7 +124,8 @@ static void alsa_scan_handle_dev(GSList **devices,
        }
        hwrates[offset++] = 0;
 
-       snd_pcm_close(temp_handle);
+       if ((ret = snd_pcm_close(temp_handle)) < 0)
+               sr_err("Failed to close device: %s.", snd_strerror(ret));
        temp_handle = NULL;
 
        /*
@@ -177,7 +181,10 @@ scan_error_cleanup:
        if (hw_params)
                snd_pcm_hw_params_free(hw_params);
        if (temp_handle)
-               snd_pcm_close(temp_handle);
+               if ((ret = snd_pcm_close(temp_handle)) < 0) {
+                       sr_err("Failed to close device: %s.",
+                              snd_strerror(ret));
+               }
 }
 
 /**
@@ -211,12 +218,12 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di)
        /* TODO */
        (void)options;
 
-       if (snd_ctl_card_info_malloc(&info) < 0) {
-               sr_err("Cannot malloc card info.");
+       if ((ret = snd_ctl_card_info_malloc(&info)) < 0) {
+               sr_dbg("Failed to malloc card info: %s.", snd_strerror(ret));
                return NULL;
        }
-       if (snd_pcm_info_malloc(&pcminfo) < 0) {
-               sr_err("Cannot malloc pcm info.");
+       if ((ret = snd_pcm_info_malloc(&pcminfo) < 0)) {
+               sr_dbg("Cannot malloc pcm info: %s.", snd_strerror(ret));
                return NULL;
        }
 
@@ -224,13 +231,16 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di)
        while (snd_card_next(&card) >= 0 && card >= 0) {
                snprintf(hwcard, sizeof(hwcard), "hw:%d", card);
                if ((ret = snd_ctl_open(&handle, hwcard, 0)) < 0) {
-                       sr_err("Cannot open (%d): %s.", card, snd_strerror(ret));
+                       sr_dbg("Cannot open (%d): %s.", card, snd_strerror(ret));
                        continue;
                }
                if ((ret = snd_ctl_card_info(handle, info)) < 0) {
-                       sr_err("Cannot get hardware info (%d): %s.",
+                       sr_dbg("Cannot get hardware info (%d): %s.",
                               card, snd_strerror(ret));
-                       snd_ctl_close(handle);
+                       if ((ret = snd_ctl_close(handle)) < 0) {
+                               sr_dbg("Cannot close device (%d): %s.",
+                                      card, snd_strerror(ret));
+                       }
                        continue;
                }
                dev = -1;
@@ -246,8 +256,8 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di)
                        snd_pcm_info_set_stream(pcminfo,
                                                SND_PCM_STREAM_CAPTURE);
                        if ((ret = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
-                               sr_err("Cannot get device info: %s.",
-                                      snd_strerror(ret));
+                               sr_dbg("Cannot get device info (%s): %s.",
+                                      hwdev, snd_strerror(ret));
                                continue;
                        }
 
@@ -260,7 +270,10 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di)
                        alsa_scan_handle_dev(&devices, cardname, hwdev,
                                             di, pcminfo);
                }
-               snd_ctl_close(handle);
+               if ((ret = snd_ctl_close(handle)) < 0) {
+                       sr_dbg("Cannot close device (%d): %s.",
+                              card, snd_strerror(ret));
+               }
        }
 
        snd_pcm_info_free(pcminfo);
@@ -320,7 +333,7 @@ SR_PRIV int alsa_set_samplerate(const struct sr_dev_inst *sdi,
        } while (devc->supp_rates.list[i++] != 0);
 
        if (!rate) {
-               sr_err("Sample rate " PRIu64 " not supported.", newrate);
+               sr_err("Sample rate %" PRIu64 " not supported.", newrate);
                return SR_ERR_ARG;
        }
 
@@ -383,6 +396,7 @@ SR_PRIV int alsa_receive_data(int fd, int revents, void *cb_data)
        }
 
        /* Send a sample packet with the analog values. */
+       analog.probes = sdi->probes;
        analog.num_samples = count;
        analog.mq = SR_MQ_VOLTAGE; /* FIXME */
        analog.unit = SR_UNIT_VOLT; /* FIXME */