2019-10-24 03:46:27 +11:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2019-10-24 05:05:23 +11:00
|
|
|
#define T_BUFF_WAVES (16384*2)
|
2019-10-24 03:46:27 +11:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int blast_this_file(char *fname, ao_device *dev, int loop)
|
|
|
|
{
|
|
|
|
SNDFILE *sndf;
|
|
|
|
SF_INFO sfinfo;
|
2019-10-24 05:05:23 +11:00
|
|
|
int foo, lus, pass;
|
2019-10-24 03:46:27 +11:00
|
|
|
short *buffer;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__, fname, dev, loop);
|
|
|
|
#endif
|
|
|
|
|
2019-10-24 04:01:22 +11:00
|
|
|
buffer = calloc(T_BUFF_WAVES, sizeof(short)*2);
|
|
|
|
if (NULL == buffer) {
|
|
|
|
fprintf(stderr, "ALLOC FAIL, ABEND in %s\n", __func__);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2019-10-24 03:46:27 +11:00
|
|
|
sndf = sf_open(fname, SFM_READ, &sfinfo);
|
|
|
|
if (NULL==sndf)
|
|
|
|
{
|
|
|
|
perror("sf_open");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = calloc(T_BUFF_WAVES, sizeof(short)*2);
|
|
|
|
|
2019-11-04 04:58:21 +11:00
|
|
|
if (verbosity) {
|
|
|
|
fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate);
|
|
|
|
fprintf(stderr, "frames : %ld\n", sfinfo.frames);
|
|
|
|
fprintf(stderr, "seekable : %d\n", sfinfo.seekable);
|
|
|
|
}
|
2019-10-24 03:46:27 +11:00
|
|
|
|
2019-10-24 05:05:23 +11:00
|
|
|
for (pass=0; pass<loop; pass++) {
|
2019-10-24 03:46:27 +11:00
|
|
|
|
2019-10-24 05:05:23 +11:00
|
|
|
sf_seek(sndf, 0, SEEK_SET);
|
|
|
|
|
|
|
|
while ((lus = sf_read_short(sndf, buffer, T_BUFF_WAVES))) {
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, "%s : %d bytes read\n", fname, lus);
|
2019-10-24 03:46:27 +11:00
|
|
|
#endif
|
2019-10-24 05:05:23 +11:00
|
|
|
ao_play(dev, buffer, lus*2);
|
|
|
|
}
|
|
|
|
|
2019-10-24 03:46:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do some cleanup */
|
|
|
|
sf_close(sndf);
|
2019-10-24 04:01:22 +11:00
|
|
|
free(buffer);
|
2019-10-24 03:46:27 +11:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|