void start_sound()
{  if (sound_recording)
   {  message(0, "already recording");
      return;
   }
   stop_play_file();
   open_sound_record();
   if (!opened)
	 return;
   sound_recording=1;
   SetDlgItemText(hMainDialog,IDC_LISTEN_INDICATOR,"LISTENING");
   init_Mixer_data();
   set_Mixer_data();
   if (!submit_sound_buffer() || !submit_sound_buffer())
   { errormsg("Unable to get buffers for sound recording",0);
	 stop_sound();
     return;
   }
   reset_volumecompression();
   start_encoder();
   error_code = waveInStart( hwavein );
   if( error_code != MMSYSERR_NOERROR)
   { errormsg("Unable to start sound recording.",error_code);
     stop_sound();
	 return;
   }
   meter_on();
}
Exemple #2
0
void handler_func(){
	/*мелодия играет 1 раз*/
	if(!melody_played){
		melody_counter++;
		if(!melody_started){
			if(melody_counter>=ticks_in_ms(ring_interval)){
				melody_started=true;
				melody_counter-=ticks_in_ms(ring_interval);
				/*если звучит тик, нужно его выключить*/
				if(tick_started){
					tick_started=false;
				}
				note_index=0;
				play_note();		
			}
		} else {
			/*нота закончила звучать*/
			if(melody_counter>=ticks_in_ms(notes[note_index].duration)){
				melody_counter-=ticks_in_ms(notes[note_index].duration);			
				note_index++;
				if(note_index==num_notes){
					stop_sound();
					melody_started=false;
					melody_played=true;
				} else {
					play_note();
				}
			}	
		}	
	}
	/*даже если мелодия начала играть, тики все равно отсчитываются, но не звучат*/
	tick_counter++;
	if(tick_started){
		if(tick_counter>=ticks_in_ms(tick_duration)){
			tick_started=false;
			tick_counter-=ticks_in_ms(tick_duration);
			if(!melody_started){
				stop_sound();
			}
		}
	} else {
		uint16_t actual_interval=tick_interval;
		if(tick_occured){
			actual_interval-=tick_duration;
		}
		if(tick_counter>=ticks_in_ms(actual_interval)){
			tick_counter-=ticks_in_ms(actual_interval);
			if(!melody_started){
				tick_started=tick_occured=true;
				play_sound(TICK_FREQ);
			}
		}
	}
}
Exemple #3
0
void cal_play_anim_sound(actor *pActor, struct cal_anim anim, int is_emote){

	unsigned int *cookie;

	cookie = (is_emote) ? (&pActor->cur_emote_sound_cookie):(&pActor->cur_anim_sound_cookie);
	// Check if we need a walking sound
	if (pActor->moving && !pActor->fighting &&!is_emote){
		handle_walking_sound(pActor, anim.sound);
	} else {
		if (check_sound_loops(*cookie))
				stop_sound(*cookie);
		*cookie = 0;
		
		if (anim.sound > -1 && !pActor->dead){
			// We are going to try letting sounds continue until finished, except looping sounds of course
			// Found a sound, so add it
			*cookie = add_sound_object_gain(anim.sound,
							 2*pActor->x_pos,
							 2*pActor->y_pos,
							 pActor->actor_id == yourself ? 1 : 0,
							 anim.sound_scale);
		}
	}

}
Exemple #4
0
int loadgame_simple ()
{
	char home[MAX_PATH], path[MAX_PATH];
	int rc = 0;

	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Error loading game.");
		return err_BadFileOpen;
	}

	sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, 0);

	erase_both();
	stop_sound();
	close_window();

	if ((rc = load_game (path)) == err_OK) {
		message_box ("Game restored.");
		game.exit_all_logics = 1;
		menu_enable_all();
	} else {
		message_box ("Error restoring game.");
	}

	return rc;
}
Exemple #5
0
void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    const char *error_str;

    if (argc != 0) {
        error_str = "Invalid syntax!";
        goto on_error;
    }

    if ( !ASettins.av ) {
        error_str = "Audio not supported!";
        goto on_error;
    }

    ToxAvError error = toxav_cancel(ASettins.av, self->call_idx, self->num,
                                    "Only those who appreciate small things know the beauty that is life");

    if ( error != ErrorNone ) {
        if ( error == ErrorNoCall ) error_str = "No call!";
        else if ( error == ErrorInvalidState ) error_str = "Cannot cancel in invalid state!";
        else error_str = "Internal error!";

        goto on_error;
    }

