//Load Sound .wav to memory
int AddVoice(const char *filename, int sfx)
{
    SAMPLE *samp;
    int v;
    samp=load_sample(filename);
    if(!samp)
        return 0;
    if((v=allocate_voice(samp))==-1)
    {
        destroy_sample(samp);
        return 0;
    }
    if(sfx)
    {
        voice_len_sfx++;
        VoicesSfx=(int*)realloc(VoicesSfx,voice_len_sfx*sizeof(int));
        VoicesSfx[voice_len_sfx-1]=v;
        voice_set_volume(v,Effect_volume);
    }
    else
    {
        voice_len_music++;
        VoicesMusic=(int*)realloc(VoicesMusic,voice_len_music*sizeof(int));
        VoicesMusic[voice_len_music-1]=v;
        voice_set_volume(v,Music_volume);
    }

    return v;
}
Exemple #2
0
BITMAP *GetCurrentBitmap(struct Animation *Anim)
{
   LastSpeedStore = LastSpeed;
   if (Anim->SkateVoice >= 0) {
      if (LastSpeed >= 1.0f && OnLand)
         voice_set_volume(Anim->SkateVoice, 256 - (256 / LastSpeed));
      else
         voice_set_volume(Anim->SkateVoice, 0);
   }
   return Anim->CBitmap;
}
Exemple #3
0
void try_sample_backwards(int sample_index, int x, int y, int volume, int priority, int freq)
{
    if (!snd_data)
       return;

    SAMPLE *s = (SAMPLE *)(snd_data[sample_index].dat);
    int voice = allocate_voice(s);

    if (!playfield->visible(x,y))
    {
      volume /= 2;
      priority /= 2;
    }
    
    if (voice >=0)
    {
         voice_set_volume(voice,volume);
         voice_set_priority(voice,priority);
         voice_set_frequency(voice, voice_get_frequency(voice) * freq / 1000);
         voice_set_playmode(voice, PLAYMODE_BACKWARD);
         voice_start(voice);
         release_voice(voice);
    }


}
Exemple #4
0
// allocates a voice for the sample "wav_index" (index into zelda.dat)
// if a voice is already allocated (and/or playing), then it just returns true
// Returns true:  voice is allocated
//         false: unsuccessful
bool sfx_init(int index)
{
    // check index
    if(index<=0 || index>=WAV_COUNT)
        return false;
        
    if(sfx_voice[index]==-1)
    {
        if(sfxdat)
        {
            if(index<Z35)
            {
                sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[index].dat);
            }
            else
            {
                sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[Z35].dat);
            }
        }
        else
        {
            sfx_voice[index]=allocate_voice(&customsfxdata[index]);
        }
        
        voice_set_volume(sfx_voice[index], sfx_volume);
    }
    
    return sfx_voice[index] != -1;
}
Exemple #5
0
void try_loop(short *voice, int sample_index, int x, int y, int volume, int priority, int freq)
{
    if (!snd_data)
       return;

    SAMPLE *s = (SAMPLE *)(snd_data[sample_index].dat);

    if (*voice <0)
    {
        *voice = allocate_voice(s);
         if (*voice >= 0)
         {
            voice_start(*voice);
            voice_set_frequency(*voice, voice_get_frequency(*voice) * freq / 1000);
         }
    }

    if (playfield && !playfield->visible(x,y))
    {
      volume /= 2;
      priority /= 2;
    }
    
    if (*voice >=0)
    {
         voice_set_volume(*voice,volume);
         voice_set_priority(*voice,priority);
         voice_set_playmode(*voice, PLAYMODE_LOOP);
    }

}
Exemple #6
0
void set_all_voice_volume(int sfx_volume)
{
    for(int i=0; i<WAV_COUNT; ++i)
    {
        //allegro assertion fails when passing in -1 as voice -DD
        if(sfx_voice[i] > 0)
            voice_set_volume(sfx_voice[i], sfx_volume);
    }
}
void SetEffectsVolume(int volume)
{
    int i;
    for(i=0; i<voice_len_sfx; i++)
    {
        voice_set_volume(VoicesSfx[i], Effect_volume);
    }
    set_config_int("sound","Effect_volume",Effect_volume);
    flush_config_file();
}
void SetMusicVolume(int volume)
{
    int i;
    for(i=0; i<voice_len_music; i++)
    {
        voice_set_volume(VoicesMusic[i], Music_volume);
    }
    set_config_int("sound","Music_volume",Music_volume);
    flush_config_file();
}
void alogg_adjust_ogg(ALOGG_OGG *ogg, int vol, int pan, int speed, int loop) {
  /* return if we are not playing */
  if (!alogg_is_playing_ogg(ogg))
    return;

  /* adjust the sample */
  adjust_sample(ogg->audiostream->samp, vol, pan, speed, TRUE);
  voice_set_volume (ogg->audiostream->voice, vol);
  ogg->loop = loop;
}
Exemple #10
0
  void set_volume(int newvol)
  {
    vol = newvol;

    if (voice >= 0)
    {
      newvol += volModifier + directionalVolModifier;
      if (newvol < 0) newvol = 0;
      voice_set_volume(voice, newvol);
    }
  }
