当前位置: 首页>>代码示例>>C++>>正文


C++ Audio::setFormat方法代码示例

本文整理汇总了C++中Audio::setFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ Audio::setFormat方法的具体用法?C++ Audio::setFormat怎么用?C++ Audio::setFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Audio的用法示例。


在下文中一共展示了Audio::setFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cui_main

int cui_main(int argc, char *argv[])
{
    uint32_t tid = syscall_mthread_create(inputLoop);
    struct audio_data_format defaultFormat = {0, 2, 16, 4400};
    Audio* audio = new Audio(&defaultFormat, AUDIO_OUTPUT);
    if (-1 == audio->start())
    {
        _printf("Can not connect to AUDIO server!\n");
    }

    strings oggFiles;
    if (strcmp(argv[1], "-d") == 0 && argc > 2)
    {
        listOggfiles(argv[2], oggFiles);
    }
    else
    {
        for (int i = 1; i < argc; i++)
        {
            oggFiles.push_back(argv[i]);
        }
    }

    for (int i = 0; i < oggFiles.size(); i++)
    {
        FILE* fp = fopen(oggFiles[i].data(), "rb");
        if (NULL == fp)
        {
            fprintf(stderr, "File open error: %s.\n", oggFiles[i].data());
            delete audio;
            return -1;
        }
        OggVorbis_File vf;
        if (ov_open(fp, &vf, NULL, 0) < 0)
        {
            fprintf(stderr, "Skipped, %s does not appear to be an Ogg bitstream.\n", argv[i]);
            continue;
        }
        char** infoTexts = ov_comment(&vf, -1)->user_comments;
        vorbis_info* vi=ov_info(&vf, -1);
        while(*infoTexts)
        {
            fprintf(stderr, "%s\n", *infoTexts);
            ++infoTexts;
        }
//         fprintf(stderr, "\nBitstream is %d channel, %dHz\n", vi->channels, vi->rate);
//         fprintf(stderr, "\nDecoded length: %d samples\n",(long)ov_pcm_total(&vf, -1));
//         fprintf(stderr, "Encoded by: %s\n\n", ov_comment(&vf, -1)->vendor);

        struct audio_data_format format = {0, vi->channels, 16, vi->rate};
        audio->setFormat(&format);
        int current_section;
        char pcmout[4096];
        fprintf(stdout, "key q(quit) <=(prev) =>(next)\n");
        for (;;)
        {
            switch(command)
            {
            case COMMAND_FORWARD:
                command = COMMAND_NONE;
                goto replay;
            case COMMAND_BACKWARD:
                command = COMMAND_NONE;
                i -= 2;
                goto replay;
            case COMMAND_EXIT:
                i = oggFiles.size();
                goto replay;
            case COMMAND_VOLUME_UP:
            case COMMAND_VOLUME_DOWN:
                break;
            default:
                break;
            }
            long ret = ov_read(&vf, pcmout, sizeof(pcmout), &current_section);
            if (ret == 0)
            {
                break;
            }
            else if (ret < 0)
            {
                fprintf(stderr, "Warning data broken? %s\n", argv[i]);
            }
            else
            {
                audio->write(pcmout, ret);
            }
        }
    replay:
        fclose(fp);
    }
    audio->stop();
    delete audio;
// cleanup causes crash!
//    ov_clear(&vf);
}
开发者ID:mumurik,项目名称:mona,代码行数:96,代码来源:CUIPlayer.cpp


注:本文中的Audio::setFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。