src/audio/alsa/SDL_alsa_audio.c
changeset 942 41a59de7f2ed
parent 939 c7c04f811994
child 1161 05d4b93b911e
equal deleted inserted replaced
941:5095c4a264aa 942:41a59de7f2ed
   161 	return 0;
   161 	return 0;
   162 }
   162 }
   163 
   163 
   164 #endif /* ALSA_DYNAMIC */
   164 #endif /* ALSA_DYNAMIC */
   165 
   165 
   166 static const char *get_audio_device()
   166 static const char *get_audio_device(int channels)
   167 {
   167 {
   168 	const char *device;
   168 	const char *device;
   169 	
   169 	
   170 	device = getenv("AUDIODEV");	/* Is there a standard variable name? */
   170 	device = getenv("AUDIODEV");	/* Is there a standard variable name? */
   171 	if ( device == NULL ) {
   171 	if ( device == NULL ) {
   172 		device = DEFAULT_DEVICE;
   172 		if (channels == 6) device = "surround51";
       
   173 		else if (channels == 4) device = "surround40";
       
   174 		else device = DEFAULT_DEVICE;
   173 	}
   175 	}
   174 	return device;
   176 	return device;
   175 }
   177 }
   176 
   178 
   177 /* Audio driver bootstrap functions */
   179 /* Audio driver bootstrap functions */
   184 
   186 
   185 	available = 0;
   187 	available = 0;
   186 	if (LoadALSALibrary() < 0) {
   188 	if (LoadALSALibrary() < 0) {
   187 		return available;
   189 		return available;
   188 	}
   190 	}
   189 	status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   191 	status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(2), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   190 	if ( status >= 0 ) {
   192 	if ( status >= 0 ) {
   191 		available = 1;
   193 		available = 1;
   192         	SDL_NAME(snd_pcm_close)(handle);
   194         	SDL_NAME(snd_pcm_close)(handle);
   193 	}
   195 	}
   194 	UnloadALSALibrary();
   196 	UnloadALSALibrary();
   317 	snd_pcm_format_t     format;
   319 	snd_pcm_format_t     format;
   318 	snd_pcm_uframes_t    frames;
   320 	snd_pcm_uframes_t    frames;
   319 	Uint16               test_format;
   321 	Uint16               test_format;
   320 
   322 
   321 	/* Open the audio device */
   323 	/* Open the audio device */
   322 	status = SDL_NAME(snd_pcm_open)(&pcm_handle, get_audio_device(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   324 	/* Name of device should depend on # channels in spec */
       
   325 	status = SDL_NAME(snd_pcm_open)(&pcm_handle, get_audio_device(spec->channels), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
       
   326 
   323 	if ( status < 0 ) {
   327 	if ( status < 0 ) {
   324 		SDL_SetError("Couldn't open audio device: %s", SDL_NAME(snd_strerror)(status));
   328 		SDL_SetError("Couldn't open audio device: %s", SDL_NAME(snd_strerror)(status));
   325 		return(-1);
   329 		return(-1);
   326 	}
   330 	}
   327 
   331