1434 views|3 replies

2

Posts

1

Resources
The OP
 

[RVB2601 Creative Application Development] Audio Playback [Copy link]

 

Add all built-in audio files to the demo, and modify the cli prompt information to conduct experiments:

if (argc == 3 && strcmp(argv[1], "play") == 0) {
        char url[128];

        if (strcmp(argv[2], "welcom") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&_welcome_mp3, _welcome_mp3_len);
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "raw") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u&avformat=rawaudio&avcodec=pcm_s8&channel=1&rate=8000", (uint32_t)&_example_little_raw, _example_little_raw_len);
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "hello") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_hello, sizeof(local_audio_hello));
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "net_fail") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_fail, sizeof(local_audio_net_fail));
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "net_succ") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_succ, sizeof(local_audio_net_succ));
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "ok") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_ok, sizeof(local_audio_ok));
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "sorry2") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_sorry2, sizeof(local_audio_sorry2));
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "sorry") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_sorry, sizeof(local_audio_sorry));
            player_play(get_player_demo(), url, 0);
        } else if (strcmp(argv[2], "starting") == 0) {
            snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_starting, sizeof(local_audio_starting));
            player_play(get_player_demo(), url, 0);
        } else {
            player_play(get_player_demo(), argv[2], 0);
        }
    } else if (argc == 2 && strcmp(argv[1], "stop") == 0) {
        player_stop(get_player_demo());
    } else if (argc == 2 && strcmp(argv[1], "pause") == 0) {
        player_pause(get_player_demo());
    } else if (argc == 2 && strcmp(argv[1], "resume") == 0) {
        player_resume(get_player_demo());
    } else {
        printf("\tplayer play welcom/raw/hello/net_fail/net_succ/ok/sorry2/sorry/starting\n");
        printf("\tplayer pause\n");
        printf("\tplayer resume\n");
        printf("\tplayer stop\n");
        printf("\tplayer help");
    }

Play test log:

The audio playback interface encapsulated by the system is very simple and easy to use. After initializing the relevant parameters, you can directly call the API interface to play the content. Then I started to test the web player and test how to get the audio stream through the network for playback. This involves connecting to the Internet, but you don’t need to worry about it for now. Just modify the WiFi parameters in the init.c code and use your own SSID name and password:

static void network_init()
{
    w800_wifi_param_t w800_param;
    /* init wifi driver and network */
    w800_param.reset_pin      = PA21;
    w800_param.baud           = 1*1000000;
    w800_param.cs_pin         = PA15;
    w800_param.wakeup_pin     = PA25;
    w800_param.int_pin        = PA22;
    w800_param.channel_id     = 0;
    w800_param.buffer_size    = 4*1024;

    wifi_w800_register(NULL, &w800_param);
    app_netmgr_hdl = netmgr_dev_wifi_init();

    if (app_netmgr_hdl) {
        utask_t *task = utask_new("netmgr", 2 * 1024, QUEUE_MSG_COUNT, AOS_DEFAULT_APP_PRI);
        netmgr_service_init(task);
        netmgr_config_wifi(app_netmgr_hdl, "test", strlen("test"), "123456789", strlen("123456789"));
        netmgr_start(app_netmgr_hdl);
    }
}

Now that we have the actual networking action, of course we need to use the audio playback we just got familiar with, and play the results of networking success and failure through audio. In app_main.c, add the corresponding audio playback code to the networking callback event monitoring function:

static void network_event(uint32_t event_id, const void *param, void *context)
{
	char url[128] = {0};
    switch(event_id) {
    case EVENT_NETMGR_GOT_IP:
        LOGD(TAG, "net got ip");
		player_stop(get_player_demo());
		snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_succ, sizeof(local_audio_net_succ));
		player_play(get_player_demo(), url, 0);
        break;
    case EVENT_NETMGR_NET_DISCON:
        LOGD(TAG, "net disconnect");
		player_stop(get_player_demo());
		snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&local_audio_net_fail, sizeof(local_audio_net_fail));
		player_play(get_player_demo(), url, 0);
        break;
    }

    /*do exception process */
    app_exception_event(event_id);
}

Note: A welcome audio will be played at startup. If the network connection is successful or failed and relevant audio needs to be played, if it is still playing, you need to stop the previous playback first and call player_stop(get_player_demo()).

The log shows that the IP address has been obtained: 192.168.199.193. The startup video is as follows:

https://en.eeworld.com/bbs/forum.php?mod=attachment&aid=NTk5MTgzfDI2Y2M3NzUwODY0NGI3NDA2YWRkYWVmYTZlYTcwYTVlfDE3MzIyMTM1MTY%3D&request=yes&_f=.mp4

In the webplayer demo, I also added volume control code

if (argc == 3 && strcmp(argv[1], "vol") == 0) {
	g_volume = atoi(argv[2]);
	printf("set player volume %d\n", g_volume);
	player_set_vol(get_player_demo(), g_volume);
}

Test playing web audio, play Jay Chou's songs in the LAN HTTP server, test the actions of play, pause, continue, increase, decrease, stop, etc.:

https://download.eeworld.com.cn/detail/UwenS/623253

The above is the current record~

Latest reply

Lots of debugging information.   Details Published on 2022-4-11 17:08
 
 

6587

Posts

0

Resources
2
 

The introduction is quite detailed. In fact, the test obtains the audio stream through the network for playback. I want to know how to configure and set it up when it comes to networking.

 
 
 

5217

Posts

239

Resources
3
 

Just record an effect demonstration

Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

7452

Posts

2

Resources
4
 

Lots of debugging information.

Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list