예제 #1
0
파일: sound.c 프로젝트: zacaj/pinball-sound
uint32_t audio(void *data)
{
	if(!paused) {
		uint8_t out=128;

		int32_t s=0;
		for(int i=0;i<MAX_SOUND;i++) {
			if(sounds[i]==NULL)
				continue;
			Sample ss=sound_get(i);
			s+=ss;
		}

		//out=(s/256)+127;//(at/4)<2?0:255;//
		//out=s;
		//out=(at%4)<2? 0:255;
		//GPIO_Write(bD,out<<8);
	/*	if(s)
			STM_EVAL_LEDOn(LED4);
		else
			STM_EVAL_LEDOff(LED4);*/
		int32_t S=((int32_t)s)+65535/2;
		DAC_SetChannel1Data(DAC_Align_12b_R, S>>4);
		at++;
		t += 1.0 / rate;
	}
예제 #2
0
파일: outfit.c 프로젝트: pegue/naev
/**
 * @brief Parses the afterburner tidbits of the outfit.
 *
 *    @param temp Outfit to finish loading.
 *    @param parent Outfit's parent node.
 */
static void outfit_parseSAfterburner( Outfit* temp, const xmlNodePtr parent )
{
   xmlNodePtr node;
   node = parent->children;

   /* must be >= 1. */
   temp->u.afb.thrust_perc = 1.;
   temp->u.afb.speed_perc = 1.;
   
   do { /* parse the data */
      xmlr_float(node,"rumble",temp->u.afb.rumble);
      if (xml_isNode(node,"sound"))
         temp->u.afb.sound = sound_get( xml_get(node) );

      if (xml_isNode(node,"thrust_perc"))
         temp->u.afb.thrust_perc = 1. + xml_getFloat(node)/100.;
      xmlr_float(node,"thrust_abs",temp->u.afb.thrust_abs);
      if (xml_isNode(node,"speed_perc"))
         temp->u.afb.speed_perc = 1. + xml_getFloat(node)/100.;
      xmlr_float(node,"speed_abs",temp->u.afb.speed_abs);
      xmlr_float(node,"energy",temp->u.afb.energy);
   } while (xml_nextNode(node));
}
예제 #3
0
파일: sound.c 프로젝트: zacaj/pinball-sound
Sample sound_get(int i) {
	Sound *sound=sounds[i];

	if(sound->f_loc>=sound->file.fsize)
		sound->done=1;
	if(!sound->ready[sound->cur] || sound->f_loc>=sound->file.fsize || sound->done)
		return 0;

	uint32_t off=sound->f_loc - sound->start[sound->cur];
	if(off>40000 || sound->cur>1)
		return 0;
	if(off>=sound->size[sound->cur]) {
		sound->ready[sound->cur]=0;
		free(sound->data[sound->cur]);
		sound->data[sound->cur]=NULL;
		sound->cur=!sound->cur;
		return sound_get(i);
	}
	else {
		sound->f_loc+=sizeof(Sample);
		Sample t=*((Sample*)(sound->data[sound->cur]+off));
		return t;
	}
}
예제 #4
0
파일: sound.c 프로젝트: EVWeb/naev
/**
 * @brief Initializes the sound subsystem.
 *
 *    @return 0 on success.
 */
int sound_init (void)
{
   int ret;

   /* See if sound is disabled. */
   if (conf.nosound) {
      sound_disabled = 1;
      music_disabled = 1;
   }

   /* Parse conf. */
   if (sound_disabled && music_disabled)
      return 0;

   /* Choose sound system. */
   if ((sound_sys_init == NULL) && (conf.sound_backend != NULL) &&
         (strcmp(conf.sound_backend,"openal")==0)) {
#if USE_OPENAL
      /*
       * OpenAL Sound.
       */
      /* Creation. */
      sound_sys_init       = sound_al_init;
      sound_sys_exit       = sound_al_exit;
      /* Sound Creation. */
      sound_sys_load       = sound_al_load;
      sound_sys_free       = sound_al_free;
      /* Sound settings. */
      sound_sys_volume     = sound_al_volume;
      sound_sys_getVolume  = sound_al_getVolume;
      sound_sys_getVolumeLog = sound_al_getVolumeLog;
      /* Sound playing. */
      sound_sys_play       = sound_al_play;
      sound_sys_playPos    = sound_al_playPos;
      sound_sys_updatePos  = sound_al_updatePos;
      sound_sys_updateVoice = sound_al_updateVoice;
      /* Sound management. */
      sound_sys_update     = sound_al_update;
      sound_sys_stop       = sound_al_stop;
      sound_sys_pause      = sound_al_pause;
      sound_sys_resume     = sound_al_resume;
      sound_sys_setSpeed   = sound_al_setSpeed;
      sound_sys_setSpeedVolume = sound_al_setSpeedVolume;
      /* Listener. */
      sound_sys_updateListener = sound_al_updateListener;
      /* Groups. */
      sound_sys_createGroup = sound_al_createGroup;
      sound_sys_playGroup  = sound_al_playGroup;
      sound_sys_stopGroup  = sound_al_stopGroup;
      sound_sys_pauseGroup = sound_al_pauseGroup;
      sound_sys_resumeGroup = sound_al_resumeGroup;
      sound_sys_speedGroup = sound_al_speedGroup;
      sound_sys_volumeGroup = sound_al_volumeGroup;
      /* Env. */
      sound_sys_env        = sound_al_env;
#else /* USE_OPENAL */
      WARN("OpenAL support not compiled in!");
#endif /* USE_OPENAL */
   }
   if ((sound_sys_init == NULL) && (conf.sound_backend != NULL) &&
         (strcmp(conf.sound_backend,"sdlmix")==0)) {
#if USE_SDLMIX
      /*
       * SDL_mixer Sound.
       */
      /* Creation. */
      sound_sys_init       = sound_mix_init;
      sound_sys_exit       = sound_mix_exit;
      /* Sound Creation. */
      sound_sys_load       = sound_mix_load;
      sound_sys_free       = sound_mix_free;
      /* Sound settings. */
      sound_sys_volume     = sound_mix_volume;
      sound_sys_getVolume  = sound_mix_getVolume;
      sound_sys_getVolumeLog = sound_mix_getVolumeLog;
      /* Sound playing. */
      sound_sys_play       = sound_mix_play;
      sound_sys_playPos    = sound_mix_playPos;
      sound_sys_updatePos  = sound_mix_updatePos;
      sound_sys_updateVoice = sound_mix_updateVoice;
      /* Sound management. */
      sound_sys_update     = sound_mix_update;
      sound_sys_stop       = sound_mix_stop;
      sound_sys_pause      = sound_mix_pause;
      sound_sys_resume     = sound_mix_resume;
      sound_sys_setSpeed   = sound_mix_setSpeed;
      sound_sys_setSpeedVolume = sound_mix_setSpeedVolume;
      /* Listener. */
      sound_sys_updateListener = sound_mix_updateListener;
      /* Groups. */
      sound_sys_createGroup = sound_mix_createGroup;
      sound_sys_playGroup  = sound_mix_playGroup;
      sound_sys_stopGroup  = sound_mix_stopGroup;
      sound_sys_pauseGroup = sound_mix_pauseGroup;
      sound_sys_resumeGroup = sound_mix_resumeGroup;
      sound_sys_speedGroup = sound_mix_speedGroup;
      sound_sys_volumeGroup = sound_mix_volumeGroup;
      /* Env. */
      sound_sys_env        = sound_mix_env;
#else /* USE_SDLMIX */
      WARN("SDL_mixer support not compiled in!");
#endif /* USE_SDLMIX */
   }
   if (sound_sys_init == NULL) {
      WARN("Unknown/Unavailable sound backend '%s'.", conf.sound_backend);
      sound_disabled = 1;
      WARN("Sound disabled.");
      music_disabled = 1;
      return 0;
   }

   /* Initialize sound backend. */
   ret = sound_sys_init();
   if (ret != 0) {
      sound_disabled = 1;
      music_disabled = 1;
      WARN("Sound disabled.");
      return ret;
   }

   /* Create voice lock. */
   voice_mutex = SDL_CreateMutex();
   if (voice_mutex == NULL)
      WARN("Unable to create voice mutex.");

   /* Load available sounds. */
   ret = sound_makeList();
   if (ret != 0)
      return ret;

   /* Initialize music. */
   ret = music_init();
   if (ret != 0) {
      music_disabled = 1;
      WARN("Music disabled.");
   }

   /* Set volume. */
   if ((conf.sound > 1.) || (conf.sound < 0.))
      WARN("Sound has invalid value, clamping to [0:1].");
   sound_volume(conf.sound);

   /* Initialized. */
   sound_initialized = 1;

   /* Load compression noise. */
   snd_compression = sound_get( "compression" );
   if (snd_compression >= 0) {
      snd_compressionG = sound_createGroup( 1 );
      sound_speedGroup( snd_compressionG, 0 );
   }


   return 0;
}
예제 #5
0
파일: outfit.c 프로젝트: pegue/naev
/**
 * @brief Parses the specific area for a weapon and loads it into Outfit.
 *
 *    @param temp Outfit to finish loading.
 *    @param parent Outfit's parent node.
 */
static void outfit_parseSAmmo( Outfit* temp, const xmlNodePtr parent )
{
   xmlNodePtr node;
   char *buf;

   node = parent->xmlChildrenNode;

   /* Defaults. */
   temp->u.amm.spfx_armour = -1;
   temp->u.amm.spfx_shield = -1;
   temp->u.amm.sound = -1;

   do { /* load all the data */
      /* Basic */
      xmlr_float(node,"duration",temp->u.amm.duration);
      xmlr_float(node,"lockon",temp->u.amm.lockon);
      xmlr_float(node,"resist",temp->u.amm.resist);
      /* Movement */
      xmlr_float(node,"thrust",temp->u.amm.thrust);
      xmlr_float(node,"turn",temp->u.amm.turn);
      xmlr_float(node,"speed",temp->u.amm.speed);
      xmlr_float(node,"accuracy",temp->u.amm.accuracy);
      xmlr_float(node,"energy",temp->u.amm.energy);
      if (xml_isNode(node,"gfx")) {
         temp->u.amm.gfx_space = xml_parseTexture( node,
               OUTFIT_GFX"space/%s.png", 6, 6,
               OPENGL_TEX_MAPTRANS );
         xmlr_attr(node, "spin", buf);
         if (buf != NULL) {
            outfit_setProp( temp, OUTFIT_PROP_WEAP_SPIN );
            temp->u.blt.spin = atof( buf );
            free(buf);
         }
         continue;
      }
      else if (xml_isNode(node,"spfx_armour"))
         temp->u.amm.spfx_armour = spfx_get(xml_get(node));
      else if (xml_isNode(node,"spfx_shield"))
         temp->u.amm.spfx_shield = spfx_get(xml_get(node));
      else if (xml_isNode(node,"sound"))
         temp->u.amm.sound = sound_get( xml_get(node) );
      else if (xml_isNode(node,"damage"))
         outfit_parseDamage( &temp->u.amm.dtype, &temp->u.amm.damage, node );
   } while (xml_nextNode(node));

   /* Post-processing */
   temp->u.amm.resist /= 100.; /* Set it in per one */

#define MELEMENT(o,s) \
if (o) WARN("Outfit '%s' missing/invalid '"s"' element", temp->name) /**< Define to help check for data errors. */
   MELEMENT(temp->u.amm.gfx_space==NULL,"gfx");
   MELEMENT(temp->u.amm.spfx_shield==-1,"spfx_shield");
   MELEMENT(temp->u.amm.spfx_armour==-1,"spfx_armour");
   MELEMENT((sound_disabled!=0) && (temp->u.amm.sound<0),"sound");
   /* MELEMENT(temp->u.amm.thrust==0,"thrust"); */
   /* Dumb missiles don't need everything */
   if (outfit_isSeeker(temp)) {
      MELEMENT(temp->u.amm.turn==0,"turn");
      MELEMENT(temp->u.amm.lockon==0,"lockon");
   }
   MELEMENT(temp->u.amm.speed==0,"speed");
   MELEMENT(temp->u.amm.duration==0,"duration");
   MELEMENT(temp->u.amm.damage==0,"damage");
#undef MELEMENT
}
예제 #6
0
파일: outfit.c 프로젝트: pegue/naev
/**
 * @brief Parses the beam weapon specifics of an outfit.
 *
 *    @param temp Outfit to finish loading.
 *    @param parent Outfit's parent node.
 */
static void outfit_parseSBeam( Outfit* temp, const xmlNodePtr parent )
{
   xmlNodePtr node;

   /* Defaults. */
   temp->u.bem.spfx_armour = -1;
   temp->u.bem.spfx_shield = -1;
   temp->u.bem.sound_warmup = -1;
   temp->u.bem.sound = -1;
   temp->u.bem.sound_off = -1;

   node = parent->xmlChildrenNode;
   do { /* load all the data */
      xmlr_float(node,"range",temp->u.bem.range);
      xmlr_float(node,"turn",temp->u.bem.turn);
      xmlr_float(node,"energy",temp->u.bem.energy);
      xmlr_long(node,"delay",temp->u.bem.delay);
      xmlr_float(node,"warmup",temp->u.bem.warmup);
      xmlr_float(node,"duration",temp->u.bem.duration);

      if (xml_isNode(node,"damage")) {
         outfit_parseDamage( &temp->u.bem.dtype, &temp->u.bem.damage, node );
         continue;
      }

      /* Graphic stuff. */
      if (xml_isNode(node,"gfx")) {
         temp->u.bem.gfx = xml_parseTexture( node,
               OUTFIT_GFX"space/%s.png", 1, 1, 0 );
         continue;
      }
      if (xml_isNode(node,"spfx_armour")) {
         temp->u.bem.spfx_armour = spfx_get(xml_get(node));
         continue;
      }
      if (xml_isNode(node,"spfx_shield")) {
         temp->u.bem.spfx_shield = spfx_get(xml_get(node));
         continue;
      }

      /* Sound stuff. */
      if (xml_isNode(node,"sound_warmup")) {
         temp->u.bem.sound_warmup = sound_get( xml_get(node) );
         continue;
      }
      if (xml_isNode(node,"sound")) {
         temp->u.bem.sound = sound_get( xml_get(node) );
         continue;
      }
      if (xml_isNode(node,"sound_off")) {
         temp->u.bem.sound_off = sound_get( xml_get(node) );
         continue;
      }
   } while (xml_nextNode(node));

#define MELEMENT(o,s) \
if (o) WARN("Outfit '%s' missing/invalid '"s"' element", temp->name) /**< Define to help check for data errors. */
   MELEMENT(temp->u.bem.gfx==NULL,"gfx");
   MELEMENT(temp->u.bem.spfx_shield==-1,"spfx_shield");
   MELEMENT(temp->u.bem.spfx_armour==-1,"spfx_armour");
   MELEMENT((sound_disabled!=0) && (temp->u.bem.warmup > 0.) && (temp->u.bem.sound<0),"sound_warmup");
   MELEMENT((sound_disabled!=0) && (temp->u.bem.sound<0),"sound");
   MELEMENT((sound_disabled!=0) && (temp->u.bem.sound_off<0),"sound_off");
   MELEMENT(temp->u.bem.delay==0,"delay");
   MELEMENT(temp->u.bem.duration==0,"duration");
   MELEMENT(temp->u.bem.range==0,"range");
   MELEMENT((temp->type!=OUTFIT_TYPE_BEAM) && (temp->u.bem.turn==0),"turn");
   MELEMENT(temp->u.bem.energy==0,"energy");
   MELEMENT(temp->u.bem.damage==0,"damage");
#undef MELEMENT
}
예제 #7
0
파일: outfit.c 프로젝트: pegue/naev
/**
 * @brief Parses the specific area for a bolt weapon and loads it into Outfit.
 *
 *    @param temp Outfit to finish loading.
 *    @param parent Outfit's parent node.
 */
static void outfit_parseSBolt( Outfit* temp, const xmlNodePtr parent )
{
   xmlNodePtr node;
   char *buf;

   /* Defaults */
   temp->u.blt.spfx_armour = -1;
   temp->u.blt.spfx_shield = -1;
   temp->u.blt.sound = -1;

   node = parent->xmlChildrenNode;
   do { /* load all the data */
      xmlr_float(node,"speed",temp->u.blt.speed);
      xmlr_float(node,"delay",temp->u.blt.delay);
      xmlr_float(node,"range",temp->u.blt.range);
      xmlr_float(node,"accuracy",temp->u.blt.accuracy);
      xmlr_float(node,"energy",temp->u.blt.energy);

      if (xml_isNode(node,"gfx")) {
         temp->u.blt.gfx_space = xml_parseTexture( node,
               OUTFIT_GFX"space/%s.png", 6, 6,
               OPENGL_TEX_MAPTRANS );
         xmlr_attr(node, "spin", buf);
         if (buf != NULL) {
            outfit_setProp( temp, OUTFIT_PROP_WEAP_SPIN );
            temp->u.blt.spin = atof( buf );
            free(buf);
         }
         continue;
      }
      if (xml_isNode(node,"spfx_shield")) {
         temp->u.blt.spfx_shield = spfx_get(xml_get(node));
         continue;
      }
      if (xml_isNode(node,"spfx_armour")) {
         temp->u.blt.spfx_armour = spfx_get(xml_get(node));
         continue;
      }
      if (xml_isNode(node,"sound")) {
         temp->u.blt.sound = sound_get( xml_get(node) );
         continue;
      }
      if (xml_isNode(node,"damage")) {
         outfit_parseDamage( &temp->u.blt.dtype, &temp->u.blt.damage, node );
         continue;
      }
   } while (xml_nextNode(node));

#define MELEMENT(o,s) \
if (o) WARN("Outfit '%s' missing/invalid '"s"' element", temp->name) /**< Define to help check for data errors. */
   MELEMENT(temp->u.blt.gfx_space==NULL,"gfx");
   MELEMENT(temp->u.blt.spfx_shield==-1,"spfx_shield");
   MELEMENT(temp->u.blt.spfx_armour==-1,"spfx_armour");
   MELEMENT((sound_disabled!=0) && (temp->u.blt.sound<0),"sound");
   MELEMENT(temp->u.blt.delay==0,"delay");
   MELEMENT(temp->u.blt.speed==0,"speed");
   MELEMENT(temp->u.blt.range==0,"range");
   MELEMENT(temp->u.blt.accuracy==0,"accuracy");
   MELEMENT(temp->u.blt.damage==0,"damage");
#undef MELEMENT
}