#ifdef _SOUND_NOTIFY
    stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
    /* Callback will print status... */

    return;
on_error:
    print_err (self, error_str);
}
void JVlibForm::on_System_PauseMidi_button_toggled(bool checked)
{
  unsigned int current_tick;
  if (checked) {
      stopPlayer();
      if (seqTimer->isActive()) {
            disconnect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
            seqTimer->stop();
      }
        snd_seq_get_queue_status(seq, queue, status);
	current_tick = snd_seq_queue_status_get_tick_time(status);
        snd_seq_stop_queue(seq,queue,NULL);
        snd_seq_drain_output(seq);
	stop_sound();
	disconnect_port();
        System_PauseMidi_button->setText("Resume");
  }
  else {
	connect_port();
        snd_seq_continue_queue(seq, queue, NULL);
        snd_seq_drain_output(seq);
        snd_seq_get_queue_status(seq, queue, status);
	current_tick = snd_seq_queue_status_get_tick_time(status);
        System_PauseMidi_button->setText("Pause");
        connect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
	startPlayer(current_tick);
        seqTimer->start(100);
  }
}   // end on_System_PauseMidi_button_toggled
Exemple #7
0
void play_note(){
	if(notes[note_index].freq==WAIT_FREQ){
		stop_sound();
	} else {
		play_sound(notes[note_index].freq);
	}
}
Exemple #8
0
void close_sound() 
{
	int numtimesopened, frequency, channels;
	Uint16 format;

	if (mix_ok) {
		stop_bell();
		stop_UI_sound();
		stop_sound();
		sound_cache.clear();
		stop_music();
		mix_ok = false;

		numtimesopened = Mix_QuerySpec(&frequency, &format, &channels);
		if(numtimesopened == 0) {
			ERR_AUDIO << "Error closing audio device: " << Mix_GetError() << "\n";
		}
		while (numtimesopened) {
			Mix_CloseAudio();
			--numtimesopened;
		}
	}
	if (SDL_WasInit(SDL_INIT_AUDIO) != 0) {
		SDL_QuitSubSystem(SDL_INIT_AUDIO);
	}

	LOG_AUDIO << "Audio device released.\n";
}
Exemple #9
0
void destroy_sound_context(SoundContext* _cnt) {
	ThreadInfo* bgm = 0;
	ThreadInfo* sfx = 0;
	bgm = (ThreadInfo*)_cnt->bgm;
	sfx = (ThreadInfo*)_cnt->sfx;

	stop_sound(_cnt, ST_BGM);
	stop_sound(_cnt, ST_SFX);

	TerminateThread(bgm->thread_handle, 1);
	WaitForSingleObject(bgm->thread_handle, 10);
	CloseHandle(bgm->thread_handle);
	bgm->thread_handle = 0;
	bgm->thread_id = 0;
	TerminateThread(sfx->thread_handle, 1);
	WaitForSingleObject(sfx->thread_handle, 10);
	CloseHandle(sfx->thread_handle);
	sfx->thread_handle = 0;
	sfx->thread_id = 0;

	DeleteCriticalSection(&bgm->lock);
	DeleteCriticalSection(&sfx->lock);

	if(bgm->shadow) {
		if(bgm->shadow->sequence) {
			AGE_FREE(bgm->shadow->sequence);
		}
		AGE_FREE(bgm->shadow);
	}
	if(sfx->shadow) {
		if(sfx->shadow->sequence) {
			AGE_FREE(sfx->shadow->sequence);
		}
		AGE_FREE(sfx->shadow);
	}
	if(bgm->sequence) {
		AGE_FREE(bgm->sequence);
	}
	if(sfx->sequence) {
		AGE_FREE(sfx->sequence);
	}
	AGE_FREE(_cnt->bgm);
	AGE_FREE(_cnt->sfx);
	AGE_FREE(_cnt);
}
/**
 * Set up new room.
 * This function is called when ego enters a new room.
 * @param n room number
 */
void new_room(int n) {
	struct vt_entry *v;
	int i;

	debugC(4, kDebugLevelMain, "*** room %d ***", n);
	stop_sound();

	i = 0;
	for (v = game.view_table; v < &game.view_table[MAX_VIEWTABLE]; v++) {
		v->entry = i++;
		v->flags &= ~(ANIMATED | DRAWN);
		v->flags |= UPDATE;
		v->step_time = 1;
		v->step_time_count = 1;
		v->cycle_time = 1;
		v->cycle_time_count = 1;
		v->step_size = 1;
	}
	agi_unload_resources();

	game.player_control = true;
	game.block.active = false;
	game.horizon = 36;
	game.vars[V_prev_room] = game.vars[V_cur_room];
	game.vars[V_cur_room] = n;
	game.vars[V_border_touch_obj] = 0;
	game.vars[V_border_code] = 0;
	game.vars[V_ego_view_resource] = game.view_table[0].current_view;

	agi_load_resource(rLOGIC, n);

	/* Reposition ego in the new room */
	switch (game.vars[V_border_touch_ego]) {
	case 1:
		game.view_table[0].y_pos = _HEIGHT - 1;
		break;
	case 2:
		game.view_table[0].x_pos = 0;
		break;
	case 3:
		game.view_table[0].y_pos = HORIZON + 1;
		break;
	case 4:
		game.view_table[0].x_pos = _WIDTH - game.view_table[0].x_size;
		break;
	}

	game.vars[V_border_touch_ego] = 0;
	setflag(F_new_room_exec, true);

	game.exit_all_logics = true;

	_text->write_status();
	_text->write_prompt();
}
Exemple #11
0
int main(void)
  {
    init();

/*    start_sound(sound[0], 0, ON);*/ /* Start up the jet engine */

    printf("Press:\n");
    printf("  1)  Machine Gun\n");
    printf("  2)  Crash\n");
    printf("  3)  Cannon\n");
    printf("  4)  Laser\n");
    printf("  5)  Breaking glass\n");
    printf("  Q)  Quit\n");

    stop = FALSE;

    counter = 0;

    do
      {
       /* Increment and display counters */
        counter++;
        cprintf("%8lu %8lu %4u", counter, intcount, voicecount);
        gotoxy(1, wherey());

       /* Maybe start a random sound */
        if (!random(10000))
          {
           num = (random(NUMSOUNDS-1))+1;
           start_sound(sound[num], num, OFF);
          }

       /* Start a sound if a key is pressed */
        if (kbhit())
          {
            inkey = getch();
            if ((inkey >= '0') && (inkey <= '9'))
              {
                num = inkey - '0'; /* Convert to integer */
                if (num < NUMSOUNDS)
                  start_sound(sound[num], num, FALSE);
              }
            else
              stop = TRUE;
          }
      }
    while (!stop);

    printf("\n");
    stop_sound(1); /* Stop the jet engine */

    shutdown();

    return(EXIT_SUCCESS);
  }
