playing a WAV file
parent
2e538157c5
commit
1bd06fb67b
@ -1,10 +1,10 @@
|
||||
|
||||
/* generic output */
|
||||
|
||||
int init_ao_output(int smplrate);
|
||||
int close_ao_output(void);
|
||||
ao_device * init_ao_output(int smplrate);
|
||||
int close_ao_output(ao_device *dev);
|
||||
|
||||
|
||||
/* tests functions */
|
||||
|
||||
int play_some_stuff(int notused);
|
||||
int play_some_stuff(ao_device *dev, int notused);
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* NcLooper fonctions audio output
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <ao/ao.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "ao_output.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
#define T_BUFF_WAVES 16384
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
int blast_this_file(char *fname, ao_device *dev, int loop)
|
||||
{
|
||||
SNDFILE *sndf;
|
||||
SF_INFO sfinfo;
|
||||
int foo, lus;
|
||||
short *buffer;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__, fname, dev, loop);
|
||||
#endif
|
||||
|
||||
sndf = sf_open(fname, SFM_READ, &sfinfo);
|
||||
if (NULL==sndf)
|
||||
{
|
||||
perror("sf_open");
|
||||
abort();
|
||||
}
|
||||
|
||||
buffer = calloc(T_BUFF_WAVES, sizeof(short)*2);
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate);
|
||||
fprintf(stderr, "frames : %ld\n", sfinfo.frames);
|
||||
fprintf(stderr, "seekable : %d\n", sfinfo.seekable);
|
||||
#endif
|
||||
|
||||
while ((lus = sf_read_short(sndf, buffer, T_BUFF_WAVES))) {
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : %d bytes read\n", fname, lus);
|
||||
#endif
|
||||
foo = ao_play(dev, buffer, T_BUFF_WAVES*2);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : %d played\n", fname, foo);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* do some cleanup */
|
||||
free(buffer);
|
||||
sf_close(sndf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
int blast_this_file(char *fname, ao_device *dev, int loop);
|
Loading…
Reference in New Issue