Compare commits

...

2 Commits

Author SHA1 Message Date
tth ad54bac3f7 blurpped sound, wtf ? 2019-10-23 19:01:22 +02:00
tth 1bd06fb67b playing a WAV file 2019-10-23 18:46:27 +02:00
7 changed files with 159 additions and 26 deletions

View File

@ -2,9 +2,21 @@
Les scratchmen utilisent des loopers en Flash 11. Les scratchmen utilisent des loopers en Flash 11.
Il est temps qu'ils découvrent une interface ncurses Il est temps qu'ils découvrent une interface ncurses
pilotée au joystick :) pilotable au joystick ou par OSC :)
## Prérequis : ## Prérequis :
libsndfile, libao, libcurses. libsndfile, libao, liblo, libcurses.avec les bons -dev !
## Compilation :
Pour le moment, vous êtes laissé à vous-même.
## Hacking :
La voie est libre.

View File

@ -6,6 +6,11 @@ LIBS = -lao -lsndfile -lm
ao_output.o: ao_output.c Makefile ao_output.o: ao_output.c Makefile
$(CC) ${CCOPT} -c $< $(CC) ${CCOPT} -c $<
t: t.c ao_output.o Makefile playfile.o: playfile.c Makefile
$(CC) ${CCOPT} $< ao_output.o ${LIBS} -o $@ $(CC) ${CCOPT} -c $<
OBJS = ao_output.o playfile.o
t: t.c ${OBJS} Makefile
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@

View File

@ -1,5 +1,5 @@
/* /*
* NcLooper fonctions audio * NcLooper fonctions audio output
*/ */
#include <stdio.h> #include <stdio.h>
@ -15,13 +15,14 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static ao_device *device; /* never alone with a singleton */ extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int init_ao_output(int smplrate) ao_device *init_ao_output(int smplrate)
{ {
int default_driver; int default_driver;
ao_sample_format format; ao_sample_format format;
ao_device *device;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %d )\n", __func__, smplrate); fprintf(stderr, ">>> %s ( %d )\n", __func__, smplrate);
@ -43,33 +44,39 @@ format.byte_format = AO_FMT_LITTLE;
device = ao_open_live(default_driver, &format, NULL); device = ao_open_live(default_driver, &format, NULL);
if (device == NULL) { if (device == NULL) {
fprintf(stderr, "Error opening AO device.\n"); fprintf(stderr, "Error opening AO device.\n");
return -1; return NULL;
} }
#if DEBUG_LEVEL
fprintf(stderr, "%s : device at %p\n", __func__, device);
#endif
return 0; return device;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int close_ao_output(void) int close_ao_output(ao_device *dev)
{ {
ao_close(device); if (NULL == dev) {
ao_shutdown(); fprintf(stderr, "%s : no output to close\n", __func__);
return -1;
}
device = NULL; ao_close(dev);
ao_shutdown();
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int play_some_stuff(int notused) int play_some_stuff(ao_device *dev, int notused)
{ {
int i, sample; int i, sample;
char *buffer; char *buffer;
float freq = 440.0; float freq = 440.0;
#define NB_SAMPLES 44100 #define NB_SAMPLES (44100*2)
if (NULL == device) { if (NULL == dev) {
fprintf(stderr, "%s : please call 'init_ao_output' first\n", fprintf(stderr, "%s : please call 'init_ao_output' first\n",
__func__); __func__);
exit(1); exit(1);
@ -85,7 +92,13 @@ for (i = 0; i < NB_SAMPLES; i++) {
buffer[4*i] = buffer[4*i+2] = sample & 0xff; buffer[4*i] = buffer[4*i+2] = sample & 0xff;
buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff; buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff;
} }
ao_play(device, buffer, NB_SAMPLES); ao_play(dev, buffer, NB_SAMPLES);
free(buffer);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

View File

@ -1,10 +1,10 @@
/* generic output */ /* generic output */
int init_ao_output(int smplrate); ao_device * init_ao_output(int smplrate);
int close_ao_output(void); int close_ao_output(ao_device *dev);
/* tests functions */ /* tests functions */
int play_some_stuff(int notused); int play_some_stuff(ao_device *dev, int notused);

72
audio/playfile.c Normal file
View File

@ -0,0 +1,72 @@
/*
* 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*2
/* --------------------------------------------------------------------- */
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
buffer = calloc(T_BUFF_WAVES, sizeof(short)*2);
if (NULL == buffer) {
fprintf(stderr, "ALLOC FAIL, ABEND in %s\n", __func__);
abort();
}
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
ao_play(dev, buffer, lus*2);
}
/* do some cleanup */
sf_close(sndf);
free(buffer);
return 0;
}
/* --------------------------------------------------------------------- */

3
audio/playfile.h Normal file
View File

@ -0,0 +1,3 @@
int blast_this_file(char *fname, ao_device *dev, int loop);

View File

@ -3,25 +3,53 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <ao/ao.h>
#include "ao_output.h" #include "ao_output.h"
#include "playfile.h"
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int verbosity;
/* --------------------------------------------------------------------- */
void help(int k)
{
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo;
ao_device *device;
int opt;
foo = init_ao_output(44100); while ((opt = getopt(argc, argv, "hv")) != -1) {
fprintf(stderr, "AO init -> %d\n", foo); switch(opt) {
case 'h': help(0); break;
case 'v': verbosity++; break;
}
}
foo = play_some_stuff(0); #if DEBUG_LEVEL
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
#endif
device = init_ao_output(44100);
fprintf(stderr, "AO init -> %p\n", device);
foo = play_some_stuff(device, 0);
fprintf(stderr, "play stuff -> %d\n", foo); fprintf(stderr, "play stuff -> %d\n", foo);
foo = close_ao_output(); sleep(1);
foo = blast_this_file("/home/tth/BU/vrac/1337.wav", device, 0);
fprintf(stderr, "blast file -> %d\n", foo);
foo = close_ao_output(device);
fprintf(stderr, "AO close -> %d\n", foo); fprintf(stderr, "AO close -> %d\n", foo);