dm: sound: Use the correct number of channels for sound
At present the 'beep' sound generates a waveform for only one channel even
if two are being used. This means that the beep is twice the frequency it
should be. Correct this by making it a parameter.
The fix in a previous commit was correct for sandbox but not for other
boards.
Fixes: 03f11e87a8 ("sound: Correct data output in sound_create_square_wave()")
Signed-off-by: Simon Glass <sjg@chromium.org>
			
			
This commit is contained in:
		
							parent
							
								
									e221cdcf44
								
							
						
					
					
						commit
						f987177db9
					
				|  | @ -53,7 +53,7 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size, | 	sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size, | ||||||
| 				 frequency_hz); | 				 frequency_hz, i2s_uc_priv->channels); | ||||||
| 
 | 
 | ||||||
| 	while (msecs >= 1000) { | 	while (msecs >= 1000) { | ||||||
| 		ret = sound_play(dev, data, data_size); | 		ret = sound_play(dev, data, data_size); | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ | ||||||
| #include <sound.h> | #include <sound.h> | ||||||
| 
 | 
 | ||||||
| void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | ||||||
| 			      uint freq) | 			      uint freq, uint channels) | ||||||
| { | { | ||||||
| 	const unsigned short amplitude = 16000; /* between 1 and 32767 */ | 	const unsigned short amplitude = 16000; /* between 1 and 32767 */ | ||||||
| 	const int period = freq ? sample_rate / freq : 0; | 	const int period = freq ? sample_rate / freq : 0; | ||||||
|  | @ -21,14 +21,17 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | ||||||
| 		size--; | 		size--; | ||||||
| 
 | 
 | ||||||
| 	while (size) { | 	while (size) { | ||||||
| 		int i; | 		int i, j; | ||||||
|  | 
 | ||||||
| 		for (i = 0; size && i < half; i++) { | 		for (i = 0; size && i < half; i++) { | ||||||
| 			size -= 2; | 			size -= 2; | ||||||
| 			*data++ = amplitude; | 			for (j = 0; j < channels; j++) | ||||||
|  | 				*data++ = amplitude; | ||||||
| 		} | 		} | ||||||
| 		for (i = 0; size && i < period - half; i++) { | 		for (i = 0; size && i < period - half; i++) { | ||||||
| 			size -= 2; | 			size -= 2; | ||||||
| 			*data++ = -amplitude; | 			for (j = 0; j < channels; j++) | ||||||
|  | 				*data++ = -amplitude; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -37,13 +37,14 @@ struct sound_uc_priv { | ||||||
| /**
 | /**
 | ||||||
|  * Generates square wave sound data for 1 second |  * Generates square wave sound data for 1 second | ||||||
|  * |  * | ||||||
|  * @param sample_rate   Sample rate in Hz |  * @sample_rate: Sample rate in Hz | ||||||
|  * @param data          data buffer pointer |  * @data: data buffer pointer | ||||||
|  * @param size          size of the buffer in bytes |  * @size: size of the buffer in bytes | ||||||
|  * @param freq          frequency of the wave |  * @freq: frequency of the wave | ||||||
|  |  * @channels: Number of channels to use | ||||||
|  */ |  */ | ||||||
| void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | ||||||
| 			      uint freq); | 			      uint freq, uint channels); | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * The sound uclass brings together a data transport (currently only I2C) and a |  * The sound uclass brings together a data transport (currently only I2C) and a | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue