Exemplo n.º 1
0
static int cmd_play_file(struct re_printf *pf, void *arg)
{
	static struct play *g_play;
	struct cmd_arg *carg = arg;
	const char *filename = carg->prm;
	int err = 0;

	/* Stop the current tone, if any */
	g_play = mem_deref(g_play);

	if (str_isset(filename))
	{
		err = re_hprintf(pf, "playing audio file \"%s\" ..\n",
				 filename);
		if (err)
			return err;

		err = play_file(&g_play, baresip_player(), filename, 0);
		if (err)
		{
			warning("debug_cmd: play_file(%s) failed (%m)\n",
					filename, err);
			return err;
		}
	}

	return err;
}
Exemplo n.º 2
0
static void playing_test(void) {
	char *filename = ms_strdup_printf("%s/sounds/hello_opus_h264.mkv", liblinphone_tester_file_prefix);
	const char *audio_mime = "opus";
	const char *video_mime = "h264";
	play_file(filename, !linphone_local_player_matroska_supported(), audio_mime, video_mime);
	ms_free(filename);
}
Exemplo n.º 3
0
int play_raw(const char *fg, int rate, int ch, const char *device, const char *fn)
{
    int fd;
    unsigned flag = 0;

    if(!fn) {
        fd = fileno(stdin);
        piped = 1;
    } else {
        fd = open(fn, O_RDONLY);
        if (fd < 0) {
            fprintf(stderr, "Aplay:aplay: cannot open '%s'\n", fn);
            return fd;
        }
    }

    if (!strncmp(fg, "M", sizeof("M")))
        flag = PCM_MMAP;
    else if (!strncmp(fg, "N", sizeof("N")))
        flag = PCM_NMMAP;

    fprintf(stderr, "aplay: Playing '%s': format %s ch = %d\n",
		    fn, get_format_desc(format), ch );
    return play_file(rate, ch, fd, flag, device, 0);
}
Exemplo n.º 4
0
int play_wav(const char *fg, int rate, int ch, const char *device, const char *fn)
{
    struct wav_header hdr;
    int fd;
    unsigned flag = 0;

    if (pcm_flag) {
        if(!fn) {
            fd = fileno(stdin);
            piped = 1;
        } else {
            fd = open(fn, O_RDONLY);
            if (fd < 0) {
                fprintf(stderr, "Aplay:aplay: cannot open '%s'\n", fn);
                return fd;
            }
        }
        if (compressed) {
            hdr.sample_rate = rate;
            hdr.num_channels = ch;
            hdr.data_sz = 0;
            goto ignore_header;
        }

        if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
            fprintf(stderr, "Aplay:aplay: cannot read header\n");
            return -errno;
        }

        if ((hdr.riff_id != ID_RIFF) ||
            (hdr.riff_fmt != ID_WAVE) ||
            (hdr.fmt_id != ID_FMT)) {
            fprintf(stderr, "Aplay:aplay: '%s' is not a riff/wave file\n", fn);
            return -EINVAL;
        }
        if ((hdr.audio_format != FORMAT_PCM) ||
            (hdr.fmt_sz != 16)) {
            fprintf(stderr, "Aplay:aplay: '%s' is not pcm format\n", fn);
            return -EINVAL;
        }
        if (hdr.bits_per_sample != 16) {
            fprintf(stderr, "Aplay:aplay: '%s' is not 16bit per sample\n", fn);
            return -EINVAL;
        }
    } else {
        fd = -EBADFD;
        hdr.sample_rate = rate;
        hdr.num_channels = ch;
        hdr.data_sz = 0;
    }

ignore_header:
    if (!strncmp(fg, "M", sizeof("M")))
        flag = PCM_MMAP;
    else if (!strncmp(fg, "N", sizeof("N")))
        flag = PCM_NMMAP;
    fprintf(stderr, "aplay: Playing '%s':%s\n", fn, get_format_desc(format) );

    return play_file(hdr.sample_rate, hdr.num_channels, fd, flag, device, hdr.data_sz);
}
int main(int argc, char *argv[])
{
    if (argc < 2) {
	usage(argv[0]);
	return 1;
    }

    pj_init();

    init();

    if (stricmp(argv[1], "record")==0) {
	record_file("FILE.PCM");
    } else if (stricmp(argv[1], "play")==0) {
	play_file("FILE.PCM");
    } else if (stricmp(argv[1], "send")==0) {
	create_ses_by_remote_sdp(4002, listener_sdp);
    } else if (stricmp(argv[1], "recv")==0) {
	create_ses_by_remote_sdp(4000, talker_sdp);
    } else {
	usage(argv[0]);
    }
    deinit();
    return 0;
}
Exemplo n.º 6
0
void pick() {
   if (is_dir(cursor_pos)) {
      cd();
      cursor_pos = 0;
   } else {
      play_file();
      state = STATE_IDLE;
   }
}
Exemplo n.º 7
0
int play_wav(const char *fg, int rate, int ch, const char *device, const char *fn)
{
    struct wav_header hdr;
    int fd;
    unsigned flag = 0;

    if (pcm_flag) {
        if(!fn) {
            fd = fileno(stdin);
        } else {
            fd = open(fn, O_RDONLY);
            if (fd < 0) {
                fprintf(stderr, "Aplay:aplay: cannot open '%s'\n", fn);
                return fd;
            }
        }
        if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
            fprintf(stderr, "Aplay:aplay: cannot read header\n");
            return -errno;
        }
        if (debug)
            fprintf(stderr, "Aplay:aplay: %d ch, %d hz, %d bit, %s\n",
                hdr.num_channels, hdr.sample_rate, hdr.bits_per_sample,
                hdr.audio_format == FORMAT_PCM ? "PCM" : "unknown");

        if ((hdr.riff_id != ID_RIFF) ||
            (hdr.riff_fmt != ID_WAVE) ||
            (hdr.fmt_id != ID_FMT)) {
            fprintf(stderr, "Aplay:aplay: '%s' is not a riff/wave file\n", fn);
            return -EINVAL;
        }
        if ((hdr.audio_format != FORMAT_PCM) ||
            (hdr.fmt_sz != 16)) {
            fprintf(stderr, "Aplay:aplay: '%s' is not pcm format\n", fn);
            return -EINVAL;
        }
        if (hdr.bits_per_sample != 16) {
            fprintf(stderr, "Aplay:aplay: '%s' is not 16bit per sample\n", fn);
            return -EINVAL;
        }
    } else {
        fd = -EBADFD;
        hdr.sample_rate = rate;
        hdr.num_channels = ch;
    }
    if (!strcmp(fg, "M")) {
        fprintf(stderr, "Aplay:aplay: '%s' is playing in MMAP as input is %s\n", fn, fg);
        flag = PCM_MMAP;
    } else if (!strcmp(fg, "N")) {
        fprintf(stderr, "Aplay:aplay: '%s' is playing in non-MMAP as input is %s\n", fn, fg);
        flag = PCM_NMMAP;
    }
    return play_file(hdr.sample_rate, hdr.num_channels, fd, hdr.data_sz, flag, device);
}
Exemplo n.º 8
0
/**
 * Main function of a simple player
 */
