00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #include "stdinc.h"
00032
00033 #include <pulse/simple.h>
00034
00035 #include "audio_file.h"
00036 #include "audio_output.h"
00037 #include "gui.h"
00038
00042 static pa_simple* devptr = NULL;
00046 static pa_sample_spec devfmt = { PA_SAMPLE_S16LE, 0, 0 };
00047
00048 int
00049 audio_output_open(void)
00050 {
00051 return (0);
00052 }
00053
00054 int
00055 audio_output_play(struct audio_file *fd)
00056 {
00057 int16_t buf[2048];
00058 size_t len;
00059
00060 if ((len = audio_file_read(fd, buf, sizeof buf / sizeof(int16_t))) == 0)
00061 return (-1);
00062
00063 if (devfmt.rate != fd->srate || devfmt.channels != fd->channels) {
00064
00065 audio_output_close();
00066
00067 devfmt.rate = fd->srate;
00068 devfmt.channels = fd->channels;
00069 }
00070
00071 if (devptr == NULL) {
00072
00073 devptr = pa_simple_new(NULL, APP_NAME,
00074 PA_STREAM_PLAYBACK, NULL, "Audio output", &devfmt,
00075 NULL, NULL, NULL);
00076 if (devptr == NULL) {
00077 gui_msgbar_warn(_("Cannot open the audio device."));
00078 return (-1);
00079 }
00080 }
00081
00082 if (pa_simple_write(devptr, buf, len * sizeof(int16_t), NULL) != 0) {
00083
00084 audio_output_close();
00085 return (-1);
00086 }
00087
00088 return (0);
00089 }
00090
00091 void
00092 audio_output_close(void)
00093 {
00094 if (devptr != NULL) {
00095
00096 pa_simple_free(devptr);
00097 devptr = NULL;
00098 }
00099 }