Vladimir Oka wrote:
vf***@talktalk.net wrote: I get compile error:
undefined reference to snd_pcm_format_width.
I included the library directory with -I flag on gcc.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include "../include/asoundlib.h"
#include <sys/time.h>
#include <math.h>
A few problems you have here:
- there's a lot of non-standard stuff here, so it's off topic
- there's no program here at all, just some `#include`s
- there's a memory (and oil) leak on lines 42, and 57
Sorry, I was a bit sloppy, the "../include/" is different. I only
pasted the header as that is where it looks for its references right ?
Here is the full code upto the error.
/*
* This small demo sends a simple sinusoidal wave to your speakers.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include "../include/asoundlib.h"
#include <sys/time.h>
#include <math.h>
static char *device = "plughw:0,0"; /* playback
device */
static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample
format */
static unsigned int rate = 44100; /* stream rate
*/
static unsigned int channels = 1; /* count of
channels */
static unsigned int buffer_time = 500000; /* ring buffer
length in us */
static unsigned int period_time = 100000; /* period time
in us */
static double freq = 440; /* sinusoidal
wave frequency in Hz */
static int verbose = 0; /* verbose flag */
static int resample = 1; /* enable
alsa-lib resampling */
static snd_pcm_sframes_t buffer_size;
static snd_pcm_sframes_t period_size;
static snd_output_t *output = NULL;
static void generate_sine(const snd_pcm_channel_area_t *areas,
snd_pcm_uframes_t offset,
int count, double *_phase)
{
static double max_phase = 2. * M_PI;
double phase = *_phase;
double step = max_phase*freq/(double)rate;
double res;
unsigned char *samples[channels], *tmp;
int steps[channels];
unsigned int chn, byte;
int ires;
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1))
- 1;
int bps = snd_pcm_format_width(format) / 8; /* bytes per
sample */
/* verify and prepare the contents of areas */