Compare commits

..

No commits in common. "ad54bac3f7880e43fcdf910acfafefcc1d4400cd" and "2e538157c51df38d299cba06d81c4adb7db92291" have entirely different histories.

7 changed files with 32 additions and 165 deletions

View File

@ -2,21 +2,9 @@
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
pilotable au joystick ou par OSC :) pilotée au joystick :)
## Prérequis : ## Prérequis :
libsndfile, libao, liblo, libcurses.avec les bons -dev ! libsndfile, libao, libcurses.
## Compilation :
Pour le moment, vous êtes laissé à vous-même.
## Hacking :
La voie est libre.

View File

@ -6,11 +6,6 @@ LIBS = -lao -lsndfile -lm
ao_output.o: ao_output.c Makefile ao_output.o: ao_output.c Makefile
$(CC) ${CCOPT} -c $< $(CC) ${CCOPT} -c $<
playfile.o: playfile.c Makefile t: t.c ao_output.o Makefile
$(CC) ${CCOPT} -c $< $(CC) ${CCOPT} $< ao_output.o ${LIBS} -o $@
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 output * NcLooper fonctions audio
*/ */
#include <stdio.h> #include <stdio.h>
@ -15,14 +15,13 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
extern int verbosity; static ao_device *device; /* never alone with a singleton */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
ao_device *init_ao_output(int smplrate) int 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);
@ -44,39 +43,33 @@ 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 NULL;
}
#if DEBUG_LEVEL
fprintf(stderr, "%s : device at %p\n", __func__, device);
#endif
return device;
}
/* --------------------------------------------------------------------- */
int close_ao_output(ao_device *dev)
{
if (NULL == dev) {
fprintf(stderr, "%s : no output to close\n", __func__);
return -1; return -1;
} }
ao_close(dev);
ao_shutdown();
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int play_some_stuff(ao_device *dev, int notused) int close_ao_output(void)
{
ao_close(device);
ao_shutdown();
device = NULL;
return 0;
}
/* --------------------------------------------------------------------- */
int play_some_stuff(int notused)
{ {
int i, sample; int i, sample;
char *buffer; char *buffer;
float freq = 440.0; float freq = 440.0;
#define NB_SAMPLES (44100*2) #define NB_SAMPLES 44100
if (NULL == dev) { if (NULL == device) {
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);
@ -92,13 +85,7 @@ 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(dev, buffer, NB_SAMPLES); ao_play(device, buffer, NB_SAMPLES);
free(buffer);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

View File

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

View File

@ -1,72 +0,0 @@
/*
* 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;
}
/* --------------------------------------------------------------------- */

View File

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

View File

@ -3,53 +3,25 @@
*/ */
#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;
while ((opt = getopt(argc, argv, "hv")) != -1) { foo = init_ao_output(44100);
switch(opt) { fprintf(stderr, "AO init -> %d\n", foo);
case 'h': help(0); break;
case 'v': verbosity++; break;
}
}
#if DEBUG_LEVEL foo = play_some_stuff(0);
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);
sleep(1); foo = close_ao_output();
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);