G 711 aオーディオ再生テスト
3299 ワード
demo:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "gmlib.h"
#include "GM8136s_hal_gpio_voice_player.h"
void *audio_groupfd2;
void *file_object;
void *render_object;
int audio_fd2;
int hal_audio_dec_init(void)
{
int i = 0;
DECLARE_ATTR(file_attr, gm_file_attr_t);
DECLARE_ATTR(audio_render_attr, gm_audio_render_attr_t);
audio_groupfd2 = gm_new_groupfd();
//g_av_info.audio_info[1].audio_buf_len = AUDIO_BITSTREAM_LEN;
// g_av_info.audio_info[1].audio_buf = malloc(g_av_info.audio_info[1].audio_buf_len);
// memset(g_av_info.audio_info[i].audio_buf, 0, AUDIO_BITSTREAM_LEN);
file_attr.sample_rate = 16000;
file_attr.sample_size = 16;
file_attr.channel_type = GM_MONO;//
file_object = gm_new_obj(GM_FILE_OBJECT);
render_object= gm_new_obj(GM_AUDIO_RENDER_OBJECT);
gm_set_attr(file_object, &file_attr);
// block_size: PCM(don't care) AAC(1024) ADPCM(256) G711(320)
audio_render_attr.vch = 0;
audio_render_attr.encode_type = GM_G711_ALAW;
audio_render_attr.block_size = 320;
gm_set_attr(render_object, &audio_render_attr);
audio_fd2 = gm_bind(audio_groupfd2, file_object, render_object);
return 0;
}
int hal_audio_dec_uninit(void)
{
gm_unbind(audio_fd2);
gm_apply(audio_groupfd2);
gm_delete_obj(file_object);
gm_delete_obj(render_object);
gm_delete_groupfd(audio_groupfd2);
}
int hal_audio_dec_start(void)
{
int ret = -1;
ret = gm_apply(audio_groupfd2);
if(ret < 0 )
{
printf("video_playback_start failed!!!
");
return -1;
}
return 0;
}
int hal_audio_playback(int audio_type,const char *audio_data,int date_len)
{
int ret;
char dec_buf[1024] = {0};
gm_dec_multi_bitstream_t multi_bs[1];
multi_bs[0].bindfd = audio_fd2;
multi_bs[0].bs_buf = audio_data;
multi_bs[0].bs_buf_len = date_len;
if ((ret = gm_send_multi_bitstreams(multi_bs, 1, 500)) < 0)
{
printf("
", ret);
return -1;
}
//printf("audio_playback .....................> end
");
return 0;
}
int voice_player(char *filename)
{
FILE* fp;
fp = fopen(filename,"rb");
if(fp == 0){
return -1;
}
char AudioBuff[1000];
int ret;
while(1)
{
ret = fread(AudioBuff,1,320,fp);
if (ret <= 0)
{
break;
}
hal_audio_playback(0,AudioBuff,ret);
usleep(1000/12);
}
return 0;
}
int main(int argc,char* argv[])
{
if(argc != 2)
{
printf("useage : voice_player xxx.g711a");
return 0;
}
int ret = 0;
ret = gm_init(); //gmlib initial
if(ret == 0 )
{
printf("gm_init sucess
");
}else
{
printf("gm_init error ret = %d
",ret);
}
hal_gm8136s_gpio_pin_init();
hal_gm8136s_speaker_ctrl(1);
hal_audio_dec_init();
hal_audio_dec_start();
voice_player(argv[1]);
usleep(500*1000);
hal_audio_dec_uninit();
hal_gm8136s_speaker_ctrl(0);
printf("voice_player_sucess!!
");
return 0;
}