aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-02-27 23:13:26 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-02-27 23:13:26 +0000
commit821355361ccf360cd1867278178bc6fb32d8abab (patch)
tree609ba1ab13344fba8f9f136c3bf1780be3ef13a5 /src
parent5622edbc98f55852bc079a50690137232fbd82a1 (diff)
downloadmpd-821355361ccf360cd1867278178bc6fb32d8abab.tar.gz
mpd-821355361ccf360cd1867278178bc6fb32d8abab.tar.xz
mpd-821355361ccf360cd1867278178bc6fb32d8abab.zip
audio cleanups
git-svn-id: https://svn.musicpd.org/mpd/trunk@109 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/audio.c22
-rw-r--r--src/audio.h2
-rw-r--r--src/decode.c11
3 files changed, 22 insertions, 13 deletions
diff --git a/src/audio.c b/src/audio.c
index d1f8d863c..d8abc5648 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -131,12 +131,11 @@ int isCurrentAudioFormat(AudioFormat * audioFormat) {
int initAudio(AudioFormat * audioFormat) {
ao_sample_format format;
- if(!audio_device) {
- if(!isCurrentAudioFormat(audioFormat)) {
- finishAudio();
- return 0;
- }
+ if(audio_device && !isCurrentAudioFormat(audioFormat)) {
+ finishAudio();
+ }
+ if(!audio_device) {
format.bits = audioFormat->bits;
format.rate = audioFormat->sampleRate;
format.byte_format = AO_FMT_NATIVE;
@@ -157,24 +156,29 @@ int initAudio(AudioFormat * audioFormat) {
}
-void playAudio(char * playChunk, int size) {
+int playAudio(char * playChunk, int size) {
int send;
- if(audio_device==NULL) return 0;
+ if(audio_device==NULL) {
+ ERROR("trying to play w/ the audio device being open!\n");
+ return -1;
+ }
while(size>0) {
send = audio_write_size>size?size:audio_write_size;
- if(!ao_play(audio_device,playChunk,send)) {
+ if(ao_play(audio_device,playChunk,send)==0) {
audioError();
ERROR("closing audio device due to write error\n");
finishAudio();
- return;
+ return -1;
}
playChunk+=send;
size-=send;
}
+
+ return 0;
}
void finishAudio() {
diff --git a/src/audio.h b/src/audio.h
index 60cee26f3..07c842dc1 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -41,7 +41,7 @@ void finishAudioDriver();
int initAudio(AudioFormat * audioFormat);
-void playAudio(char * playChunk,int size);
+int playAudio(char * playChunk,int size);
void finishAudio();
diff --git a/src/decode.c b/src/decode.c
index 637df6d66..bdd5cd379 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -337,7 +337,9 @@ void decode() {
}
else doCrossFade = -1;
}
- if(pause) playAudio(silence,CHUNK_SIZE);
+ if(pause) {
+ if(playAudio(silence,CHUNK_SIZE)<0) quit = 1;
+ }
else if((cb->begin!=cb->end || cb->wrap) &&
cb->begin!=cb->next)
{
@@ -399,8 +401,11 @@ void decode() {
cb->chunkSize[cb->begin],
af,
pc->softwareVolume);
- playAudio(cb->chunks+cb->begin*CHUNK_SIZE,
- cb->chunkSize[cb->begin]);
+ if(playAudio(cb->chunks+cb->begin*CHUNK_SIZE,
+ cb->chunkSize[cb->begin])<0)
+ {
+ quit = 1;
+ }
cb->begin++;
if(cb->begin>=buffered_chunks) {
cb->begin = 0;