int player_main(int argc, char ** argv)
{
    // Args
    if (argc != 2) {
        fprintf(stderr, "Wrong number of args.\n");
        return 1;
    }

    // File name
    char const * file_name = argv[1];
    printf("File name: '%s'.\n", file_name);
    return play_file(file_name);
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
	int serial_fd = -1;
	struct termios old_termio;

	/* check args */
	if (argc <= 1) {
		usage();
		goto err;
	};

	/* initalize */
	if ((serial_fd = serial_init(&old_termio)) < 0) {
		logging(FATAL, "serial_init() failed\n");
		goto err;
	}

	if (spfm_reset(serial_fd) == false) {
		logging(FATAL, "spfm_reset() failed\n");
		goto err;
	}

	if (set_signal(SIGINT, sig_handler) < 0) {
		logging(FATAL, "set_signal() failed\n");
		goto err;
	}

	/* play file */
	if (play_file(serial_fd, argv[1]) == false) {
		logging(WARN, "play_file() failed\n");
		goto err;
	}

	/* end process */
	spfm_reset(serial_fd);
	serial_die(serial_fd, &old_termio);
	return EXIT_SUCCESS;

err:
	if (serial_fd != -1) {
		spfm_reset(serial_fd);
		serial_die(serial_fd, &old_termio);
	}
	return EXIT_FAILURE;
}
Exemplo n.º 10
0
int mp3_play(struct audtest_config *config)
{
  struct stat stat_buf;
  int fd;

  fd = open(config->file_name, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "playmp3: cannot open '%s'\n", config->file_name);
    return -1;
  }

  (void) fstat(fd, &stat_buf);


  play_file(config, 44100, 2, fd, stat_buf.st_size);

  return 0;
}
Exemplo n.º 11
0
int wav_play(struct audtest_config *config)
{

	struct wav_header hdr;
	int fd;

	if (config == NULL) {
		return -1;
	}

	fd = open(config->file_name, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "playwav: cannot open '%s'\n", config->file_name);
		return -1;
	}
	if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
		fprintf(stderr, "playwav: cannot read header\n");
		return -1;
	}
	fprintf(stderr,"playwav: %d ch, %d hz, %d bit, %s\n",
		hdr.num_channels, hdr.sample_rate, hdr.bits_per_sample,
		hdr.audio_format == FORMAT_PCM ? "PCM" : "unknown");

	if ((hdr.riff_id != ID_RIFF) ||
			(hdr.riff_fmt != ID_WAVE) ||
			(hdr.fmt_id != ID_FMT)) {
		fprintf(stderr, "playwav: '%s' is not a riff/wave file\n", config->file_name);
		return -1;
	}
	if ((hdr.audio_format != FORMAT_PCM) /*||
			(hdr.fmt_sz != 16)*/) {
		fprintf(stderr, "playwav: '%s' is not pcm format\n", config->file_name);
		return -1;
	}
	if (hdr.bits_per_sample != 16) {
		fprintf(stderr, "playwav: '%s' is not 16bit per sample\n", config->file_name);
		return -1;
	}

	play_file(config, hdr.sample_rate, hdr.num_channels,
	fd, hdr.data_sz);

	return 0;
}
Exemplo n.º 12
0
void
pcspkr_play(const char *infilename, const char *outfilename)
{
	FILE           *infp, *outfp;

    infp = outfp = NULL;
	if ((infp = fopen(infilename, "r")) == NULL)
		err(2, "\"%s\"", infilename);
    if (outfilename) {
        if ((outfp = fopen(outfilename, "wb")) == NULL)
            err(2, "\"%s\"", outfilename);
    }   

	play_file(infp, outfp);

	fclose(infp);
    if (outfp)
        fclose(outfp);
}
Exemplo n.º 13
0
int wav_play(const char *fn)
{
	struct wav_header hdr;
    unsigned rate, channels;
	int fd;
	fd = open(fn, O_RDONLY);
	if (fd < 0) {
        fprintf(stderr, "playwav: cannot open '%s'\n", fn);
		return -1;
	}
	if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
        fprintf(stderr, "playwav: cannot read header\n");
		return -1;
	}
    fprintf(stderr,"playwav: %d ch, %d hz, %d bit, %s\n",
            hdr.num_channels, hdr.sample_rate, hdr.bits_per_sample,
            hdr.audio_format == FORMAT_PCM ? "PCM" : "unknown");
    
    if ((hdr.riff_id != ID_RIFF) ||
        (hdr.riff_fmt != ID_WAVE) ||
        (hdr.fmt_id != ID_FMT)) {
        fprintf(stderr, "playwav: '%s' is not a riff/wave file\n", fn);
        return -1;
    }
    if ((hdr.audio_format != FORMAT_PCM) ||
        (hdr.fmt_sz != 16)) {
        fprintf(stderr, "playwav: '%s' is not pcm format\n", fn);
        return -1;
    }
    if (hdr.bits_per_sample != 16) {
        fprintf(stderr, "playwav: '%s' is not 16bit per sample\n", fn);
        return -1;
    }

    play_file(hdr.sample_rate, hdr.num_channels,
              fd, hdr.data_sz);
    
    return 0;
}
Exemplo n.º 14
0
void handle_play_mode(FILINFO* pfile_info) {
  // reset to the root after a possible record operation
  change_dir("/");
  // refresh the file list to avoid blank entries bug
  if ((g_num_files = get_num_files(pfile_info)) == 0) {
    lcd_title_P(S_NO_FILES_FOUND);
    lcd_busy_spinner();
    return;
  }

  g_cur_file_index = 0;
  if (!get_file_at_index(pfile_info, g_cur_file_index)) {
    // shouldn't happen...
    lcd_title_P(S_NO_FILES_FOUND);
    lcd_busy_spinner();
    return;
  }

  lcd_title_P(S_SELECT_FILE);
  display_filename(pfile_info);
  
  while (1) {
    switch(get_cur_command()) {
      case COMMAND_SELECT:
        if (pfile_info->fattrib & AM_DIR) {
          if (change_dir(pfile_info->fname) == FR_OK) {
            g_num_files = get_num_files(pfile_info);
            g_cur_file_index = 0;
            get_file_at_index(pfile_info, g_cur_file_index);
            display_filename(pfile_info);
          } else {
            lcd_status_P(S_CHDIR_FAILED);
          }
        } else {
          display_filename(pfile_info);
          play_file(pfile_info);
          lcd_title_P(S_SELECT_FILE);
          // buffer is used so get the file again
          get_file_at_index(pfile_info, g_cur_file_index);
          display_filename(pfile_info);
        }
      break;
      case COMMAND_ABORT:
        if (g_fs.cdir != 0) {
          if (change_dir("..") == FR_OK) {
            g_num_files = get_num_files(pfile_info);
            g_cur_file_index = 0;
            get_file_at_index(pfile_info, g_cur_file_index);
            display_filename(pfile_info);
          } else {
            lcd_status_P(S_CHDIR_FAILED);
          }        
        } else {
          // back to main menu
          return;
        }
      break;
      case COMMAND_NEXT:
        if (++g_cur_file_index >= g_num_files) {
          g_cur_file_index = 0;
        }
        get_file_at_index(pfile_info, g_cur_file_index);
        display_filename(pfile_info);
      break;
      case COMMAND_PREVIOUS:
        if (--g_cur_file_index < 0) {
          g_cur_file_index = g_num_files - 1;
        }
        get_file_at_index(pfile_info, g_cur_file_index);
        display_filename(pfile_info);
      break;
    }
    filename_ticker(pfile_info, get_timer_tick());
  }
}
Exemplo n.º 15
0
int main()
{
    pj_caching_pool cp;
    pj_bool_t done = PJ_FALSE;
    pj_status_t status;

    /* Init pjlib */
    status = pj_init();
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);
    
    pj_log_set_decor(PJ_LOG_HAS_NEWLINE);

    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);

    status = pjmedia_aud_subsys_init(&cp.factory);
    if (status != PJ_SUCCESS) {
	app_perror("pjmedia_aud_subsys_init()", status);
	pj_caching_pool_destroy(&cp);
	pj_shutdown();
	return 1;
    }

    list_devices();

    while (!done) {
	char line[80];

	print_menu();

	if (fgets(line, sizeof(line), stdin)==NULL)
	    break;

	switch (line[0]) {
	case 'l':
	    list_devices();
	    break;

	case 'R':
	    pjmedia_aud_dev_refresh();
	    puts("Audio device list refreshed.");
	    break;

	case 'i':
	    {
		unsigned dev_index;
		if (sscanf(line+2, "%u", &dev_index) != 1) {
		    puts("error: device ID required");
		    break;
		}
		show_dev_info(dev_index);
	    }
	    break;

	case 't':
	    {
		pjmedia_dir dir;
		int rec_id, play_id;
		unsigned clock_rate, ptime, chnum;
		int cnt;

		cnt = sscanf(line+2, "%d %d %u %u %u", &rec_id, &play_id, 
			     &clock_rate, &ptime, &chnum);
		if (cnt < 4) {
		    puts("error: not enough parameters");
		    break;
		}
		if (clock_rate < 8000 || clock_rate > 128000) {
		    puts("error: invalid clock rate");
		    break;
		}
		if (ptime < 10 || ptime > 500) {
		    puts("error: invalid ptime");
		    break;
		}
		if (cnt==5) {
		    if (chnum < 1 || chnum > 4) {
			puts("error: invalid number of channels");
			break;
		    }
		} else {
		    chnum = 1;
		}

		if (rec_id >= 0 && rec_id < (int)dev_count) {
		    if (play_id >= 0 && play_id < (int)dev_count)
			dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
		    else
			dir = PJMEDIA_DIR_CAPTURE;
		} else if (play_id >= 0 && play_id < (int)dev_count) {
		    dir = PJMEDIA_DIR_PLAYBACK;
		} else {
		    puts("error: at least one valid device index required");
		    break;
		}

		test_device(dir, rec_id, play_id, clock_rate, ptime, chnum);
		
	    }
	    break;

	case 'r':
	    /* record */
	    {
		int index;
		char filename[80];
		int count;

		count = sscanf(line+2, "%d %s", &index, filename);
		if (count==1)
		    record(index, NULL);
		else if (count==2)
		    record(index, filename);
		else
		    puts("error: invalid command syntax");
	    }
	    break;

	case 'p':
	    /* playback */
	    {
		int index;
		char filename[80];
		int count;

		count = sscanf(line+2, "%d %s", &index, filename);
		if (count==1)
		    play_file(index, NULL);
		else if (count==2)
		    play_file(index, filename);
		else
		    puts("error: invalid command syntax");
	    }
	    break;

	case 'd':
	    /* latencies */
	    {
		int rec_lat, play_lat;

		if (sscanf(line+2, "%d %d", &rec_lat, &play_lat) == 2) {
		    capture_lat = (unsigned) 
			 (rec_lat>=0? rec_lat:PJMEDIA_SND_DEFAULT_REC_LATENCY);
		    playback_lat = (unsigned)
			 (play_lat >= 0? play_lat : PJMEDIA_SND_DEFAULT_PLAY_LATENCY);
		    printf("Recording latency=%ums, playback latency=%ums",
			   capture_lat, playback_lat);
		} else {
		    printf("Current latencies: record=%ums, playback=%ums",
			   capture_lat, playback_lat);
		}
		puts("");
	    }
	    break;

	case 'v':
	    if (pj_log_get_level() <= 3) {
		pj_log_set_level(5);
		puts("Logging set to detail");
	    } else {
		pj_log_set_level(3);
		puts("Logging set to quiet");
	    }
	    break;

	case 'q':
	    done = PJ_TRUE;
	    break;
	}
    }

    pj_caching_pool_destroy(&cp);
    pj_shutdown();
    return 0;
}
static void playing_twice_test(void) {
	play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, TRUE, 15000);
}
static void play_hello_opus_h264_mkv(void) {
	play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
}
static void play_hello_pcmu_mka(void) {
	play_file("./sounds/hello_pcmu.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
}
Exemplo n.º 19
0
int main(int argc, char **argv) {
    int status = 0;
    struct params par;
    int opt;

    signal(SIGHUP,  interrupt_handler);
    signal(SIGINT,  interrupt_handler);
    signal(SIGQUIT, interrupt_handler);

    ao_initialize();
    driver_id = ao_default_driver_id();
    memset(&current_sample_format, 0, sizeof(current_sample_format));

    if (argc == 1) {
        /* We were invoked with no arguments */
        usage(argv[0]);
        goto done;
    }

    again:

    {
        struct params default_par = DEFAULT_PARAMS;
        memcpy(&par, &default_par, sizeof(par));
    }

    while ((opt = getopt(argc, argv, "-D:F:L:M:S:b:d:f:o:@:hrv")) != -1) {
        switch (opt) {
            case '@':
                if (play_playlist(optarg, &par)) {
                    status = 1;
                    goto done;
                }
                break;
            case 'D':
                par.fade_delay = atof(optarg);
                break;
            case 'F':
                par.fade_time = atof(optarg);
                break;
            case 'L':
                par.loop_count = atoi(optarg);
                break;
            case 'M':
                par.min_time = atof(optarg);
                par.loop_count = -1;
                break;
            case 'S':
                par.stream_index = atoi(optarg);
                break;
            case 'b':
                if (!buffer)
                    buffer_size_kb = atoi(optarg);
                break;
            case 'd':
                driver_id = ao_driver_id(optarg);
                if (driver_id < 0) {
                    fprintf(stderr, "Invalid output driver \"%s\"\n", optarg);
                    status = 1;
                    goto done;
                }
                break;
            case 'f':
                out_filename = optarg;
                break;
            case 'h':
                usage(argv[0]);
                goto done;
            case 'o':
                add_driver_option(optarg);
                break;
            case 'r':
                repeat = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            default:
                goto done;
        }
    }
    argc -= optind;
    argv += optind;

    for (opt = 0; opt < argc; ++opt) {
        if (play_file(argv[opt], &par)) {
            status = 1;
            goto done;
        }
    }

    if (repeat) {
        optind = 0;
        goto again;
    }

    done:

    if (device)
        ao_close(device);
    if (buffer)
        free(buffer);

    ao_free_options(device_options);
    ao_shutdown();

    return status;
}
int main(int ac, char *av[])
{
	FILE *fd_file;
	int fd_audio, fd_audio2;
	int i, loop, ssi_index;
	int err = 0;
	char rep[32];
	int flag;
/*	unsigned int reg, val;
	dbmx_cfg cfg;*/

	printf("Hi... \n");

	if (ac == 1) {
		printf
		    ("main <device> <ssi_nb> <soundfile.wav> [nb_loops]\n Plays the file to /dev/dspX (uncompressed data)\n");
		printf("device : 0 for stdac; 1 for codec ... \n");
		printf("ssi_nb : 1 for SSI1 ... \n");
		return 0;
	}

	/* Open driver in WR mode for stdac, R/W for codec */
	flag = (atoi(av[ARG_DEV]) == 0 ? O_WRONLY : O_RDWR);

	ssi_index = atoi(av[ARG_SSI]);
	if ((fd_audio = open("/dev/sound/dsp", flag)) < 0) {
		printf("Error opening dsp");
		err++;
		goto _err_drv_open1;
	}

	if (ssi_index == 2) {
		fd_audio2 = fd_audio;
		if ((fd_audio = open("/dev/sound/dsp1", O_WRONLY)) < 0) {
			printf("Error opening dsp1");
			err++;
			goto _err_drv_open2;
		}
	}

	if (ac == 5)
		loop = atoi(av[ARG_LOOPS]);
	else
		loop = 1;

	if ((fd_file = fopen(av[ARG_FILE], "r")) <= 0) {
		err++;
		goto _err_file_not_found;
	}

/*	printf("Want to configure the HW (y/n) ?\n"); scanf("%s", rep);
	while ( rep[0] != 'n' )
	{
		printf("R/W reg val (n 0 0 to exit)\n");
		scanf("%s %x %x", rep, &reg, &val);
		cfg.reg = reg; cfg.val = val;
		if ( rep[0] == 'R' ) printf("Read returned = %x\n", ioctl(fd_audio, SNDCTL_DBMX_HW_SSI_CFG_R, &cfg));
		if ( rep[0] == 'W' ) printf("Write returned = %x\n", ioctl(fd_audio, SNDCTL_DBMX_HW_SSI_CFG_W, &cfg));
	}*/

	if (set_audio_config(fd_audio, fd_file) < 0) {
		printf("Bad format for file 1. ");
		printf("Do you want to continue ? (y/n) : ");
		scanf("%s", rep);
		err++;
		if (rep[0] != 'y')
			goto _err_fmt;
	}
	// read the file many times if desired
	for (i = 0; i < loop; i++) {
		err += play_file(fd_audio, fd_file);
	}

	/* Flush output */
	write(fd_audio, NULL, 0);

	printf("************** Closing the device\n");
	fclose(fd_file);
	close(fd_audio);
	close(fd_audio2);

	if (err)
		goto _end_err;
	printf("All tests passed with success\n");
	return 0;

      _err_fmt:
	fclose(fd_file);
      _err_file_not_found:
	close(fd_audio2);
      _err_drv_open2:
	close(fd_audio);
      _err_drv_open1:
      _end_err:
	printf("Encountered %d errors\n", err);
	return err;
}
Exemplo n.º 21
0
void on_open_yuv4m_activate(LiVESMenuItem *menuitem, livespointer user_data) {
  // open a general yuvmpeg stream
  // start "playing" but open frames in yuv4mpeg format on stdin

  int old_file=mainw->current_file,new_file=mainw->first_free_file;
  char *tmp;
  char *filename;
  char *fname;

  char *audio_real,*audio_fake;

  if (menuitem && !do_yuv4m_open_warning()) return;

  fname=lives_strdup(_("yuv4mpeg stream"));

  if (!get_new_handle(new_file,fname)) {
    lives_free(fname);
    return;
  }

  mainw->current_file=new_file;

  if (!strlen(prefs->yuvin))
    filename=lives_build_filename(prefs->tmpdir,"stream.yuv",NULL);
  else
    filename=lives_strdup(prefs->yuvin);

  mkfifo(filename,S_IRUSR|S_IWUSR);

  if (!open_yuv4m_inner(filename,fname,new_file,YUV4_TYPE_GENERIC,0)) {
    close_current_file(old_file);
    lives_free(filename);
    lives_free(fname);
    return;
  }

  lives_free(fname);

  if (!lives_yuv_stream_start_read(cfile)) {
    close_current_file(old_file);
    lives_free(filename);
    return;
  }

  new_file=mainw->current_file;

  lives_snprintf(cfile->type,40,"%s",_("yu4mpeg stream in"));

  d_print((tmp=lives_strdup_printf(_("Opened yuv4mpeg stream on %s"),filename)));
  lives_free(tmp);
  lives_free(filename);

  d_print(_("Audio: "));

  if (cfile->achans==0) {
    d_print(_("none\n"));
  } else {
    d_print((tmp=lives_strdup_printf(P_("%d Hz %d channel %d bps\n","%d Hz %d channels %d bps\n",cfile->achans),
                                     cfile->arate,cfile->achans,cfile->asampsize)));
    lives_free(tmp);
  }

  // if not playing, start playing
  if (mainw->playing_file==-1) {

    // temp kludge, symlink audiodump.pcm to wav file, then pretend we are playing
    // an opening preview . Doesn't work with fifo.
    // and we dont really care if it doesnt work

    // but what it means is, if we have an audio file or stream at
    // "prefs->tmpdir/audiodump.pcm" we will try to play it



    // real is tmpdir/audiodump.pcm
    audio_real=lives_build_filename(prefs->tmpdir,"audiodump.pcm",NULL);
    // fake is tmpdir/handle/audiodump.pcm
    audio_fake=lives_build_filename(prefs->tmpdir,cfile->handle,"audiodump.pcm",NULL);


#ifndef IS_MINGW
    // fake file will go away when we close the current clip
    lives_system((tmp=lives_strdup_printf("/bin/ln -s \"%s\" \"%s\" >/dev/null 2>&1",
                                          audio_real,audio_fake)),TRUE);
#else
    // TODO
#endif

    lives_free(audio_real);
    lives_free(audio_fake);

    lives_free(tmp);

    // start playing
    play_file();

    mainw->noswitch=FALSE;
  }
  // TODO - else...

  if (mainw->current_file!=old_file&&mainw->current_file!=new_file)
    old_file=mainw->current_file; // we could have rendered to a new file

  mainw->current_file=new_file;

  // close this temporary clip
  close_current_file(old_file);

}
Exemplo n.º 22
0
int 
main (int argc, char *argv[])
{
  int option_index = 0, c = 0;

  struct option opts[] = {
    { "server", required_argument, NULL, 's' },
    { "help", no_argument, NULL, 'h' },
    { "version", no_argument, NULL, 'v' },
    { 0, 0, 0, 0 }
  };

  program_name = argv [0];

  /* parse options
   */

  while (1)
    {
      c = getopt_long(argc, argv, "s:hv", opts, &option_index);

      if (c == -1)
	break;

      switch (c)
	{
	case 's':
#ifdef HAVE_SETENV
	  setenv("ESPEAKER", optarg, 1);
#else
#ifdef HAVE_PUTENV
	  {
	    /* The following malloc is correct, and does take into
               account the trailing \0 too.  */
	    char *espeaker_env = malloc (strlen (optarg) + sizeof "ESPEAKER=");
	    if (espeaker_env)
	      {
		strcpy (espeaker_env, "ESPEAKER=");
		strcat (espeaker_env, optarg);
		putenv (espeaker_env);
	      }
	  }
#else
#error "How am I supposed to set an environment variable?"
#endif
#endif
	  break;

	case 'h':
	  usage_exit (0);
	  
	case 'v':
	  /* fputs ("esdplay " VERSION "\n", stdout); */
	  fputs ("esdplay\n", stdout);
	  exit (0);

	case '?':
	  /* `getopt_long' already printed an error message. */
	  fprintf(stderr,"Try `%s --help' for more information.\n", 
		  program_name);
	  exit (1);

	default:
	  abort();
	}
    }

  if (optind != argc-1)
    usage_exit (1);

  return play_file (argv[optind]);
}
Exemplo n.º 23
0
static void call_event_handler(struct call *call, enum call_event ev,
			       const char *str, void *arg)
{
	struct ua *ua = arg;
	const char *peeruri;
	struct call *call2 = NULL;
	int err;

	MAGIC_CHECK(ua);

	peeruri = call_peeruri(call);

	/* stop any ringtones */
	ua->play = mem_deref(ua->play);

	switch (ev) {

	case CALL_EVENT_INCOMING:

		if (contact_block_access(peeruri)) {

			info("ua: blocked access: \"%s\"\n", peeruri);

			ua_event(ua, UA_EVENT_CALL_CLOSED, call, str);
			mem_deref(call);
			break;
		}

		switch (ua->acc->answermode) {

		case ANSWERMODE_EARLY:
			(void)call_progress(call);
			break;

		case ANSWERMODE_AUTO:
			(void)call_answer(call, 200);
			break;

		case ANSWERMODE_MANUAL:
		default:
			if (list_count(&ua->calls) > 1) {
				(void)play_file(&ua->play,
						    "callwaiting.wav", 3);
			}
			else {
				/* Alert user */
				(void)play_file(&ua->play, "ring.wav", -1);
			}

			ua_event(ua, UA_EVENT_CALL_INCOMING, call, peeruri);
			break;
		}
		break;

	case CALL_EVENT_RINGING:
		(void)play_file(&ua->play, "ringback.wav", -1);

		ua_event(ua, UA_EVENT_CALL_RINGING, call, peeruri);
		break;

	case CALL_EVENT_PROGRESS:
		ua_printf(ua, "Call in-progress: %s\n", peeruri);
		ua_event(ua, UA_EVENT_CALL_PROGRESS, call, peeruri);
		break;

	case CALL_EVENT_ESTABLISHED:
		ua_printf(ua, "Call established: %s\n", peeruri);
		ua_event(ua, UA_EVENT_CALL_ESTABLISHED, call, peeruri);
		break;

	case CALL_EVENT_CLOSED:
		if (call_scode(call)) {
			const char *tone;
			tone = translate_errorcode(call_scode(call));
			if (tone)
				(void)play_file(&ua->play, tone, 1);
		}
		ua_event(ua, UA_EVENT_CALL_CLOSED, call, str);
		mem_deref(call);
		break;

	case CALL_EVENT_TRANSFER:

		/*
		 * Create a new call to transfer target.
		 *
		 * NOTE: we will automatically connect a new call to the
		 *       transfer target
		 */

		ua_printf(ua, "transferring call to %s\n", str);

		err = ua_call_alloc(&call2, ua, VIDMODE_ON, NULL, call,
				    call_localuri(call));
		if (!err) {
			struct pl pl;

			pl_set_str(&pl, str);

			err = call_connect(call2, &pl);
			if (err) {
				warning("ua: transfer: connect error: %m\n",
					err);
			}
		}

		if (err) {
			(void)call_notify_sipfrag(call, 500, "Call Error");
			mem_deref(call2);
		}
		break;

	case CALL_EVENT_TRANSFER_FAILED:
		ua_event(ua, UA_EVENT_CALL_TRANSFER_FAILED, call, str);
		break;
	}
}
Exemplo n.º 24
0
static int play_playlist(const char *filename, struct params *default_par) {
    int ret = 0;
    FILE *f;
    char *line = NULL;
    size_t line_mem = 0;
    ssize_t line_len = 0;
    struct params par;

    memcpy(&par, default_par, sizeof(par));

    f = fopen(filename, "r");
    if (!f) {
        fprintf(stderr, "%s: cannot open playlist file\n", filename);
        return -1;
    }

    while ((line_len = getline(&line, &line_mem, f)) >= 0) {

        /* Remove any leading whitespace
         */
        size_t ws_len = strspn(line, "\t ");
        if (ws_len > 0) {
            line_len -= ws_len;
            memmove(line, line + ws_len, line_len + 1);
        }

        /* Remove trailing whitespace
         */
        while (line_len >= 1 && (line[line_len - 1] == '\r' || line[line_len - 1] == '\n'))
            line[--line_len] = '\0';

#define EXT_PREFIX "#EXT-X-VGMSTREAM:"

        if (!strncmp(line, EXT_PREFIX, sizeof(EXT_PREFIX) - 1)) {

            /* Parse vgmstream-specific metadata */

            char *param = strtok(line + sizeof(EXT_PREFIX) - 1, ",");

#define PARAM_MATCHES(NAME) (!strncmp(param, NAME "=", sizeof(NAME)) && arg)

            while (param) {
                char *arg = strchr(param, '=');
                if (arg) arg++;

                if (PARAM_MATCHES("FADEDELAY"))
                    par.fade_delay = atof(arg);
                else if (PARAM_MATCHES("FADETIME"))
                    par.fade_time = atof(arg);
                else if (PARAM_MATCHES("LOOPCOUNT"))
                    par.loop_count = atoi(arg);
                else if (PARAM_MATCHES("STREAMINDEX"))
                    par.stream_index = atoi(arg);

                param = strtok(NULL, ",");
            }
        }

        /* Skip blank or comment lines
         */
        if (line[0] == '\0' || line[0] == '#')
            continue;

        ret = play_file(line, &par);
        if (ret) break;

        /* Reset playback options to default */
        memcpy(&par, default_par, sizeof(par));
    }

    free(line);
    fclose(f);

    return ret;
}
Exemplo n.º 25
0
int
main (int argc, char **argv)
{
  GPtrArray *files;
  gchar **args = NULL;
  guint num, i;
  GError *err = NULL;
  GOptionContext *ctx;
  GOptionEntry options[] = {
    {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL},
    {NULL}
  };
  GTimer *timer;

  if (!g_thread_supported ())
    g_thread_init (NULL);

  ctx = g_option_context_new ("FILES OR DIRECTORIES WITH AUDIO FILES");
  g_option_context_add_main_entries (ctx, options, NULL);
  g_option_context_add_group (ctx, gst_init_get_option_group ());
  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
    exit (1);
  }
  g_option_context_free (ctx);

  if (args == NULL || *args == NULL) {
    g_print ("Please provide one or more directories with audio files\n\n");
    return 1;
  }

  files = g_ptr_array_new ();

  num = g_strv_length (args);
  for (i = 0; i < num; ++i) {
    if (g_path_is_absolute (args[i])) {
      check_arg (files, args[i]);
    } else {
      g_warning ("Argument '%s' is not an absolute file path", args[i]);
    }
  }

  if (files->len == 0) {
    g_print ("Did not find any files\n\n");
    return 1;
  }

  timer = g_timer_new ();

  while (g_timer_elapsed (timer, NULL) < TEST_RUNTIME) {
    gint32 idx;

    idx = g_random_int_range (0, files->len);
    play_file ((const gchar *) g_ptr_array_index (files, idx));
  }

  g_strfreev (args);
  g_timer_destroy (timer);

  return 0;
}
static void play_hello_16000_wav(void) {
	play_file("./sounds/hello16000.wav", FALSE, FALSE, FALSE, 20000);
}
Exemplo n.º 27
0
int main (int argc, char *argv[]) {
	play_file(argv[1]);
	//analyze(argv[1]);
}
Exemplo n.º 28
0
static int play_compressed_file(const char *filename, struct params *par, const char *expand_cmd) {
    int ret;
    char temp_dir[128] = "/tmp/vgmXXXXXX";
    const char *base_name;
    char *last_slash, *last_dot;
    char *cmd = NULL, *temp_file = NULL;
    FILE *in_fp, *out_fp;

    cmd = malloc(strlen(filename) + 1024);
    temp_file = malloc(strlen(filename) + 256);

    if (!cmd || !temp_file)
        return -2;

    if (!mkdtemp(temp_dir)) {
        fprintf(stderr, "%s: error creating temp dir for decompression\n", temp_dir);
        goto fail;
    }

    /* Get the base name of the file path
     */
    last_slash = strrchr(filename, '/');
    if (last_slash)
        base_name = last_slash + 1;
    else
        base_name = filename;

    sprintf(temp_file, "%s/%s", temp_dir, base_name);

    /* Chop off the compressed-file extension
     */
    last_dot = strrchr(temp_file, '.');
    if (last_dot) *last_dot = '\0';

    printf("Decompressing file: %s\n", filename);

    in_fp  = fopen(filename, "rb");
    out_fp = fopen(temp_file, "wb");

    if (in_fp && out_fp) {
        setbuf(in_fp, NULL);
        setbuf(out_fp, NULL);

        /* Don't put filenames into the system() arg; that's insecure!
         */
        sprintf(cmd, "%s <&%d >&%d ", expand_cmd, fileno(in_fp), fileno(out_fp));
        ret = system(cmd);

        if (WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
            interrupted = 1;
    }
    else
        ret = -1;

    if (in_fp && fclose(in_fp))
        ret = -1;
    if (out_fp && fclose(out_fp))
        ret = -1;

    if (ret) {
        if (interrupted) {
            putchar('\r');
            ret = record_interrupt();
            if (ret) fputs("Exiting...\n", stdout);
        }
        else
            fprintf(stderr, "%s: error decompressing file\n", filename);
    }
    else
        ret = play_file(temp_file, par);

    remove(temp_file);
    remove(temp_dir);

    fail:

    free(cmd);
    free(temp_file);

    return ret;
}
Exemplo n.º 29
0
int play(char *fn)
{
    int maxlatency;
    int thread_id;

    current_file_mode = m_memmap_file;

    if (current_file_mode) {
        if (play_memmap(fn))
            return -1;
    } else {
        if (play_file(fn))
            return -1;
    }

	if(seek_table)
	{
		free(seek_table);
		seek_table = NULL;
		seek_table_length = 0;
	}

	get_AAC_format(fn, &file_info, &seek_table, &seek_table_length, 0);

	if(infile->http)
	{
		/* No seeking in http streams */
		mod.is_seekable = 0;
	}
	else
	{
		if (file_info.headertype == 2) /* ADTS header - seekable */
			mod.is_seekable = 1;
		else
			mod.is_seekable = 0; /* ADIF or Headerless - not seekable */
	}

    strcpy(lastfn,fn);
    paused=0;
    decode_pos_ms=0;
    seek_needed=-1;

    /*
      To RageAmp: This is really needed, because aacinfo isn't very accurate on ADIF files yet.
                  Can be fixed though :-)
    */
    file_info.sampling_rate = samplerate;
    file_info.channels = frameInfo.channels;

    maxlatency = mod.outMod->Open(file_info.sampling_rate, file_info.channels, 16, -1,-1);

    if (maxlatency < 0) // error opening device
    {
        return -1;
    }

    // initialize vis stuff
    mod.SAVSAInit(maxlatency, file_info.sampling_rate);
    mod.VSASetInfo(file_info.sampling_rate, file_info.channels);

    mod.SetInfo(file_info.bitrate/1000, file_info.sampling_rate/1000, file_info.channels,1);

    mod.outMod->SetVolume(-666); // set the output plug-ins default volume

    killPlayThread = 0;

    if((play_thread_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PlayThread, (void *) &killPlayThread, 0, &thread_id)) == NULL)
    {
        MessageBox(mod.hMainWindow, "Fatal error: Cannot create playback thread\n", "FAAD Error", MB_OK);
        return -1;
    }

    // Note: This line seriously slows down start up time
	if(m_priority != 3) // if the priority in config window is set to normal, there is nothing to reset!
	    SetThreadPriority(play_thread_handle, priority_table[m_priority]);

    return 0;
}
Exemplo n.º 30
0
int main(int argc, char *argv[])
{
	int c, i;
	char *fn, *fn2 = NULL;
	int cmd_decode = 0;
	int cmd_chg_channels = 0;
	int cmd_info = 0, cmd_play = 0;
	int cf_set_chans = 0;

	while ((c = getopt(argc, argv, "pdiMSqhrmsnvo:")) != -1) {
		switch (c) {
		case 'h':
			usage(0);
			break;
		case 'd':
			cmd_decode = 1;
			break;
		case 'i':
			cmd_info = 1;
			break;
		case 'p':
			cmd_play = 1;
			break;
		case 'M':
			cmd_chg_channels = 1;
			cf_set_chans = 1;
			break;
		case 'S':
			cmd_chg_channels = 1;
			cf_set_chans = 2;
			break;
		case 'q':
			cf_quiet = 1;
			break;
		case 'm':
			cf_force_chans = 1;
			break;
		case 's':
			cf_force_chans = 2;
			break;
		case 'r':
			cf_raw = 1;
			break;
		case 'n':
			cf_no_output = 1;
			break;
		case 'o':
			fn2 = optarg;
			break;
		case 'v':
			printf("%s\n", version);
			exit(0);
		default:
			fprintf(stderr, "bad arg: -%c\n", c);
			usage(1);
		}
	}
	i = cmd_chg_channels + cmd_info + cmd_decode + cmd_play;
	if (i < 1 || i > 1) {
		fprintf(stderr, "only one command at a time please\n");
		usage(1);
	}

	/* play file */
	if (cmd_play) {
#ifdef HAVE_AO
		ao_initialize();
		for (i = optind; i < argc; i++)
			play_file(argv[i]);
		close_audio();
		ao_shutdown();
		return 0;
#else
		fprintf(stderr, "For audio output, please compile with libao.\n");
		return 1;
#endif
	}

	/* show info */
	if (cmd_info) {
		for (i = optind; i < argc; i++)
			show_info(argv[i]);
		return 0;
	}
	
	/* channel changing */
	if (cmd_chg_channels) {
		for (i = optind; i < argc; i++)
			set_channels(argv[i], cf_set_chans);
		return 0;
	}
	
	/* regular converting */
	if (optind == argc)
		usage(1);
	if (fn2) {
		if (optind + 1 != argc)
			usage(1);
		fn = argv[optind];
		decode_file(fn, fn2);
	} else {
		while (optind < argc) {
			fn = argv[optind++];
			fn2 = makefn(fn, cf_raw ? ".raw" : ".wav");
			decode_file(fn, fn2);
			free(fn2);
		}
	}
	return 0;
}