Exemple #1
0
/**************************************************************************
  Initialize base audio system. Note that this function is called very
  early at the client startup. So for example logging isn't available.
**************************************************************************/
void audio_init()
{
  audio_none_init();
  assert(num_plugins_used == 1);
  selected_plugin = 0;

#ifdef AUDIO_SDL
  audio_sdl_init();
#endif
}
Exemple #2
0
int audio_main(int argc, char *argv[])
{
	t_mdxmini mini;
	
    char pcmpath_mem[1024];
    char nlgpath_mem[1024];

    char *nlgfile = NULL;
    char *pcmpath = NULL;
    char *wavfile = NULL;

    int opt;
    
	int rate = 44100;
    int nosound = 0;
    int nlg_log = 0;
    int len = -1;
    
#ifdef _WIN32
    freopen("CON", "wt", stdout);
    freopen("CON", "wt", stderr);
#endif

    audio_sdl_init();
    signal(SIGINT, audio_sig_handle);

    printf("MDXPLAY on SDL Version %s\n", MDXMINI_VERSION);

	if (argc < 2)
	{
        usage();
		return 1;
	}
    
    while ((opt = getopt(argc, argv, "q:l:r:s:o:bpwhx")) != -1)
    {
        switch (opt)
        {
            case 'q': // pcm path
                pcmpath = optarg;
                break;
            case 'l': // length
                len = atoi(optarg);
                break;
            case 'b': // log without path(no arguments)
                nlg_log = NLG_SAMEPATH;
                nlgfile = NULL;
                nosound = 1;
                break;
            case 'r': // log with path
                nlg_log = NLG_NORMAL;
                nlgfile = optarg;
                break;
            case 'p': // no sound(no arguments)
                nosound = 1;
                break;
            case 's': // rate
                rate = atoi(optarg);
                break;
            case 'o': // output to wav file
                wavfile = optarg;
                break;
            case 'w': // verbose mode(no arguments)
                g_verbose = 1;
                break;
            case 'x': // view note mode(no arguments)
                g_viewnote = 1;
                break;
            case 'h':
            default:
                usage();
                return 1;
        }
    }
    
    if (rate < 8000)
        rate = 8000;
    
	if (audio_init(rate))
	{
		printf("Failed to initialize audio\n");
		
		return 0;
	}
	
	pcm.on = 1;
	
	mdx_set_rate(rate);


    if (!pcmpath)
    {
        pcmpath_mem[0] = 0;
        
        char *home = getenv("HOME");
        if (home)
        {
            pcmpath = pcmpath_mem;
            strcpy(pcmpath, home);
            strcat(pcmpath,_PATH_SEP);
            strcat(pcmpath, ".mdxplay");
            strcat(pcmpath,_PATH_SEP);
        }
    }
    
    // play files
    for(;optind < argc; optind++)
    {
        
        char *playfile = argv[optind];
        
        // make NLG log
        if (nlg_log)
        {
            // NLG filename is not given
            if (!nlgfile)
            {
                nlgpath_mem[0] = 0;
                nlgfile = nlgpath_mem;

                strcpy(nlgfile, playfile);
                
                char *p = strrchr(nlgfile, '.');
                
                if (p)
                    strcpy(p,".NLG");
                else
                    strcat(nlgfile,".NLG");
            }
            
            printf("CreateNLG:%s\n",nlgfile);
            nlgctx = CreateNLG(nlgfile);
        }
        
        // open mdx
        if (mdx_open(&mini, playfile, pcmpath))
        {
            printf("File open error: %s\n", playfile);
            CloseNLG(nlgctx);
            nlgctx = NULL;
            return 0;
        }
        
        if (nosound || wavfile)
            audio_loop_file(&mini, wavfile, rate, len);
        else
            audio_loop(&mini, rate, len);
        
        CloseNLG(nlgctx);
        nlgfile = NULL;
        nlgctx = NULL;

        // close mdx
        mdx_close(&mini);
    }
    
	audio_free();

	return 0;
}