Exemple #11
0
void set_mod_volume (int volume)
{
    int chn;

    if (volume < 0)
        volume = 0;
    else if (volume > 255)
        volume = 255;
        
    mod_volume = volume;

    for (chn=0; chn<mi.max_chn ; chn++)
        voice_set_volume (voice_table[chn], calc_volume(chn));
}
Exemple #12
0
void stop_mod (void)
{
    int index;

    if (of == null)
        return;

    mi.forbid = TRUE;
    mi.is_playing = FALSE;
    mi.trk = 0;
    for (index=0; index<(mi.max_chn); index++)
        {
        voice_stop (voice_table[index]);
        voice_set_volume (voice_table[index], 0);
        }
        
    of = null;
    mi.forbid = FALSE;
}END_OF_FUNCTION (stop_mod)
Exemple #13
0
bool JamulSoundPlay(int voice, long pan, long vol, byte playFlags)
{
	// if this copy is in use, can't play it
	if (voice_get_position(voice) > 0)
	{
		if (playFlags & SOUND_CUTOFF)
		{
			voice_set_position(voice, 0);
			// keep going to handle the rest of the stuff
		}
		else
			return FALSE; // can't play if it's playing
	}

	// set the pan and volume and start the voice
	voice_set_volume(voice, vol);
	voice_set_pan(voice, pan);
	voice_start(voice);

	return TRUE;
}
void cSoundPlayer::playSound(SAMPLE *sample, int pan, int vol) {
	if (maximumVoices < 0) return;

	assert(sample);
	if (vol < 0) return;
	assert(pan >= 0 && pan < 256);
	assert(vol > 0 && vol <= 256);

	// allocate voice
	int voice = allocate_voice(sample);

	if (voice != -1) {
		voice_set_playmode(voice,0);
		voice_set_volume(voice, vol);
		voice_set_pan(voice, pan);
		voice_start(voice);
		for (int i = 0; i < maximumVoices; i++) {
			if (voices[i] == -1) {
				voices[i] = voice;
				break;
			}
		}
	}
}
Exemple #15
0
/* (`allegro_init()' is already defined by Allegro itself.)  */
static int allegro_init_sound(const char *param, int *speed,
                              int *fragsize, int *fragnr, int *channels)
{
    unsigned int i;

    /* No stereo capability. */
    *channels = 1;

    if (allegro_startup(*speed) < 0)
        return 1;

    fragment_size = *fragsize * sizeof(SWORD);

    buffer_len = fragment_size * *fragnr;
    buffer = create_sample(16, 0, *speed, buffer_len / sizeof(SWORD));

    for (i = 0; i < buffer_len / 2; i++)
        *((WORD *)buffer->data + i) = 0x8000;

    voice = allocate_voice(buffer);
    if (voice < 0) {
        log_debug("Cannot allocate Allegro voice!\n");
        destroy_sample(buffer);
        return 1;
    }

    buffer_offset = 0;
    been_suspended = 1;
    written_samples = 0;

    voice_set_playmode(voice, PLAYMODE_LOOP);
    voice_set_volume(voice, 255);
    voice_set_pan(voice, 128);

    return 0;
}
Exemple #16
0
int install_mod(int max_chn)
{
    int index;
    int temp=0;

    if (mod_init == TRUE)      // don't need to initialize many times
        return 1;

    register_datafile_jgmod();

    if ( (max_chn > MAX_ALLEG_VOICE) || (max_chn <= 0) )
        return -1;

    if (fake_sample == null)
        fake_sample = (SAMPLE *)jgmod_calloc (sizeof (SAMPLE));     // use to trick allegro
                                                    // into giving me voice
    if (fake_sample == null)                        // channels
        {
        sprintf (jgmod_error, "Unable to setup initialization sample");
        return -1;
        }

    fake_sample->freq = 1000;
    fake_sample->loop_start = 0;
    fake_sample->loop_end = 0;
    fake_sample->priority = JGMOD_PRIORITY;

    #ifdef ALLEGRO_DATE         // for compatibility with Allegro 3.0
    fake_sample->stereo = FALSE;
    #endif

    fake_sample->bits = 8;
    fake_sample->len  = 0;
    fake_sample->param = -1;
    fake_sample->data = jgmod_calloc (0);

    if (fake_sample->data == null)
        {
        sprintf (jgmod_error, "JGMOD : Not enough memory to setup initialization sample");
        free (fake_sample);
        return -1;
        }

    for (index=0; index<max_chn; index++)    //allocate all the voices
        {
        voice_table[index] = allocate_voice (fake_sample);
        if (voice_table[index] == -1)
            temp = -1;
        else
            {
            ci[index].volume = 0;
            voice_set_volume (voice_table[index], 0);
            voice_start (voice_table[index]);
            }
        }
    
    if (temp == -1)
        {
        for (index=0; index<max_chn; index++)
            if (voice_table[index] != -1)
                {
                deallocate_voice (voice_table[index]);
                voice_table[index] = -1;
                }

        sprintf (jgmod_error, "JGMOD : Unable to allocate enough voices");
        return -1;
        }

    mi.max_chn = max_chn;
    mi.is_playing = FALSE;
    mi.speed_ratio = 100;
    mi.pitch_ratio = 100;
    mod_init = TRUE;

    atexit (remove_mod);
    lock_jgmod_player();    // lock functions and variables in player.c
    lock_jgmod_player2();   // in player2.c
    lock_jgmod_player3();   // in player3.c
    lock_jgmod_player4();   // in player4.c
    lock_jgmod_mod();       // and mod.c

    return 1;
}
Exemple #17
0
void MYWAVE::adjust_volume()
{
    if (voice >= 0)
        voice_set_volume(voice, get_final_volume());
}
Exemple #18
0
void saSetVolume( int channel, int data )
{
    voice_set_volume(hVoice[channel],data);
}
Exemple #19
0
static void bluetooth_parse_command(uint8_t len)
{
	uint8_t response = RESPONSE_OK;

	sei();

	if (len == 0) {
		response = RESPONSE_NO_RESPONSE;
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_HELP, len) == 0) {
		uint8_t i = 0;

		for (i = 1; i < sizeof(commands) / sizeof(commands[0]); i ++) {
			uart_puts(commands[i]);

			if ((i % 3) == 0) {
				uart_puts("\r\n");
			} else {
				uint8_t padding = 0, j = 0;
				padding = 26 - strlen(commands[i]);
				for (j = 0; j < padding; j++) {
					uart_putc(' ');
				}
			}
		}

		if (((i - 1) % 3) != 0) {
			uart_puts("\r\n");
		}

		response = RESPONSE_NO_RESPONSE;
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_BATTERY, len) == 0) {
		uint8_t capacity = 0;
		char resp[16];

		capacity = battery_get_capacity();
		itoa(capacity, resp, 10);

		uart_puts(BLUETOOTH_CMD_BATTERY);
		uart_puts(": ");
		uart_puts(resp);
		uart_puts("%\r\n");

		response = RESPONSE_NO_RESPONSE;
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_ECHO, len) == 0) {
		echo = TRUE;
		uart_puts("\r\n");
		response = RESPONSE_NO_RESPONSE;
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_EYES, strlen(BLUETOOTH_CMD_EYES)) == 0) {
		char *param = rxbuff + strlen(BLUETOOTH_CMD_EYES) + 1;

		if (len == strlen(BLUETOOTH_CMD_EYES) + strlen(BLUETOOTH_PARAM_ON) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_ON, strlen(BLUETOOTH_PARAM_ON)) == 0) {
				power_on(EYES);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_EYES) + strlen(BLUETOOTH_PARAM_OFF) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_OFF, strlen(BLUETOOTH_PARAM_OFF)) == 0) {
				power_off(EYES);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_EYES)) {
			uint8_t state = power_state(EYES);

			uart_puts(BLUETOOTH_CMD_EYES);
			uart_puts(": ");

			if (state == POWER_ON) {
				uart_puts(BLUETOOTH_PARAM_ON);
			} else {
				uart_puts(BLUETOOTH_PARAM_OFF);
			}
			uart_puts("\r\n");

			response = RESPONSE_NO_RESPONSE;
		} else {
			response = RESPONSE_ERROR;
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_HELMET, strlen(BLUETOOTH_CMD_HELMET)) == 0) {
		char *param = rxbuff + strlen(BLUETOOTH_CMD_HELMET) + 1;

		if (len == strlen(BLUETOOTH_CMD_HELMET) + strlen(BLUETOOTH_PARAM_OPEN) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_OPEN, strlen(BLUETOOTH_PARAM_OPEN)) == 0) {
				helmet_open();
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_HELMET) + strlen(BLUETOOTH_PARAM_CLOSE) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_CLOSE, strlen(BLUETOOTH_PARAM_CLOSE)) == 0) {
				helmet_close();
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_HELMET)) {
			uint8_t state = helmet_state();

			uart_puts(BLUETOOTH_CMD_HELMET);
			uart_puts(": ");

			if (state == HELMET_OPEN) {
				uart_puts(BLUETOOTH_PARAM_OPEN);
			} else {
				uart_puts(BLUETOOTH_PARAM_CLOSE);
			}
			uart_puts("\r\n");

			response = RESPONSE_NO_RESPONSE;
		} else {
			response = RESPONSE_ERROR;
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_INTENSITY, strlen(BLUETOOTH_CMD_INTENSITY)) == 0) {
		uint8_t device = 0;
		char *param = rxbuff + strlen(BLUETOOTH_CMD_INTENSITY) + 1;

		if (strncmp(param, BLUETOOTH_CMD_EYES, strlen(BLUETOOTH_CMD_EYES)) == 0) {
			if (len == strlen(BLUETOOTH_CMD_INTENSITY) + strlen(BLUETOOTH_CMD_EYES) + 3) {
				device = EYES;
			} else if (len == strlen(BLUETOOTH_CMD_INTENSITY) + strlen(BLUETOOTH_CMD_EYES) + 1) {
				device = EYES;
				response = RESPONSE_NO_RESPONSE;
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (strncmp(param, BLUETOOTH_CMD_REPULSORS, strlen(BLUETOOTH_CMD_REPULSORS)) == 0) {
			if (len == strlen(BLUETOOTH_CMD_INTENSITY) + strlen(BLUETOOTH_CMD_REPULSORS) + 3) {
				device = REPULSORS_POWER;
			} else if (len == strlen(BLUETOOTH_CMD_INTENSITY) + strlen(BLUETOOTH_CMD_REPULSORS) + 1) {
				device = REPULSORS_POWER;
				response = RESPONSE_NO_RESPONSE;
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (strncmp(param, BLUETOOTH_CMD_UNIBEAM, strlen(BLUETOOTH_CMD_UNIBEAM)) == 0) {
			if (len == strlen(BLUETOOTH_CMD_INTENSITY) + strlen(BLUETOOTH_CMD_UNIBEAM) + 3) {
				device = UNIBEAM;
			} else if (len == strlen(BLUETOOTH_CMD_INTENSITY) + strlen(BLUETOOTH_CMD_UNIBEAM) + 1) {
				device = UNIBEAM;
				response = RESPONSE_NO_RESPONSE;
			} else {
				response = RESPONSE_ERROR;
			}
		} else {
			response = RESPONSE_ERROR;
		}

		if (response == RESPONSE_OK) {
			// convert number in ascii to integer
			uint8_t intensity = rxbuff[len - 1] - '0';

			if ((intensity >= 0) && (intensity <= 9)) {
				power_set_intensity(device, intensity);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (response == RESPONSE_NO_RESPONSE) {
			int8_t intensity = power_get_intensity(device);

			uart_puts(BLUETOOTH_CMD_INTENSITY);
			uart_puts(": ");
			uart_putc('0' + intensity);
			uart_puts("\r\n");
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_QUOTE, len) == 0) {
		if (voice_is_playing()) {
			voice_stop_playback();
		} else {
			voice_play_quote();
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_REBOOT, len) == 0) {
		response = RESPONSE_NO_RESPONSE;

		// stop reporting of battery status
		battery_reporting_stop();

		voice_play_sound(SOUND_SLEEP_0);
		_delay_ms(1000);
		voice_play_sound(SOUND_SLEEP_2);
		voice_play_sound_no_wait(SOUND_POWER_DOWN);

		// turn off all devices
		power_off(ALL);

		// restart mcu
		wdt_reboot();
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_REPULSORS, strlen(BLUETOOTH_CMD_REPULSORS)) == 0) {
		char *param = rxbuff + strlen(BLUETOOTH_CMD_REPULSORS) + 1;

		if (len == strlen(BLUETOOTH_CMD_REPULSORS) + strlen(BLUETOOTH_PARAM_ON) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_ON, strlen(BLUETOOTH_PARAM_ON)) == 0) {
				power_on(REPULSORS_POWER);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_REPULSORS) + strlen(BLUETOOTH_PARAM_OFF) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_OFF, strlen(BLUETOOTH_PARAM_OFF)) == 0) {
				power_off(REPULSORS_POWER);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_REPULSORS)) {
			uint8_t state = power_state(REPULSORS_POWER);

			uart_puts(BLUETOOTH_CMD_REPULSORS);
			uart_puts(": ");

			if (state == POWER_ON) {
				uart_puts(BLUETOOTH_PARAM_ON);
			} else {
				uart_puts(BLUETOOTH_PARAM_OFF);
			}
			uart_puts("\r\n");

			response = RESPONSE_NO_RESPONSE;
		} else {
			response = RESPONSE_ERROR;
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_REPULSOR, strlen(BLUETOOTH_CMD_REPULSOR)) == 0) {
		char *param = rxbuff + strlen(BLUETOOTH_CMD_REPULSOR) + 1;

		if (len == strlen(BLUETOOTH_CMD_REPULSOR) + strlen(BLUETOOTH_PARAM_LEFT) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_LEFT, strlen(BLUETOOTH_PARAM_LEFT)) == 0) {
				power_blast(REPULSOR_LEFT);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_REPULSOR) + strlen(BLUETOOTH_PARAM_RIGHT) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_RIGHT, strlen(BLUETOOTH_PARAM_RIGHT)) == 0) {
				power_blast(REPULSOR_RIGHT);
			} else {
				response = RESPONSE_ERROR;
			}
		} else {
			response = RESPONSE_ERROR;
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_UNIBEAM, strlen(BLUETOOTH_CMD_UNIBEAM)) == 0) {
		char *param = rxbuff + strlen(BLUETOOTH_CMD_UNIBEAM) + 1;

		if (len == strlen(BLUETOOTH_CMD_UNIBEAM) + strlen(BLUETOOTH_PARAM_ON) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_ON, strlen(BLUETOOTH_PARAM_ON)) == 0) {
				power_on(UNIBEAM);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_UNIBEAM) + strlen(BLUETOOTH_PARAM_OFF) + 1) {
			if (strncmp(param, BLUETOOTH_PARAM_OFF, strlen(BLUETOOTH_PARAM_OFF)) == 0) {
				power_off(UNIBEAM);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_UNIBEAM)) {
			uint8_t state = power_state(UNIBEAM);

			uart_puts(BLUETOOTH_CMD_UNIBEAM);
			uart_puts(": ");

			if (state == POWER_ON) {
				uart_puts(BLUETOOTH_PARAM_ON);
			} else {
				uart_puts(BLUETOOTH_PARAM_OFF);
			}
			uart_puts("\r\n");

			response = RESPONSE_NO_RESPONSE;
		} else {
			response = RESPONSE_ERROR;
		}
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_VERSION, len) == 0) {
		uart_puts(BLUETOOTH_RESPONSE_VERSION);
		uart_puts("\r\n");
		response = RESPONSE_NO_RESPONSE;
	} else if (strncmp(rxbuff, BLUETOOTH_CMD_VOLUME, strlen(BLUETOOTH_CMD_VOLUME)) == 0) {
		if (len == strlen(BLUETOOTH_CMD_VOLUME) + 2) {
			// convert number in ascii to integer
			uint8_t volume = rxbuff[len - 1] - '0';

			if ((volume >= 0) && (volume <= 7)) {
				voice_set_volume(SOUND_VOLUME_0 + volume);
			} else {
				response = RESPONSE_ERROR;
			}
		} else if (len == strlen(BLUETOOTH_CMD_VOLUME)) {
			uint8_t volume = voice_get_volume() - SOUND_VOLUME_0;

			uart_puts(BLUETOOTH_CMD_VOLUME);
			uart_puts(": ");
			uart_putc('0' + volume);
			uart_puts("\r\n");

			response = RESPONSE_NO_RESPONSE;
		} else {
			response = RESPONSE_ERROR;
		}
	} else {
		response = RESPONSE_ERROR;
	}

	if (response == RESPONSE_OK) {
		uart_puts(BLUETOOTH_RESPONSE_OK);
		uart_puts("\r\n");
	} else if (response == RESPONSE_ERROR) {
		uart_puts(BLUETOOTH_RESPONSE_ERROR);
		uart_puts("\r\n");
	}

	if (echo) {
		uart_puts(BLUETOOTH_PROMPT);
	}
}