[xmp] Call ALSA using sound driver structure

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 14 years ago
parent 8886da925e
commit 3e2641d653
  1. 17
      src/main.c
  2. 10
      src/sound.h
  3. 38
      src/sound_alsa.c

@ -8,10 +8,13 @@
#include <signal.h>
#include <sys/time.h>
#include <xmp.h>
//#include "sound.h"
#include "sound.h"
#include "common.h"
extern int optind;
extern struct sound_driver sound_alsa;
struct sound_driver *sound = &sound_alsa;
static void cleanup(int sig)
{
@ -21,7 +24,7 @@ static void cleanup(int sig)
signal(SIGFPE, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
sound_deinit();
sound->deinit();
reset_tty();
signal(sig, SIG_DFL);
@ -66,7 +69,7 @@ int main(int argc, char **argv)
shuffle(argc - optind + 1, &argv[optind - 1]);
}
if (sound_init(44100, 2) < 0) {
if (sound->init(44100, 2) < 0) {
fprintf(stderr, "%s: can't initialize sound\n", argv[0]);
exit(EXIT_FAILURE);
}
@ -115,7 +118,7 @@ int main(int argc, char **argv)
break;
info_frame(&mi, new_mod);
sound_play(mi.buffer, mi.buffer_size);
sound->play(mi.buffer, mi.buffer_size);
new_mod = 0;
options.start = 0;
@ -124,14 +127,14 @@ int main(int argc, char **argv)
xmp_player_end(ctx);
}
sound->flush();
xmp_release_module(ctx);
printf("\n");
}
xmp_free_context(ctx);
xmp_free_context(ctx);
reset_tty();
sound_deinit();
sound->deinit();
exit(EXIT_SUCCESS);
}

@ -3,9 +3,11 @@ struct sound_driver {
char *id;
char *description;
char **help;
int (*init) ();
void (*deinit) ();
void (*pause) ();
void (*resume) ();
int (*init)(int, int);
void (*deinit)();
void (*play)(void *, int);
void (*flush)();
void (*pause)();
void (*resume)();
struct list_head *next;
};

@ -6,7 +6,7 @@
static snd_pcm_t *pcm_handle;
int sound_init(int sampling_rate, int channels)
static int init(int sampling_rate, int channels)
{
snd_pcm_hw_params_t *hwparams;
int ret;
@ -51,7 +51,7 @@ int sound_init(int sampling_rate, int channels)
return 0;
}
void sound_play(void *b, int i)
static void play(void *b, int i)
{
int frames;
@ -61,10 +61,40 @@ void sound_play(void *b, int i)
}
}
void sound_deinit()
static void deinit()
{
/* snd_pcm_drain(pcm_handle); */
snd_pcm_close(pcm_handle);
}
static void flush()
{
snd_pcm_drain(pcm_handle);
}
static void onpause()
{
}
static void onresume()
{
}
static char *help[] = {
"buffer=num", "Set the ALSA buffer time in milliseconds",
"period=num", "Set the ALSA period time in milliseconds",
"card <name>", "Select sound card to use",
NULL
};
struct sound_driver sound_alsa = {
"alsa",
"ALSA pcm audio",
help,
init,
deinit,
play,
flush,
onpause,
onresume
};

Loading…
Cancel
Save