Mercurial > SDL_sound_CoreAudio
comparison playsound/playsound.c @ 280:06fbb106a554
Can now read from stdin.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 14 Mar 2002 21:11:52 +0000 |
parents | 0ac181b5adc6 |
children | 6c059c4d2cea |
comparison
equal
deleted
inserted
replaced
279:52b9f37998db | 280:06fbb106a554 |
---|---|
106 " --format fmt Playback in fmt format (see below).\n" | 106 " --format fmt Playback in fmt format (see below).\n" |
107 " --channels n Playback on n channels (1 or 2).\n" | 107 " --channels n Playback on n channels (1 or 2).\n" |
108 " --decodebuf n Buffer n decoded bytes at a time (default %d).\n" | 108 " --decodebuf n Buffer n decoded bytes at a time (default %d).\n" |
109 " --audiobuf n Buffer n samples to audio device (default %d).\n" | 109 " --audiobuf n Buffer n samples to audio device (default %d).\n" |
110 " --volume n Playback volume multiplier (default 1.0).\n" | 110 " --volume n Playback volume multiplier (default 1.0).\n" |
111 " --stdin [ext] Read from stdin (treat data as format [ext])\n" | |
111 " --version Display version information and exit.\n" | 112 " --version Display version information and exit.\n" |
112 " --decoders List supported data formats and exit.\n" | 113 " --decoders List supported data formats and exit.\n" |
113 " --predecode Decode entire sample before playback.\n" | 114 " --predecode Decode entire sample before playback.\n" |
114 " --loop Loop playback until SIGINT.\n" | 115 " --loop Loop playback until SIGINT.\n" |
115 " --credits Shameless promotion.\n" | 116 " --credits Shameless promotion.\n" |
474 else if (strcmp(argv[i], "--loop") == 0) | 475 else if (strcmp(argv[i], "--loop") == 0) |
475 { | 476 { |
476 looping = 1; | 477 looping = 1; |
477 } /* else if */ | 478 } /* else if */ |
478 | 479 |
480 else if (strcmp(argv[i], "--stdin") == 0) | |
481 { | |
482 /* deal with it at Sound_Sample creation time... */ | |
483 } /* else if */ | |
484 | |
479 else | 485 else |
480 { | 486 { |
481 fprintf(stderr, "unknown option: \"%s\"\n", argv[i]); | 487 fprintf(stderr, "unknown option: \"%s\"\n", argv[i]); |
482 return(42); | 488 return(42); |
483 } /* else */ | 489 } /* else */ |
511 | 517 |
512 signal(SIGINT, sigint_catcher); | 518 signal(SIGINT, sigint_catcher); |
513 | 519 |
514 for (i = 1; i < argc; i++) | 520 for (i = 1; i < argc; i++) |
515 { | 521 { |
522 char *filename = NULL; | |
523 | |
516 /* !!! FIXME: This is ugly! */ | 524 /* !!! FIXME: This is ugly! */ |
517 if ( (strcmp(argv[i], "--rate") == 0) || | 525 if ( (strcmp(argv[i], "--rate") == 0) || |
518 (strcmp(argv[i], "--format") == 0) || | 526 (strcmp(argv[i], "--format") == 0) || |
519 (strcmp(argv[i], "--channels") == 0) || | 527 (strcmp(argv[i], "--channels") == 0) || |
520 (strcmp(argv[i], "--audiobuf") == 0) || | 528 (strcmp(argv[i], "--audiobuf") == 0) || |
523 { | 531 { |
524 i++; | 532 i++; |
525 continue; | 533 continue; |
526 } /* if */ | 534 } /* if */ |
527 | 535 |
528 if (strncmp(argv[i], "--", 2) == 0) | 536 if (strcmp(argv[i], "--stdin") == 0) |
537 { | |
538 SDL_RWops *rw = SDL_RWFromFP(stdin, 1); | |
539 filename = "...from stdin..."; | |
540 | |
541 /* | |
542 * The second argument will be NULL if --stdin is the last | |
543 * thing on the command line. This is correct behaviour. | |
544 */ | |
545 sample = Sound_NewSample(rw, argv[++i], | |
546 use_specific_audiofmt ? &sound_desired : NULL, | |
547 decode_buffersize); | |
548 } | |
549 | |
550 else if (strncmp(argv[i], "--", 2) == 0) | |
551 { | |
529 continue; | 552 continue; |
530 | 553 } |
531 sample = Sound_NewSampleFromFile(argv[i], | 554 |
532 use_specific_audiofmt ? &sound_desired : NULL, | 555 else |
533 decode_buffersize); | 556 { |
557 filename = argv[i]; | |
558 sample = Sound_NewSampleFromFile(argv[i], | |
559 use_specific_audiofmt ? &sound_desired : NULL, | |
560 decode_buffersize); | |
561 } | |
534 | 562 |
535 if (!sample) | 563 if (!sample) |
536 { | 564 { |
537 fprintf(stderr, "Couldn't load \"%s\"!\n" | 565 fprintf(stderr, "Couldn't load \"%s\"!\n" |
538 " reason: [%s].\n", argv[i], Sound_GetError()); | 566 " reason: [%s].\n", filename, Sound_GetError()); |
539 continue; | 567 continue; |
540 } /* if */ | 568 } /* if */ |
541 | 569 |
542 /* | 570 /* |
543 * Unless explicitly specified, pick the format from the sound | 571 * Unless explicitly specified, pick the format from the sound |
567 Sound_Quit(); | 595 Sound_Quit(); |
568 SDL_Quit(); | 596 SDL_Quit(); |
569 return(42); | 597 return(42); |
570 } /* if */ | 598 } /* if */ |
571 | 599 |
572 printf("Now playing [%s]...\n", argv[i]); | 600 printf("Now playing [%s]...\n", filename); |
573 | 601 |
574 if (predecode) | 602 if (predecode) |
575 { | 603 { |
576 printf(" predecoding...", argv[i]); | 604 printf(" predecoding..."); |
577 decoded_bytes = Sound_DecodeAll(sample); | 605 decoded_bytes = Sound_DecodeAll(sample); |
578 decoded_ptr = sample->buffer; | 606 decoded_ptr = sample->buffer; |
579 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) | 607 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
580 { | 608 { |
581 fprintf(stderr, | 609 fprintf(stderr, |
582 "Couldn't fully decode \"%s\"!\n" | 610 "Couldn't fully decode \"%s\"!\n" |
583 " reason: [%s].\n" | 611 " reason: [%s].\n" |
584 " (playing first %lu bytes of decoded data...)\n", | 612 " (playing first %lu bytes of decoded data...)\n", |
585 argv[i], Sound_GetError(), decoded_bytes); | 613 filename, Sound_GetError(), decoded_bytes); |
586 } /* if */ | 614 } /* if */ |
587 else | 615 else |
588 { | 616 { |
589 printf("done.\n"); | 617 printf("done.\n"); |
590 } /* else */ | 618 } /* else */ |