mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	direct pcm plugins: fix channel number selection
The code to set the number of channels did not work when the requested channel count was not available and when the min/max channel counts were not identical. Replacing the entire selection code with snd_pcm_hw_params_set_channels_near() gives the same result in the cases where it previously worked, and works in all other cases.
This commit is contained in:
		
							parent
							
								
									0f99fe7830
								
							
						
					
					
						commit
						9819099e0e
					
				
					 1 changed files with 3 additions and 21 deletions
				
			
		| 
						 | 
					@ -899,29 +899,11 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		params->format = format;
 | 
							params->format = format;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ret = snd_pcm_hw_params_set_channels(spcm, hw_params, params->channels);
 | 
						ret = INTERNAL(snd_pcm_hw_params_set_channels_near)(spcm, hw_params, (unsigned int *)¶ms->channels);
 | 
				
			||||||
	if (ret < 0) {
 | 
					 | 
				
			||||||
		unsigned int min, max;
 | 
					 | 
				
			||||||
		ret = INTERNAL(snd_pcm_hw_params_get_channels_min)(hw_params, &min);
 | 
					 | 
				
			||||||
		if (ret < 0) {
 | 
					 | 
				
			||||||
			SNDERR("cannot obtain minimal count of channels");
 | 
					 | 
				
			||||||
			return ret;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		ret = INTERNAL(snd_pcm_hw_params_get_channels_min)(hw_params, &max);
 | 
					 | 
				
			||||||
		if (ret < 0) {
 | 
					 | 
				
			||||||
			SNDERR("cannot obtain maximal count of channels");
 | 
					 | 
				
			||||||
			return ret;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (min == max) {
 | 
					 | 
				
			||||||
			ret = snd_pcm_hw_params_set_channels(spcm, hw_params, min);
 | 
					 | 
				
			||||||
			if (ret >= 0)
 | 
					 | 
				
			||||||
				params->channels = min;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	if (ret < 0) {
 | 
						if (ret < 0) {
 | 
				
			||||||
		SNDERR("requested count of channels is not available");
 | 
							SNDERR("requested count of channels is not available");
 | 
				
			||||||
		return ret;
 | 
							return ret;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	ret = INTERNAL(snd_pcm_hw_params_set_rate_near)(spcm, hw_params, (unsigned int *)¶ms->rate, 0);
 | 
						ret = INTERNAL(snd_pcm_hw_params_set_rate_near)(spcm, hw_params, (unsigned int *)¶ms->rate, 0);
 | 
				
			||||||
	if (ret < 0) {
 | 
						if (ret < 0) {
 | 
				
			||||||
		SNDERR("requested rate is not available");
 | 
							SNDERR("requested rate is not available");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue