debut de la partie son

Cette révision appartient à :
phyto 2019-04-13 11:43:33 +02:00
Parent f7db16548d
révision 6bbeb33d25
4 fichiers modifiés avec 140 ajouts et 0 suppressions

16
audio/Makefile Fichier normal
Voir le fichier

@ -0,0 +1,16 @@
#
# audio part of the phytotron
#
CC = gcc
CCOPT = -Wall -g -DDEBUG_LEVEL=1
LIBS = -lao -lsndfile -lm
player.o: player.c Makefile
$(CC) ${CCOPT} -c $<
t.o: t.c player.h Makefile
$(CC) ${CCOPT} -c $<
t: player.o t.o Makefile
$(CC) t.o player.o ${LIBS} -o t

98
audio/player.c Fichier normal
Voir le fichier

@ -0,0 +1,98 @@
/*
* Audio player for the phytotron
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <ao/ao.h>
#include <sndfile.h>
/* --------------------------------------------------------------------- */
#define T_BUFF_WAVES (8192*4)
#define T_FNAME 1000
static ao_device *device;
static ao_sample_format format;
static int coefficient;
static int16_t buffer[T_BUFF_WAVES];
/* --------------------------------------------------------------------- */
int init_waveout(int smplrate)
{
int default_driver;
ao_initialize();
default_driver = ao_default_driver_id();
#if DEBUG_LEVEL
fprintf(stderr, "%s : ao default driver #%d\n", __func__, default_driver);
#endif
memset(&format, 0, sizeof(format));
format.bits = 16;
format.channels = 2;
format.rate = smplrate;
format.byte_format = AO_FMT_LITTLE;
device = ao_open_live(default_driver, &format, NULL);
if (device == NULL) {
fprintf(stderr, "Error opening AO device.\n");
return -1;
}
return 0;
}
/* --------------------------------------------------------------------- */
int close_waveout(void)
{
ao_close(device);
ao_shutdown();
return 0;
}
/* --------------------------------------------------------------------- */
int blast_this_file(char *fname)
{
SNDFILE *sndf;
SF_INFO sfinfo;
int foo, lus;
sndf = sf_open(fname, SFM_READ, &sfinfo);
if (NULL==sndf)
{
perror("sf_open");
abort();
}
#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
}
/* do some cleanup */
sf_close(sndf);
return -1;
}
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

3
audio/player.h Fichier normal
Voir le fichier

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

23
audio/t.c Fichier normal
Voir le fichier

@ -0,0 +1,23 @@
/*
* Audio player for the phytotron
*/
#include <stdio.h>
#include "player.h"
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
char *wavname = "1337.wav";
int foo;
foo = blast_this_file(wavname);
fprintf(stderr, "audio blaster -> %d\n", foo);
return 0;
}
/* --------------------------------------------------------------------- */