Example #1
0
ad_rec_t *ad_open_sps (int32 sps)
{
    ad_rec_t *handle;
    struct snd_pcm_channel_info info;
    snd_pcm_t *dspH;

    int err;
    int card;
    int dev;

    if (sps != DEFAULT_SAMPLES_PER_SEC) {
      if(abs(sps - DEFAULT_SAMPLES_PER_SEC) <= SPS_EPSILON) {
	  fprintf(stderr, "Audio sampling rate %d is within %d of %d samples/sec\n",
		  sps, SPS_EPSILON, DEFAULT_SAMPLES_PER_SEC);
      } else {
	fprintf(stderr, "Audio sampling rate %d not supported; must be %d samples/sec\n",
		sps, DEFAULT_SAMPLES_PER_SEC);
	return NULL;
      }
    }
    card = 0;
    dev = 0;
    
    err = snd_pcm_open(&dspH, card, dev, SND_PCM_OPEN_DUPLEX); /* XXX */
    if (err < 0) {
	fprintf(stderr, "Error opening audio device %d,%din full-duplex: %s\n",
		card, dev, snd_strerror(err));
	return NULL;
    }
    err = snd_pcm_plugin_info(dspH, &info);
    if (err < 0) {
	fprintf(stderr, "Error getting PCM plugin info: %s\n", snd_strerror(err));
	return NULL;
    }

    if (setparams(sps, dspH) < 0) {
	return NULL;
    }
    if (setlevels(0, 0) < 0) {
	return NULL;
    }

    if ((handle = (ad_rec_t *) calloc (1, sizeof(ad_rec_t))) == NULL) {
	fprintf(stderr, "calloc(%d) failed\n", sizeof(ad_rec_t));
	abort();
    }
    
    handle->dspH = dspH;
    handle->recording = 0;
    handle->sps = sps;
    handle->bps = sizeof(int16);

    return(handle);
}
Example #2
0
ad_rec_t *
ad_open_dev(const char *dev, int32 sps)
{
    ad_rec_t *handle;
    snd_pcm_t *dspH;

    int err;

    if (dev == NULL)
        dev = DEFAULT_DEVICE;

    err = snd_pcm_open(&dspH, dev, SND_PCM_STREAM_CAPTURE, 0);
    if (err < 0) {
        fprintf(stderr,
                "Error opening audio device %s for capture: %s\n",
                dev, snd_strerror(err));
        return NULL;
    }

    if (setparams(sps, dspH) < 0) {
        return NULL;
    }
    if (setlevels(dev) < 0) {
        return NULL;
    }
    if ((handle = (ad_rec_t *) calloc(1, sizeof(ad_rec_t))) == NULL) {
        fprintf(stderr, "calloc(%d) failed\n", (int)sizeof(ad_rec_t));
        abort();
    }

    handle->dspH = dspH;
    handle->recording = 0;
    handle->sps = sps;
    handle->bps = sizeof(int16);

    return (handle);
}