MXC_A39_20240320/SW/components/modules/audio/audio_encoder.h

104 lines
3.0 KiB
C
Raw Normal View History

2024-03-07 16:46:43 +08:00
#ifndef _AUDIO_ENCODER_H
#define _AUDIO_ENCODER_H
#include <stdint.h>
#include "co_list.h"
#include "codec.h"
#include "resample.h"
#include "audio_common.h"
typedef struct {
struct co_list_hdr hdr;
uint16_t length;
uint8_t data[];
} audio_encoder_frame_t;
typedef struct {
audio_type_t type;
uint8_t channels;
uint32_t sample_rate;
void *encoder;
void *resampler;
uint8_t frame_count;
uint16_t frame_max_length;
struct co_list frame_list;
audio_encoder_frame_t *frame_tmp;
} audio_encoder_t;
/************************************************************************************
* @fn audio_encoder_init
*
* @brief Init audio encoder module.
*
* @param type: audio encoder type.
* channels: mono or stereo.
* sample_rate: input PCM sample rate.
* frame_max_length:
* param: decoder parameter.
*
* @return audio encoder handler, NULL will be returned when executation is failed.
*/
audio_encoder_t *audio_encoder_init(audio_type_t type, uint8_t channels, uint32_t sample_rate, uint16_t frame_max_length, void *param);
/************************************************************************************
* @fn audio_encoder_destroy
*
* @brief destroy created audio encoder module.
*
* @param encoder: encoder handler.
*/
void audio_encoder_destroy(audio_encoder_t *encoder);
/************************************************************************************
* @fn audio_encoder_encode
*
* @brief encode input PCM data.
*
* @param encoder: encoder handler.
* buffer: PCM buffer.
* length: size of input PCM data, unit is bytes.
* channels: mono or stereo of input PCM data
* sample_rate: sample rate of input PCM data.
*
* @return encoder result, @ref audio_ret_t.
*/
int audio_encoder_encode(audio_encoder_t *encoder, const uint8_t *buffer, uint32_t length, uint8_t channels, uint32_t sample_rate);
/************************************************************************************
* @fn audio_encoder_get_frame_count
*
* @brief Get the number of frames are stored in encoder module.
*
* @param encoder: encoder handler.
*
* @return the number of frames are stored in encoder module.
*/
int audio_encoder_get_frame_count(audio_encoder_t *encoder);
/************************************************************************************
* @fn audio_encoder_frame_pop
*
* @brief Get the head of frames stored in encoder module.
*
* @param encoder: encoder handler.
*
* @return the head of frames stored in encoder module.
*/
audio_encoder_frame_t *audio_encoder_frame_pop(audio_encoder_t *encoder);
/************************************************************************************
* @fn audio_encoder_frame_release
*
* @brief Release encoded frame.
*
* @param frame: frame to be released.
*/
void audio_encoder_frame_release(audio_encoder_frame_t *frame);
#endif //_AUDIO_ENCODER_H