src/audio/alsa/SDL_alsa_audio.c
branchSDL-1.2
changeset 4329 9716da353104
parent 4321 c9a1de1eda57
child 4331 a24454ed4ac4
equal deleted inserted replaced
4328:4abf24b03b1d 4329:9716da353104
   303 
   303 
   304 
   304 
   305 static void ALSA_PlayAudio(_THIS)
   305 static void ALSA_PlayAudio(_THIS)
   306 {
   306 {
   307 	int status;
   307 	int status;
   308 	snd_pcm_uframes_t frames_left;
   308 	snd_pcm_uframes_t samps_left;
   309 	const Uint8 *sample_buf = (const Uint8 *) mixbuf;
   309 	const Uint8 *sample_buf = (const Uint8 *) mixbuf;
   310 	const int frame_size = ( ((int) this->spec.channels) *
   310 	const int sample_size = ((int) (this->spec.format & 0xFF)) / 8;
   311 	                         (((int) (this->spec.format & 0xFF)) / 8) );
       
   312 
   311 
   313 	swizzle_alsa_channels(this);
   312 	swizzle_alsa_channels(this);
   314 
   313 
   315 	frames_left = ((snd_pcm_uframes_t) this->spec.samples) / this->spec.channels;
   314 	samps_left = ((snd_pcm_uframes_t) this->spec.samples);
   316 
   315 
   317 	while ( frames_left > 0 ) {
   316 	while ( samps_left > 0 ) {
   318 		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
   317 		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, samps_left);
   319 		if ( status < 0 ) {
   318 		if ( status < 0 ) {
   320 			if ( status == -EAGAIN ) {
   319 			if ( status == -EAGAIN ) {
   321 				SDL_Delay(1);
   320 				SDL_Delay(1);
   322 				continue;
   321 				continue;
   323 			}
   322 			}
   335 				this->enabled = 0;
   334 				this->enabled = 0;
   336 				return;
   335 				return;
   337 			}
   336 			}
   338 			continue;
   337 			continue;
   339 		}
   338 		}
   340 		sample_buf += status * frame_size;
   339 		sample_buf += status * sample_size;
   341 		frames_left -= status;
   340 		samps_left -= status;
   342 	}
   341 	}
   343 }
   342 }
   344 
   343 
   345 static Uint8 *ALSA_GetAudioBuf(_THIS)
   344 static Uint8 *ALSA_GetAudioBuf(_THIS)
   346 {
   345 {