Exemple #12
0
static duk_ret_t
js_Sound_stop(duk_context* ctx)
{
	sound_t* sound;

	duk_push_this(ctx);
	duk_get_prop_string(ctx, -1, "\xFF" "ptr"); sound = duk_get_pointer(ctx, -1); duk_pop(ctx);
	duk_pop(ctx);
	stop_sound(sound, true);
	return 0;
}
static void close_sound(void)
{ if (sound_recording)
    stop_sound();
  if (!opened)
    return;
  close_Mixer_data();
  error_code = waveInClose(hwavein);
  if( error_code != MMSYSERR_NOERROR)
     errormsg("Unable to close sound recording.",error_code);
  opened=0;
}
Exemple #14
0
void bomber_sound(void)
{
		function = 'r';
		SysTick->CTRL  = 0;                   // disable SysTick during setup
		SysTick->LOAD = music[3];        // maximum reload value
		SysTick->VAL = 0;                // any write to current clears it             
		SysTick->CTRL = 0x00000007;          // enable SysTick with core clock
		
		if( temp == 100 )
			stop_sound();
		
		temp++;
}
Exemple #15
0
void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
{
    if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    self->call_idx = -1;
    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No answer!");
    
#ifdef _SOUND_NOTIFY
    stop_sound(self->active_sound);
    self->active_sound = -1;
#endif /* _SOUND_NOTIFY */
}
Exemple #16
0
void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
{
    if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    init_infobox(self);

    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
    
#ifdef _SOUND_NOTIFY
    stop_sound(self->active_sound);
    self->active_sound = -1;
#endif /* _SOUND_NOTIFY */
}
Exemple #17
0
void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
{
    if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    kill_infobox(self);
    self->call_idx = -1;
    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer disconnected; call ended!");
    
#ifdef _SOUND_NOTIFY
    stop_sound(self->active_sound);
    self->active_sound = -1;
#endif /* _SOUND_NOTIFY */
}
Exemple #18
0
int loadgame_dialog ()
{
	char home[MAX_PATH], path[MAX_PATH];
	int rc, slot = 0;
	int hm, vm, hp, vp;			/* box margins */
	int w;

	hm = 2; vm = 3;
	hp = hm * CHAR_COLS; vp = vm * CHAR_LINES;
	w = (40 - 2 * hm) - 1;

	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Error loading game.");
		return err_BadFileOpen;
	}

	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);

	erase_both();
	stop_sound();

	draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
	print_text ("Select a game which you wish to\nrestore:",
		0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	print_text ("Press ENTER to select, ESC cancels",
		0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);

	slot = select_slot (path);

	if (slot < 0) {
		message_box ("Game NOT restored.");
		return err_OK;
	}

	sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, slot);

	if ((rc = load_game (path)) == err_OK) {
		message_box ("Game restored.");
		game.exit_all_logics = 1;
		menu_enable_all();
	} else {
		message_box ("Error restoring game.");
	}

	return rc;
}
Exemple #19
0
void play_sound_string(SoundContext* _cnt, const Str _seq, SoundType _type, bl _loop) {
	ThreadInfo* thread = 0;
	stop_sound(_cnt, _type);
	if(_type == ST_BGM) {
		thread = (ThreadInfo*)(_cnt->bgm);
	} else if(_type == ST_SFX) {
		thread = (ThreadInfo*)(_cnt->sfx);
	} else {
		assert(0 && "Unknown sound type");
	}
	EnterCriticalSection(&thread->lock); {
		thread->sequence = copy_string(_seq);
		thread->loop = _loop;
		thread->stop = FALSE;
	} LeaveCriticalSection(&thread->lock);
	age_sleep(1);
}
Exemple #20
0
void JVlibForm::on_System_PlayMidi_button_toggled(bool checked) {
    if (checked) {
	seqTimer = new QTimer(this);
        System_PauseMidi_button->setEnabled(true);
        System_OpenMidi_button->setEnabled(false);
        System_PlayMidi_button->setText("Stop");
	System_MIDI_progressBar->setEnabled(true);
        connect_port();
        // queue won't actually start until it is drained
        int err = snd_seq_start_queue(seq, queue, NULL);
        check_snd("start queue", err);
	System_PlayMidi_status->on();
        connect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
        seqTimer->start(100);
	startPlayer(0);
    }
    else {
        if (seqTimer->isActive()) {
            disconnect(JVlibForm::seqTimer, SIGNAL(timeout()), this, SLOT(tickDisplay()));
            seqTimer->stop();
	    delete seqTimer;
        }
        snd_seq_stop_queue(seq,queue,NULL);
        snd_seq_drain_output(seq);
	stopPlayer();
	stop_sound();
        disconnect_port();
	System_PlayMidi_status->off();
	System_MIDI_progressBar->blockSignals(true);
        System_MIDI_progressBar->setValue(0);
	System_MIDI_progressBar->blockSignals(false);
        MIDI_time_display->setText("00:00");
        if (System_PauseMidi_button->isChecked()) {
            System_PauseMidi_button->blockSignals(true);
            System_PauseMidi_button->setChecked(false);
            System_PauseMidi_button->blockSignals(false);
            System_PauseMidi_button->setText("Pause");
        }
        System_PauseMidi_button->setEnabled(false);
        System_PlayMidi_button->setText("Play");
        System_OpenMidi_button->setEnabled(true);
	System_MIDI_Transpose->setEnabled(true);
	System_MIDI_progressBar->setEnabled(false);
	event_num=0;
    }
}   // end on_System_PlayMidi_button_toggled
Exemple #21
0
//pause between notes for half the tempo
static bool
be_quiet(void *data)
{
    struct piezo_speaker_data *mdata = data;
    int r;

    r = stop_sound(mdata);

    if (r < 0 || mdata->curr_state == ITER_LAST) {
        tune_stop(mdata);
        return false;
    }

    mdata->curr_idx = (mdata->curr_idx + 1) % mdata->num_entries;

    mdata->timer = sol_timeout_add(mdata->tempo_ms / 2, timeout_do, mdata);

    return false;
}
Exemple #22
0
int loadgame_simple ()
{
	char home[MAX_PATH], path[MAX_PATH];
	int rc = 0;
        printf("here?\n");

#ifdef DREAMCAST
	uint8 addr, port, unit;

	addr = maple_first_vmu();
	if (addr) {
		maple_create_port (addr, &port, &unit);
		sprintf (g_vmu_port, "%c%d", port + 'a', unit);
	} else {
		message_box("No VMU found.");
		return err_OK;
	}

	sprintf(path, VMU_PATH, g_vmu_port, game.id, slot);
#else	
	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Error loading game.");
		return err_BadFileOpen;
	}

	sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, 0);
