|
| 1 | +/* |
| 2 | + * ESPRESSIF MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2025 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> |
| 5 | + * |
| 6 | + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, |
| 7 | + * it is free of charge, to any person obtaining a copy of this software and associated |
| 8 | + * documentation files (the "Software"), to deal in the Software without restriction, including |
| 9 | + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished |
| 11 | + * to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all copies or |
| 14 | + * substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 18 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 19 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 20 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +#pragma once |
| 26 | + |
| 27 | +#include "esp_audio_dec.h" |
| 28 | + |
| 29 | +#ifdef __cplusplus |
| 30 | +extern "C" { |
| 31 | +#endif |
| 32 | + |
| 33 | +/** |
| 34 | + * @brief Configuration for PCM decoder |
| 35 | + * |
| 36 | + */ |
| 37 | +typedef struct { |
| 38 | + int32_t sample_rate; /*!< The sample rate of audio */ |
| 39 | + uint8_t channel; /*!< The channel num of audio */ |
| 40 | + uint8_t bits_per_sample; /*!< The bits per sample of audio */ |
| 41 | +} esp_pcm_dec_cfg_t; |
| 42 | + |
| 43 | +/** |
| 44 | + * @brief Default decoder operations for PCM |
| 45 | + */ |
| 46 | +#define ESP_PCM_DEC_DEFAULT_OPS() { \ |
| 47 | + .open = esp_pcm_dec_open, \ |
| 48 | + .decode = esp_pcm_dec_decode, \ |
| 49 | + .close = esp_pcm_dec_close, \ |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * @brief Register PCM decoder library |
| 54 | + * |
| 55 | + * @note If user want to use decoder through decoder common API, need register it firstly. |
| 56 | + * Register can use either of following methods: |
| 57 | + * 1: Manually call `esp_pcm_dec_register`. |
| 58 | + * 2: Call `esp_audio_dec_register_default` and use menuconfig to enable it. |
| 59 | + * When user want to use PCM decoder only and not manage it by common part, no need to call this API, |
| 60 | + * And call `esp_pcm_dec_open`, `esp_pcm_dec_decode`, `esp_pcm_dec_close` instead. |
| 61 | + * |
| 62 | + * @return |
| 63 | + * - ESP_AUDIO_ERR_OK On success |
| 64 | + * - ESP_AUDIO_ERR_MEM_LACK Fail to allocate memory |
| 65 | + */ |
| 66 | +esp_audio_err_t esp_pcm_dec_register(void); |
| 67 | + |
| 68 | +/** |
| 69 | + * @brief Open PCM decoder |
| 70 | + * |
| 71 | + * @param[in] cfg Pointer to `esp_pcm_dec_cfg_t` |
| 72 | + * @param[in] cfg_sz Set to sizeof(esp_pcm_dec_cfg_t) |
| 73 | + * @param[out] dec_handle The PCM decoder handle |
| 74 | + * |
| 75 | + * @return |
| 76 | + * - ESP_AUDIO_ERR_OK On success |
| 77 | + * - ESP_AUDIO_ERR_MEM_LACK Fail to allocate memory |
| 78 | + * - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter |
| 79 | + */ |
| 80 | +esp_audio_err_t esp_pcm_dec_open(void *cfg, uint32_t cfg_sz, void **dec_handle); |
| 81 | + |
| 82 | +/** |
| 83 | + * @brief Decode raw data for PCM |
| 84 | + * |
| 85 | + * @param[in] dec_handle Decoder handle |
| 86 | + * @param[in,out] raw Raw data to be decoded |
| 87 | + * @param[in,out] frame Decoded PCM frame data |
| 88 | + * @param[out] dec_info Information of decoder |
| 89 | + * |
| 90 | + * @return |
| 91 | + * - ESP_AUDIO_ERR_OK On success |
| 92 | + * - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter |
| 93 | + * - ESP_AUDIO_ERR_BUFF_NOT_ENOUGH No enough frame buffer to hold output PCM frame data |
| 94 | + */ |
| 95 | +esp_audio_err_t esp_pcm_dec_decode(void *dec_handle, esp_audio_dec_in_raw_t *raw, esp_audio_dec_out_frame_t *frame, |
| 96 | + esp_audio_dec_info_t *dec_info); |
| 97 | + |
| 98 | +/** |
| 99 | + * @brief Close decoder for PCM |
| 100 | + * |
| 101 | + * @param[in] dec_handle Decoder handle |
| 102 | + * |
| 103 | + * @return |
| 104 | + * - ESP_AUDIO_ERR_OK On success |
| 105 | + */ |
| 106 | +esp_audio_err_t esp_pcm_dec_close(void *dec_handle); |
| 107 | + |
| 108 | +#ifdef __cplusplus |
| 109 | +} |
| 110 | +#endif |
0 commit comments