aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-05-10 02:20:15 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-05-10 02:20:15 +0000
commitcd3180c70180ae49c0c5611850c18ce0cebdd464 (patch)
tree3998db9723352408f3feb2747bf2d5cd096cba9c /src/audio.c
parent9edafa886bc5d294c9f466d63c1d45876ce358d0 (diff)
downloadmpd-cd3180c70180ae49c0c5611850c18ce0cebdd464.tar.gz
mpd-cd3180c70180ae49c0c5611850c18ce0cebdd464.tar.xz
mpd-cd3180c70180ae49c0c5611850c18ce0cebdd464.zip
stuff for configuring the audio output format (sampling rate, channels, bits)
git-svn-id: https://svn.musicpd.org/mpd/trunk@967 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/audio.c')
-rw-r--r--src/audio.c105
1 files changed, 93 insertions, 12 deletions
diff --git a/src/audio.c b/src/audio.c
index b532c95e4..243f65863 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -28,15 +28,23 @@
#ifdef HAVE_AUDIO
#include <ao/ao.h>
-int audio_write_size;
+static int audio_write_size;
-int audio_ao_driver_id;
-ao_option * audio_ao_options;
+static int audio_ao_driver_id;
+static ao_option * audio_ao_options;
-AudioFormat audio_format;
-ao_device * audio_device = NULL;
+static AudioFormat audio_format;
+static ao_device * audio_device = NULL;
#endif
+static AudioFormat * audio_configFormat = NULL;
+
+static void copyAudioFormat(AudioFormat * dest, AudioFormat * src) {
+ dest->sampleRate = src->sampleRate;
+ dest->bits = src->bits;
+ dest->channels = src->channels;
+}
+
void initAudioDriver() {
#ifdef HAVE_AUDIO
ao_info * ai;
@@ -115,6 +123,81 @@ void initAudioDriver() {
#endif
}
+void getOutputAudioFormat(AudioFormat * inAudioFormat,
+ AudioFormat * outAudioFormat)
+{
+ if(audio_configFormat) {
+ copyAudioFormat(outAudioFormat,audio_configFormat);
+ }
+ else copyAudioFormat(outAudioFormat,inAudioFormat);
+}
+
+void initAudioConfig() {
+ char * conf = getConf()[CONF_AUDIO_OUTPUT_FORMAT];
+ char * test;
+
+ if(NULL == conf) return;
+
+ audio_configFormat = malloc(sizeof(AudioFormat));
+
+ memset(audio_configFormat,0,sizeof(AudioFormat));
+
+ audio_configFormat->sampleRate = strtol(conf,&test,10);
+
+ if(*test!=':') {
+ ERROR("error parsing audio output format: %s\n",conf);
+ exit(EXIT_FAILURE);
+ }
+
+ switch(audio_configFormat->sampleRate) {
+ case 48000:
+ case 44100:
+ break;
+ default:
+ ERROR("sample rate %i can not be used for audio output\n",
+ (int)audio_configFormat->sampleRate);
+ exit(EXIT_FAILURE);
+ }
+
+ audio_configFormat->bits = strtol(test,&test,10);
+
+ if(*test!=':') {
+ ERROR("error parsing audio output format: %s\n",conf);
+ exit(EXIT_FAILURE);
+ }
+
+ switch(audio_configFormat->bits) {
+ case 8:
+ case 16:
+ break;
+ default:
+ ERROR("bits %i can not be used for audio output\n",
+ (int)audio_configFormat->bits);
+ exit(EXIT_FAILURE);
+ }
+
+ audio_configFormat->channels = strtol(test,&test,10);
+
+ if(*test!='\0') {
+ ERROR("error parsing audio output format: %s\n",conf);
+ exit(EXIT_FAILURE);
+ }
+
+ switch(audio_configFormat->channels) {
+ case 1:
+ case 2:
+ break;
+ default:
+ ERROR("channels %i can not be used for audio output\n",
+ (int)audio_configFormat->channels);
+ exit(EXIT_FAILURE);
+ }
+}
+
+void finishAudioConfig() {
+ if(audio_configFormat) free(audio_configFormat);
+}
+
void finishAudioDriver() {
#ifdef HAVE_AUDIO
ao_free_options(audio_ao_options);
@@ -137,19 +220,17 @@ int isCurrentAudioFormat(AudioFormat * audioFormat) {
return 1;
}
-int initAudio(AudioFormat * audioFormat) {
+int openAudioDevice(AudioFormat * audioFormat) {
#ifdef HAVE_AUDIO
ao_sample_format format;
if(audio_device && !isCurrentAudioFormat(audioFormat)) {
- finishAudio();
+ closeAudioDevice();
}
if(!audio_device) {
if(audioFormat) {
- audio_format.bits = audioFormat->bits;
- audio_format.sampleRate = audioFormat->sampleRate;
- audio_format.channels = audioFormat->channels;
+ copyAudioFormat(&audio_format,audioFormat);
}
format.bits = audio_format.bits;
@@ -184,7 +265,7 @@ int playAudio(char * playChunk, int size) {
if(ao_play(audio_device,playChunk,send)==0) {
audioError();
ERROR("closing audio device due to write error\n");
- finishAudio();
+ closeAudioDevice();
return -1;
}
@@ -196,7 +277,7 @@ int playAudio(char * playChunk, int size) {
return 0;
}
-void finishAudio() {
+void closeAudioDevice() {
#ifdef HAVE_AUDIO
if(audio_device) {
blockSignals();