#endif

	erase_both();
	stop_sound();
	close_window();

	if ((rc = load_game (path)) == err_OK) {
		message_box ("Game restored.");
		game.exit_all_logics = 1;
		menu_enable_all();
	} else {
		message_box ("Error restoring game.");
	}

	return rc;
}
Exemple #23
0
/* Terminate all sounds but wait for them to finish first */
void graceful_clear()
{
    control_lock();

    while (1) {
        int i;

        for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
            if (actives[i].active) {
            #ifdef BOX_NOTIFY
                if (actives[i].box) {
                    GError* ignore;
                    notify_notification_close(actives[i].box, &ignore);
                    actives[i].box = NULL;
                }
            #endif

                if(actives[i].id_indicator)
                    *actives[i].id_indicator = -1;    /* reset indicator value */

                if ( actives[i].looping ) {
                    stop_sound(i);
                } else {
                    if (!is_playing(actives[i].source))
                        memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
                    else break;
                }
            }
        }

        if (i == ACTIVE_NOTIFS_MAX) {
            m_close_device(); /* In case it's opened */
            control_unlock();
            return;
        }

        usleep(1000);
    }

    control_unlock();
}
Exemple #24
0
void cal_reset_emote_anims(actor *pActor, int cycles_too){

	struct CalMixer *mixer;
	emote_anim *cur_emote;

	if (pActor==NULL)
		return;

	if (pActor->calmodel==NULL)
		return;

	mixer=CalModel_GetMixer(pActor->calmodel);	
	cur_emote=&pActor->cur_emote;

	//remove emote idle
	if(cur_emote->idle.anim_index>=0&&cycles_too) {
		//printf("CAL_reset cycle %i\n",cur_emote->idle.anim_index);
		CalMixer_ClearCycle(mixer,cur_emote->idle.anim_index, cal_cycle_blending_delay);
		cur_emote->idle.anim_index=-1;
	}
	if(cur_emote->active) {
		int i;
		//remove actions
		for(i=0;i<cur_emote->nframes;i++){
			if(cur_emote->frames[i].anim_index>=0&&cur_emote->frames[i].kind==action){
				//printf("CAL_reset action %i\n",cur_emote->frames[i].anim_index);
				CalMixer_RemoveAction(mixer,cur_emote->frames[i].anim_index);
				cur_emote->frames[i].anim_index=-1;
			}
		}
	}
	cur_emote->active=0;

#ifdef NEW_SOUND
	if(pActor->cur_emote_sound_cookie)
		stop_sound(pActor->cur_emote_sound_cookie);
#endif
	
}
Exemple #25
0
void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    const char *error_str;

    if (argc != 0) {
        error_str = "Unknown arguments.";
        goto on_error;
    }

    if ( !ASettins.av ) {
        error_str = "Audio not supported!";
        goto on_error;
    }

    ToxAvError error;

    if (toxav_get_call_state(ASettins.av, self->call_idx) == av_CallInviting) {
        error = toxav_cancel(ASettins.av, self->call_idx, self->num,
                                        "Only those who appreciate small things know the beauty that is life");
#ifdef SOUND_NOTIFY
        stop_sound(self->ringing_sound);
#endif
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call canceled!");
    } else {
        error = toxav_hangup(ASettins.av, self->call_idx);
    }

    if ( error != ErrorNone ) {
        if ( error == ErrorInvalidState ) error_str = "Cannot hangup in invalid state!";
        else if ( error == ErrorNoCall ) error_str = "No call!";
        else error_str = "Internal error!";

        goto on_error;
    }

    return;
on_error:
    print_err (self, error_str);
}
void exit_sound(void)
{ if (sound_recording) stop_sound();
  kill_encoder();
  close_sound();
}
Exemple #27
0
void weather_sound_control()
{
	static Uint32 last_sound_update = 0;
	int i;

	if (cur_time < last_sound_update + 200) return;
	else last_sound_update = cur_time;

	if (!sound_on)
	{
		rain_sound = 0;
	}
	else
	{
		if (weather_ratios[WEATHER_RAIN] > 0.0)
		{
			// Torg: Only load sounds when we need them so we aren't wasting sources.
			// This is really only for NEW_SOUND.
			if (rain_sound == 0)
#ifdef NEW_SOUND
				rain_sound = add_server_sound(snd_rain, 0, 0, weather_ratios[WEATHER_RAIN]);
			else
				sound_source_set_gain(rain_sound, weather_ratios[WEATHER_RAIN]);
#endif	//NEW_SOUND
		}
		else
		{
			if (rain_sound > 0)
			{
				stop_sound(rain_sound);
				rain_sound = 0;
			}
		}
	}
		
	for (i = 0; i < thunders_count; )
	{
		float dx = thunders[i].x_pos + camera_x;
		float dy = thunders[i].y_pos + camera_y;
		float dist = sqrtf(dx*dx + dy*dy);
		if (cur_time >= thunders[i].time + dist/SOUND_SPEED)
		{
			if (sound_on)
			{
				int snd_thunder = 0;
			
				switch (thunders[i].type)
				{
				case 0:  snd_thunder = snd_thndr_1; break;
				case 1:  snd_thunder = snd_thndr_2; break;
				case 2:  snd_thunder = snd_thndr_3; break;
				case 3:  snd_thunder = snd_thndr_4; break;
				case 4:  snd_thunder = snd_thndr_5; break;
				default: snd_thunder = 0;
				}
			
				if (snd_thunder)
				{
#ifdef NEW_SOUND
					add_server_sound(snd_thunder, 0, 0, 1.0f);
#endif	//NEW_SOUND
				}
			}
			
			// we remove the thunder from the list
			if (i < --thunders_count)
				memcpy(&thunders[i], &thunders[thunders_count], sizeof(thunder));
		}
		else ++i;
	}
}
void start_sound(int resnum, int flag) {
	int i, type;
#ifdef USE_IIGS_SOUND
	struct sound_iigs_sample *smp;
#endif

	if (game.sounds[resnum].flags & SOUND_PLAYING)
		return;

	stop_sound();

	if (game.sounds[resnum].rdata == NULL)
		return;

	type = READ_LE_UINT16(game.sounds[resnum].rdata);

	if (type != AGI_SOUND_SAMPLE && type != AGI_SOUND_MIDI && type != AGI_SOUND_4CHN)
		return;

	game.sounds[resnum].flags |= SOUND_PLAYING;
	game.sounds[resnum].type = type;
	playing_sound = resnum;
	song = (uint8 *) game.sounds[resnum].rdata;

	switch (type) {
#ifdef USE_IIGS_SOUND
	case AGI_SOUND_SAMPLE:
		debugC(3, kDebugLevelSound, "IIGS sample");
		smp = (struct sound_iigs_sample *)game.sounds[resnum].rdata;
		for (i = 0; i < NUM_CHANNELS; i++) {
			chn[i].type = type;
			chn[i].flags = 0;
			chn[i].ins = (int16 *) & game.sounds[resnum].rdata[54];
			chn[i].size = ((int)smp->size_hi << 8) + smp->size_lo;
			chn[i].ptr = &play_sample[i];
			chn[i].timer = 0;
			chn[i].vol = 0;
			chn[i].end = 0;
		}
		break;
	case AGI_SOUND_MIDI:
		debugC(3, kDebugLevelSound, "IIGS MIDI sequence");

		for (i = 0; i < NUM_CHANNELS; i++) {
			chn[i].type = type;
			chn[i].flags = AGI_SOUND_LOOP | AGI_SOUND_ENVELOPE;
			chn[i].ins = waveform;
			chn[i].size = WAVEFORM_SIZE;
			chn[i].vol = 0;
			chn[i].end = 0;
		}

		chn[0].timer = *(song + 2);
		chn[0].ptr = (struct agi_note *)(song + 3);
		break;
#endif
	case AGI_SOUND_4CHN:
		/* Initialize channel info */
		for (i = 0; i < NUM_CHANNELS; i++) {
			chn[i].type = type;
			chn[i].flags = AGI_SOUND_LOOP;
			if (env) {
				chn[i].flags |= AGI_SOUND_ENVELOPE;
				chn[i].adsr = AGI_SOUND_ENV_ATTACK;
			}
			chn[i].ins = waveform;
			chn[i].size = WAVEFORM_SIZE;
			chn[i].ptr = (struct agi_note *)(song + (song[i << 1] | (song[(i << 1) + 1] << 8)));
			chn[i].timer = 0;
			chn[i].vol = 0;
			chn[i].end = 0;
		}
		break;
	}

	memset(snd_buffer, 0, BUFFER_SIZE << 1);
	endflag = flag;

	/* Nat Budin reports that the flag should be reset when sound starts
	 */
	setflag(endflag, false);

	/* FIXME: should wait for sound time instead of setting the flag
	 *        immediately
	 */
	if (opt.nosound) {
		setflag(endflag, true);
		stop_sound();
	}
}
Exemple #29
0
int loadgame_dialog ()
{
#ifndef PALMOS
	char home[MAX_PATH], path[MAX_PATH];
	int rc, slot = 0;
	int hm, vm, hp, vp;			/* box margins */
	int w;

	hm = 2; vm = 3;
	hp = hm * CHAR_COLS; vp = vm * CHAR_LINES;
	w = (40 - 2 * hm) - 1;

#ifdef DREAMCAST
	uint8 addr, port, unit;

	addr = maple_first_vmu();
	if (addr) {
		maple_create_port (addr, &port, &unit);
		sprintf (g_vmu_port, "%c%d", port + 'a', unit);
	} else {
		message_box("No VMU found.");
		return err_OK;
	}
#else
	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Error loading game.");
		return err_BadFileOpen;
	}

# ifdef CIBYL
	sprintf (path, "recordstore://%05X.%s:",
                 game.crc, game.id);
# else
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
# endif
#endif

	erase_both();
	stop_sound();

	draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
	print_text ("Select a game which you wish to\nrestore:",
		0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	print_text ("Press ENTER to select, ESC cancels",
		0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);

	slot = select_slot (path);

	if (slot < 0) {
		message_box ("Game NOT restored.");
		return err_OK;
	}

#ifdef DREAMCAST
	sprintf(path, VMU_PATH, g_vmu_port, game.id, slot);
#elif CIBYL
	sprintf (path, "recordstore://%05X.%s:%d",
		game.crc, game.id, slot+1);
        printf("path: %s\n", path);
#else	
	sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, slot);
#endif

	if ((rc = load_game (path)) == err_OK) {
		message_box ("Game restored.");
		game.exit_all_logics = 1;
		menu_enable_all();
	} else {
		message_box ("Error restoring game.");
	}

	return rc;
#endif /* PALMOS */
}
static int play_game() {
	int ec = err_OK;

	debugC(2, kDebugLevelMain, "initializing...");
	debugC(2, kDebugLevelMain, "game.ver = 0x%x", game.ver);

	stop_sound();
	clear_screen(0);

	game.horizon = HORIZON;
	game.player_control = false;

	setflag(F_logic_zero_firsttime, true);	/* not in 2.917 */
	setflag(F_new_room_exec, true);	/* needed for MUMG and SQ2! */
	setflag(F_sound_on, true);	/* enable sound */
	setvar(V_time_delay, 2);	/* "normal" speed */

	game.gfx_mode = true;
	game.quit_prog_now = false;
	game.clock_enabled = true;
	game.line_user_input = 22;

	if (opt.agimouse)
		report("Using AGI Mouse 1.0 protocol\n");

	report("Running AGI script.\n");

	setflag(F_entered_cli, false);
	setflag(F_said_accepted_input, false);
	game.vars[V_word_not_found] = 0;
	game.vars[V_key] = 0;

	debugC(2, kDebugLevelMain, "Entering main loop");
	do {

		if (!main_cycle())
			continue;

		if (getvar(V_time_delay) == 0 ||
		    (1 + clock_count) % getvar(V_time_delay) == 0) {
			if (!game.has_prompt && game.input_mode == INPUT_NORMAL) {
				_text->write_prompt();
				game.has_prompt = 1;
			} else
			    if (game.has_prompt && game.input_mode == INPUT_NONE) {
				_text->write_prompt();
				game.has_prompt = 0;
			}

			interpret_cycle();

			setflag(F_entered_cli, false);
			setflag(F_said_accepted_input, false);
			game.vars[V_word_not_found] = 0;
			game.vars[V_key] = 0;
		}

		if (game.quit_prog_now == 0xff)
			ec = err_RestartGame;

	} while (game.quit_prog_now == 0);

	stop_sound();

	return ec;
}