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); } }
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); } }
AL_DUH_PLAYER *al_start_duh(DUH *duh, int n_channels, long pos, float volume, long bufsize, int freq) { AL_DUH_PLAYER *dp; /* This restriction is imposed by Allegro. */ ASSERT(n_channels > 0); ASSERT(n_channels <= 2); if (!duh) return NULL; dp = malloc(sizeof(*dp)); if (!dp) return NULL; dp->flags = ADP_PLAYING; dp->bufsize = bufsize; dp->freq = freq; dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128); if (!dp->stream) { free(dp); return NULL; } voice_set_priority(dp->stream->voice, 255); dp->sigrenderer = duh_start_sigrenderer(duh, 0, n_channels, pos); if (!dp->sigrenderer) { stop_audio_stream(dp->stream); free(dp); return NULL; } dp->volume = volume; dp->silentcount = 0; return dp; }
AL_DUH_PLAYER *al_duh_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer, float volume, long bufsize, int freq) { AL_DUH_PLAYER *dp; int n_channels; if (!sigrenderer) return NULL; dp = malloc(sizeof(*dp)); if (!dp) return NULL; n_channels = duh_sigrenderer_get_n_channels(sigrenderer); /* This restriction is imposed by Allegro. */ ASSERT(n_channels > 0); ASSERT(n_channels <= 2); dp->flags = ADP_PLAYING; dp->bufsize = bufsize; dp->freq = freq; dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128); if (!dp->stream) { free(dp); return NULL; } voice_set_priority(dp->stream->voice, 255); dp->sigrenderer = sigrenderer; dp->volume = volume; dp->silentcount = 0; return dp; }
int _apeg_audio_reset_parameters(APEG_LAYER *layer) { int buffer_padding; _apeg_audio_close(layer); if(layer->stream.audio.freq <= 0) { snprintf(apeg_error, sizeof(apeg_error), "Illegal audio frequency (%dhz)", layer->stream.audio.freq); return APEG_ERROR; } if(layer->stream.audio.channels <= 0) { snprintf(apeg_error, sizeof(apeg_error), "Illegal channel count (%d)", layer->stream.audio.channels); return APEG_ERROR; } buffer_padding = 0; #ifndef DISABLE_MPEG_AUDIO if(layer->stream.audio.layer == 3) buffer_padding = (128>>layer->stream.audio.down_sample) * SSLIMIT * layer->stream.audio.channels; if(layer->stream.audio.layer == 2) buffer_padding = (128>>layer->stream.audio.down_sample) * 3 * layer->stream.audio.channels; if(layer->stream.audio.layer == 1) buffer_padding = (128>>layer->stream.audio.down_sample) * SCALE_BLOCK * layer->stream.audio.channels; #endif if(layer->audio.callback_init) { int channels = layer->stream.audio.channels; int freq = layer->stream.audio.freq; int ret; ret = layer->audio.callback_init((APEG_STREAM*)layer, &channels, &freq, layer->audio.callback_arg); if(ret < 0) { snprintf(apeg_error, sizeof(apeg_error), "Audio callback init failed (code: %d)", ret); return APEG_ERROR; } if(channels > layer->stream.audio.channels || channels <= 0 || freq <= 0) { snprintf(apeg_error, sizeof(apeg_error), "Illegal audio mode requested (%dhz %d channels)", freq, channels); return APEG_ERROR; } if(ret > 0) layer->audio.bufsize = (ret+255)&(~255); free(layer->audio.pcm.samples); layer->audio.pcm.samples = malloc(layer->audio.bufsize+buffer_padding); if(!layer->audio.pcm.samples) { snprintf(apeg_error, sizeof(apeg_error), "Error allocating %d bytes for audio buffer", layer->audio.bufsize+buffer_padding); return APEG_ERROR; } if(channels == 1 && layer->stream.audio.channels > 1) layer->stream.audio.down_channel = TRUE; layer->stream.audio.channels = channels; layer->stream.audio.freq = freq; layer->audio.samples_per_update = layer->audio.bufsize / 2 / layer->stream.audio.channels; layer->audio.last_pos = -1; layer->audio.pos = -layer->audio.samples_per_update*2; return APEG_OK; } free(layer->audio.pcm.samples); layer->audio.pcm.samples = malloc(layer->audio.bufsize+buffer_padding); if(!layer->audio.pcm.samples) { snprintf(apeg_error, sizeof(apeg_error), "Error allocating %d bytes for audio buffer", layer->audio.bufsize+buffer_padding); return APEG_ERROR; } if(layer->stream.audio.channels > 2) layer->stream.audio.channels = 2; layer->audio.samples_per_update = layer->audio.bufsize / 2 / layer->stream.audio.channels; /* Start the audio stream */ layer->audio.stream = create_sample(16, layer->stream.audio.channels != 1, layer->stream.audio.freq, layer->audio.samples_per_update*2); if(layer->audio.stream) { int i; for(i = 0;i < layer->audio.bufsize;++i) ((short*)layer->audio.stream->data)[i] = 0x8000; } else { snprintf(apeg_error, sizeof(apeg_error), "Error starting stream playback"); return APEG_ERROR; } layer->audio.voice = play_sample(layer->audio.stream, 255, 127, 1000, TRUE); voice_set_priority(layer->audio.voice, 255); layer->audio.last_pos = -1; layer->audio.pos = -layer->audio.samples_per_update*2; _apeg_audio_set_speed_multiple(layer, layer->multiple); return APEG_OK; }
void al_duh_set_priority(AL_DUH_PLAYER *dp, int priority) { if (dp && dp->sigrenderer) voice_set_priority(dp->stream->voice, priority); }