Il y avait des problèmes dans la libraire...

Dependencies:   ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE

Fork of X_NUCLEO_CCA02M1 by ST

Revision:
20:9952bef19da1
Parent:
17:a758b376b018
--- a/BSP/PDM2PCMAudio.h	Thu May 04 10:39:39 2017 +0000
+++ b/BSP/PDM2PCMAudio.h	Fri May 05 11:34:10 2017 +0000
@@ -69,12 +69,11 @@
 
 /* Definitions ---------------------------------------------------------------*/
 
-#define DEMUX_FILTER_SIZE         128
-#define DEMUX_FILTER_MASK         0x55
-#define PDM2PCM_FILTER_SIZE       4
-#define PDM2PCM_NOGAIN_VOLUME     4
-#define PDM2PCM_MAX_VOLUME        64
-#define PDM2PCM_DECIMATION_FACTOR 64
+#define DEMUX_FILTER_SIZE      128
+#define DEMUX_FILTER_MASK     0x55
+#define PDM2PCM_FILTER_SIZE      4
+#define PDM2PCM_NOGAIN_VOLUME    4
+#define PDM2PCM_MAX_VOLUME      64
 
 
 /* Classes -------------------------------------------------------------------*/
@@ -100,6 +99,22 @@
 	    /* Enable CRC peripheral to unlock the PDM2PCMAudio library. */
 	    __CRC_CLK_ENABLE();
 
+	 	/* Setting configuration. */
+	    switch (_frequency)
+	    {
+	        case I2S_AUDIOFREQ_8K:
+	            _decimation_factor = 128;
+	            break;
+	
+	        case I2S_AUDIOFREQ_16K:
+	        case I2S_AUDIOFREQ_32K:
+	        case I2S_AUDIOFREQ_44K:
+	        case I2S_AUDIOFREQ_48K:
+	        default:
+	            _decimation_factor = 64;
+	            break;
+	    }
+
 	    /* Initializing PDM2PCMAudio Filter. */
 	    for (uint32_t i = 0; i < _channels; i++)
 	    {
@@ -109,6 +124,8 @@
 	        _PDM2PCM_filter[i].Fs = _frequency;
 	        _PDM2PCM_filter[i].Out_MicChannels = _channels;
 	        _PDM2PCM_filter[i].In_MicChannels = _channels;
+	        _PDM2PCM_filter[i].Decimation = _decimation_factor;
+	        _PDM2PCM_filter[i].MaxVolume = PDM2PCM_MAX_VOLUME;
 #ifdef USE_OPEN_PDM2PCM_LIBRARY
 	        Open_PDM_Filter_Init((TPDMFilter_InitStruct *) &_PDM2PCM_filter[i]);
 #else
@@ -118,14 +135,20 @@
     };
 
 	/**
-	* @brief  Converting audio data from PDM to PCM.
-	* @param  output_buffer     Pointer to output PCM buffer data.
-	* @param  input_buffer      Pointer to input PDM buffer data.
-	* @param  volume            Volume level (it must be in the range [0..64]).
-	* @param  decimation_factor Decimation factor (it must be either 64 or 128).
-	* @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
-	*/
-	status_t convert(int16_t *output_buffer, uint16_t *input_buffer, uint32_t volume, uint32_t decimation_factor);
+	 * @brief  Getting number of PCM samples from nummber of PDM samples.
+     * @param  PCM_samples Number of PCM samples.
+	 * @retval Number of equivalent PDM samples.
+	 */
+	uint32_t pcm2pdm_samples(uint32_t PCM_samples);
+
+	/**
+	 * @brief  Converting audio data from PDM to PCM.
+	 * @param  output_buffer     Pointer to output PCM buffer data.
+	 * @param  input_buffer      Pointer to input PDM buffer data.
+	 * @param  volume            Volume level (it must be in the range [0..PDM2PCM_MAX_VOLUME]).
+	 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+	 */
+	status_t convert(int16_t *output_buffer, uint16_t *input_buffer, uint32_t volume);
 
 	/**
 	 * @brief  Scrambling audio data.
@@ -150,6 +173,7 @@
 
 	uint32_t _frequency;
 	uint32_t _channels;
+	uint32_t _decimation_factor;
 #ifdef USE_OPEN_PDM2PCM_LIBRARY
 	TPDMFilter_InitStruct _PDM2PCM_filter[PDM2PCM_FILTER_SIZE];
 #else