示例#1
0
// ---------------------------------------------------------------------------------------
// Initialize the game sound system
// 
// Initialize the game sound system.  Depending on what sound library is being used,
// call the appropriate low-level initiailizations
//
// returns:     1		=> init success
//              0		=> init failed
//
int snd_init(int use_a3d, int use_eax)
{
	int rval;

	if ( Cmdline_freespace_no_sound )
		return 0;

	if (ds_initialized)	{
		nprintf(( "Sound", "SOUND => Direct Sound is already initialized!\n" ));
		return 1;
	}

	snd_clear();

	// Init DirectSound 

	// Connect to DirectSound
	int num_tries=0;
	int gave_warning = 0;
	while(1) {
		rval = ds_init(use_a3d, use_eax);

		if( rval != 0 ) {
			nprintf(( "Sound", "SOUND ==> Error initializing DirectSound, trying again in 1 second.\n"));
			Sleep(1000);
		} else {
			break;
		}

		if ( num_tries++ > 5 ) {
			if ( !gave_warning ) {
				MessageBox(NULL, XSTR("DirectSound could not be initialized.  If you are running any applications playing sound in the background, you should stop them before continuing.",971), NULL, MB_OK);
				gave_warning = 1;
			} else {
				goto Failure;
			}
		}
	}

	// Init the Audio Compression Manager
	if ( ACM_init() == -1 ) {
		HWND hwnd = (HWND)os_get_window();
		MessageBox(hwnd, XSTR("Could not properly initialize the Microsoft ADPCM codec.\n\nPlease see the readme.txt file for detailed instructions on installing the Microsoft ADPCM codec.",972), NULL, MB_OK);
//		Warning(LOCATION, "Could not properly initialize the Microsoft ADPCM codec.\nPlease see the readme.txt file for detailed instructions on installing the Microsoft ADPCM codec.");
	}

	// Init the audio streaming stuff
	audiostream_init();
			
	ds_initialized = 1;
	return 1;

Failure:
//	Warning(LOCATION, "Sound system was unable to be initialized.  If you continue, sound will be disabled.\n");
	nprintf(( "Sound", "SOUND => Direct Sound init unsuccessful, continuing without sound.\n" ));
	return 0;
}
示例#2
0
// ---------------------------------------------------------------------------------------
// Initialize the game sound system
// 
// Initialize the game sound system.  Depending on what sound library is being used,
// call the appropriate low-level initiailizations
//
// returns:     1		=> init success
//              0		=> init failed
//
int snd_init()
{
	int rval;

	if ( Cmdline_freespace_no_sound )
		return 0;

	if (ds_initialized)	{
		nprintf(( "Sound", "SOUND => Audio is already initialized!\n" ));
		return 1;
	}

	snd_clear();


	rval = ds_init();

	if ( rval != 0 ) {
		nprintf(( "Sound", "SOUND ==> Fatal error initializing audio device, turn sound off.\n" ));
		Cmdline_freespace_no_sound = Cmdline_freespace_no_music = 1;
		goto Failure;
	}

	if ( OGG_init() == -1 ) {
		mprintf(("Could not initialize the OGG vorbis converter.\n"));
	}

	snd_aav_init();

	// Init the audio streaming stuff
	audiostream_init();
			
	ds_initialized = 1;
	Sound_enabled = TRUE;
	return 1;

Failure:
//	Warning(LOCATION, "Sound system was unable to be initialized.  If you continue, sound will be disabled.\n");
	nprintf(( "Sound", "SOUND => Audio init unsuccessful, continuing without sound.\n" ));
	return 0;
}
示例#3
0
FFMovie *ffmovie_open(const char *filename)
{
/* MAIN THREAD */
    FFMovie *movie;
    int err, i;
    AVFormatParameters params = {0};

    if(!ffmovie_initialized) {
        ffmovie_initialized = 1;
        av_register_all();
    }
    
    movie = av_mallocz(sizeof(FFMovie));
    if (!movie)
        return NULL;

    err = av_open_input_file(&movie->context, filename, NULL, 0, &params);
    if (err < 0) {
        print_error(filename, err);
        return NULL;
    }

    err = av_find_stream_info(movie->context);
    if (err < 0) {
        av_free(movie);
        fprintf(stderr, "%s: could not find codec parameters\n", filename);
        return NULL;
    }

    /*find and open streams*/
    for(i = 0; i < movie->context->nb_streams; i++) {
        AVStream *stream = movie->context->streams[i];
        switch(stream->codec.codec_type) {
            case CODEC_TYPE_AUDIO:
                if (!movie->audio_st && !movie->audio_disable)
                    audiostream_init(movie, stream);
                break;
            case CODEC_TYPE_VIDEO:
                if (!movie->video_st)
                    videostream_init(movie, stream);
                break;
            default: break;
        }
    }

    if (!movie->video_st && !movie->audio_st) {
        fprintf(stderr, "%s: could not open codecs\n", filename);
        ffmovie_cleanup(movie);
        return NULL;
    }

    movie->frame_count = 0;
    movie->time_offset = 0.0;
    movie->paused = 1;
    movie->sourcename = strdup(filename);

    Global_num_active++;
    movie->decode_thread = SDL_CreateThread(decode_thread, movie);
    if (!movie->decode_thread) {
        ffmovie_cleanup(movie);
        return NULL;
    }
    return movie;
}