git stults online alsa-signals / master snd_dev.h
master

Tree @master (Download .tar.gz)

snd_dev.h @masterraw · history · blame

#ifndef SND_DEV_H
#define SND_DEV_H

#ifdef __cplusplus
extern "C" {
#endif

#include <alsa/asoundlib.h>
#include <poll.h>

typedef struct snd_dev_t
{
  volatile char        kill;

  char                 read;
  char                 write;

  char                *bf;
  unsigned int         bflen;

  unsigned int         byps;
  unsigned int         chans;
  unsigned int         rate;
  unsigned int         frames;
  unsigned int         ptime;

  snd_pcm_t           *handle;
  snd_pcm_hw_params_t *params;

  int                  nfds;
  struct pollfd       *cardfd;
} snd_dev_t;

enum {
  SND_DEV_UINT8,
  SND_DEV_UINT16,
  SND_DEV_UINT32,
  SND_DEV_INT8,
  SND_DEV_INT16,
  SND_DEV_INT32,
  SND_DEV_FLOAT32,
  SND_DEV_FLOAT64,
  SND_DEV_MU_LAW,
  SND_DEV_A_LAW,
};

enum {
  SND_DEV_INTER,
  SND_DEV_NINTER,
};

enum {
  SND_DEV_READ,
  SND_DEV_WRITE,  
};

snd_dev_t  *snd_dev_create (const char *device, unsigned int stream,
			    unsigned int access, unsigned int format,
			    unsigned int channels, unsigned int rate, 
			    unsigned int frames);

void        snd_dev_destroy  (snd_dev_t *sd);

int         snd_dev_poll     (snd_dev_t *sd);

void        snd_dev_transfer (snd_dev_t *sd, void *data,
			      snd_pcm_uframes_t frames);

/* get sample rate */
int         snd_dev_get_rate       (snd_dev_t *sd);

/* get number of channels */
int         snd_dev_get_channels   (snd_dev_t *sd);

/* get period size in frames */
int         snd_dev_get_period     (snd_dev_t *sd);

/* get frame size in bytes */
int         snd_dev_get_frame      (snd_dev_t *sd);

/* get sample size in bytes */
int         snd_dev_get_sample     (snd_dev_t *sd);

/* get sample format (enum) */
int         snd_dev_get_format     (snd_dev_t *sd);

/* gets the time for one period in microseconds */
int         snd_dev_get_ptime      (snd_dev_t *sd);

#ifdef __cplusplus
}
#endif

#endif /* SND_DEV_H */