基于libmad 的简单MP3流媒体播放器的实现

豆豆网   技术应用频道   2007年03月10日  【字号: 收藏本文

本文详细介绍基于libmad 的简单MP3流媒体播放器的实现

  下面就本文使用的 API 的功能做简单介绍。

  在本文中用到的 API 包括:

void mad_stream_init(struct mad_stream *)
void mad_synth_init(struct mad_synth *);
void mad_frame_init(struct mad_frame *);

  以上3个 API 初始化解码需要的数据结构。

void mad_stream_buffer(struct mad_stream *, unsigned char const *, unsigned long);

  此函数把原始的未解码的 MPEG 数据和 mad_stream 数据结构关联,以便使用 mad_frame_decode( ) 来解码 MPEG 帧数据。

int mad_frame_decode(struct mad_frame *, struct mad_stream *);

  把 mad_stream 中的 MPEG 帧数据解码。

void mad_synth_frame(struct mad_synth *, struct mad_frame const *);

  把解码后的音频数据合成 PCM 采样。

void mad_stream_finish(struct mad_stream *);
void mad_frame_finish(struct mad_frame *);
mad_synth_finish(struct mad_synth);

  以上 3 个 API 在解码完毕后使用,释放 libmad 占用的资源等。

  3.PCM 音频设备的操作

  对音频设备的操作主要是初始化音频设备以及往音频设备发送 PCM(Pulse Code Modulation)数据。为了方便,本文使用 ALSA(Advanced Linux Sound Architecture)提供的库和驱动。在编译和运行本文中的 MP3 流媒体播放器的时候,必须先安装 ALSA 相关的文件。

  本文用到的主要对 PCM 设备操作的函数分为 PCM 设备初始化的函数以及 PCM 接口的一些操作函数。

  PCM 硬件设备参数设置和初始化的函数有:

int snd_pcm_hw_params_malloc (snd_pcm_hw_params_t **ptr)
int snd_pcm_hw_params_any (snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
void snd_pcm_hw_params_free (snd_pcm_hw_params_t *obj)
int snd_pcm_hw_params_set_access ( snd_pcm_t *pcm,
                  snd_pcm_hw_params_t *params,
                  snd_pcm_access_t _access)
int snd_pcm_hw_params_set_format ( snd_pcm_t *pcm,
                  snd_pcm_hw_params_t *params,
                  snd_pcm_format_t val)
int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm,
                  snd_pcm_hw_params_t *params,
                  unsigned int val)
int snd_pcm_hw_params_set_rate_near(snd_pcm_t *pcm,
                  snd_pcm_hw_params_t *params,
                  unsigned int *val, int *dir)

责编:豆豆技术应用

正在加载评论...