Mercurial > SDL_sound_CoreAudio
comparison playsound/playsound.c @ 573:1911fc597c69
Set a WM caption, which the PulseAudio target can use for display purposes.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 24 Jan 2010 14:01:39 -0500 |
parents | 7815c90ba552 |
children |
comparison
equal
deleted
inserted
replaced
572:7815c90ba552 | 573:1911fc597c69 |
---|---|
717 | 717 |
718 return(1); /* everything appears to be in order. */ | 718 return(1); /* everything appears to be in order. */ |
719 } /* valid_cmdline */ | 719 } /* valid_cmdline */ |
720 | 720 |
721 | 721 |
722 static void report_filename(const char *filename) | |
723 { | |
724 const char *icon = "playsound"; | |
725 size_t len = 0; | |
726 char *buf = NULL; | |
727 char *ptr = NULL; | |
728 | |
729 fprintf(stdout, "%s: Now playing [%s]...\n", icon, filename); | |
730 | |
731 /* | |
732 * Bleeding edge versions of SDL 1.2 can use this to set the | |
733 * PulseAudio application name. It's a harmless no-op elsewhere, | |
734 * and 1.3 will probably have a formal API for this. | |
735 */ | |
736 ptr = strrchr(filename, '/'); | |
737 if (ptr != NULL) | |
738 filename = ptr + 1; | |
739 ptr = strrchr(filename, '\\'); | |
740 if (ptr != NULL) | |
741 filename = ptr + 1; | |
742 | |
743 len = strlen(filename) + strlen(icon) + 3; | |
744 buf = (char *) malloc(len); | |
745 if (buf == NULL) | |
746 SDL_WM_SetCaption(icon, icon); | |
747 else | |
748 { | |
749 snprintf(buf, len, "%s: %s", icon, filename); | |
750 SDL_WM_SetCaption(buf, icon); | |
751 free(buf); | |
752 } /* else */ | |
753 } /* report_filename */ | |
754 | |
755 | |
722 int main(int argc, char **argv) | 756 int main(int argc, char **argv) |
723 { | 757 { |
724 Sound_AudioInfo sound_desired; | 758 Sound_AudioInfo sound_desired; |
725 SDL_AudioSpec sdl_desired; | 759 SDL_AudioSpec sdl_desired; |
726 Uint32 audio_buffersize; | 760 Uint32 audio_buffersize; |
979 | 1013 |
980 sdl_desired.samples = audio_buffersize; | 1014 sdl_desired.samples = audio_buffersize; |
981 sdl_desired.callback = audio_callback; | 1015 sdl_desired.callback = audio_callback; |
982 sdl_desired.userdata = sample; | 1016 sdl_desired.userdata = sample; |
983 | 1017 |
1018 /* grr, SDL_CloseAudio() calls SDL_QuitSubSystem internally. */ | |
1019 if (!SDL_WasInit(SDL_INIT_AUDIO)) | |
1020 { | |
1021 if (SDL_Init(SDL_INIT_AUDIO) == -1) | |
1022 { | |
1023 fprintf(stderr, "SDL_Init() failed!\n" | |
1024 " reason: [%s].\n", SDL_GetError()); | |
1025 Sound_Quit(); | |
1026 SDL_Quit(); | |
1027 return(42); | |
1028 } /* if */ | |
1029 } /* if */ | |
1030 | |
1031 report_filename(filename); | |
1032 | |
984 if (SDL_OpenAudio(&sdl_desired, NULL) < 0) | 1033 if (SDL_OpenAudio(&sdl_desired, NULL) < 0) |
985 { | 1034 { |
986 fprintf(stderr, "Couldn't open audio device!\n" | 1035 fprintf(stderr, "Couldn't open audio device!\n" |
987 " reason: [%s].\n", SDL_GetError()); | 1036 " reason: [%s].\n", SDL_GetError()); |
988 Sound_Quit(); | 1037 Sound_Quit(); |
989 SDL_Quit(); | 1038 SDL_Quit(); |
990 return(42); | 1039 return(42); |
991 } /* if */ | 1040 } /* if */ |
992 | |
993 fprintf(stdout, "Now playing [%s]...\n", filename); | |
994 | 1041 |
995 if (global_state.predecode) | 1042 if (global_state.predecode) |
996 { | 1043 { |
997 fprintf(stdout, " predecoding..."); | 1044 fprintf(stdout, " predecoding..."); |
998 global_state.decoded_bytes = Sound_DecodeAll(sample); | 1045 global_state.decoded_bytes = Sound_DecodeAll(sample); |