audio cleanups
git-svn-id: https://svn.musicpd.org/mpd/trunk@109 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
5622edbc98
commit
821355361c
22
src/audio.c
22
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() {
|
||||
|
|
|
@ -41,7 +41,7 @@ void finishAudioDriver();
|
|||
|
||||
int initAudio(AudioFormat * audioFormat);
|
||||
|
||||
void playAudio(char * playChunk,int size);
|
||||
int playAudio(char * playChunk,int size);
|
||||
|
||||
void finishAudio();
|
||||
|
||||
|
|
11
src/decode.c
11
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;
|
||||
|
|
Loading…
Reference in New Issue