Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Audio sample instance playing slow on windows

This thread is locked; no one can reply to it. rss feed Print
Audio sample instance playing slow on windows
LĂ­sias de Castro
Member #14,882
January 2013
avatar

When I load any audio with allegro sample it plays a kind of slow.
If I load it with any media player and compare the audio, I can clearly see
It is not playing at the same velocity.

Here is how I load my audio.

#if defined(ALLEGRO_PLUGIN_ACTIVATED)
static ALLEGRO_SAMPLE_INSTANCE * allegro_sample_instance_set(ALLEGRO_SAMPLE * data, ALLEGRO_MIXER * mixer, float gain, float pan, float speed,
ALLEGRO_PLAYMODE mode) {
if (!data) return NULL;
ALLEGRO_SAMPLE_INSTANCE * instance = al_create_sample_instance (data);
al_attach_sample_instance_to_mixer (instance, mixer);
al_set_sample_instance_gain (instance, gain);
al_set_sample_instance_pan (instance, pan);
al_set_sample_instance_speed (instance, speed);
al_set_sample_instance_playmode (instance, mode);
return instance;
}
#endif

AUDIO_OF_CALL AudioSet * AUDIO_OF_TYPE audio_of_load(char * path, int id, int channel, AUDIO_TYPE type) {
if (machine_fail ()) return NULL;
AudioSet * p = (AudioSet *) malloc (sizeof(AudioSet));
audio_of_zero (p);
switch (type) {
case AUDIO_TYPE_MUSIC: {
switch (machine->up->audio) {
case SYSTEM_AUDIO_ALLEGRO: {
#if defined(ALLEGRO_PLUGIN_ACTIVATED)
p->channel = channel == 1 || channel == 2 ? channel : 2;
p->data = path ? al_load_audio_stream ((const char*) path, p->channel, (unsigned int) machine->audio->chunk_size) : NULL;
p->id = id;
p->type = type;
p->loop = AUDIO_PLAYBACK_ONCE;
if (p->data) {
al_set_audio_stream_speed (p->data, machine->audio->speed);
}
//al_get_audio_stream_length_secs(p->data);
#endif
}
break;
}
}
break;
case AUDIO_TYPE_EFFECT: {
switch (machine->up->audio) {
case SYSTEM_AUDIO_ALLEGRO: {
#if defined(ALLEGRO_PLUGIN_ACTIVATED)
void * data = path ? al_load_sample ((const char*) path) : NULL;
p->id = id;
p->channel = channel == 1 || channel == 2 ? channel : 2;
p->type = type;
p->loop = AUDIO_PLAYBACK_ONCE;
p->data = allegro_sample_instance_set (data, ALL_PLUGIN(machine)->mixer, machine->audio->volume->effect, machine->audio->balance,
machine->audio->speed, allegro_plugin_playmode (p->loop));
if (!p->data) {
free (p);
p = NULL;
}
if (data) al_destroy_sample (data);
#endif
}
break;
}
}
break;
}
if (p && !p->data) {
free (p);
p = NULL;
}
return p;
}

STATUS static audio_of_play(AudioSet * p) {
if (machine_fail () || !p) return Off;
switch (p->type) {
case AUDIO_TYPE_MUSIC: {
switch (machine->up->audio) {
case SYSTEM_AUDIO_ALLEGRO: {
#if defined (ALLEGRO_PLUGIN_ACTIVATED)
return !p->data || !al_attach_audio_stream_to_mixer (p->data, al_get_default_mixer ())
|| !al_set_audio_stream_gain (p->data, machine->audio->volume->music) || !al_set_audio_stream_playing (p->data, true) ? Off : On;
#endif
}
break;
}
}
break;
case AUDIO_TYPE_EFFECT: {
switch (machine->up->audio) {
case SYSTEM_AUDIO_ALLEGRO: {
#if defined (ALLEGRO_PLUGIN_ACTIVATED)
return !p->data || !al_set_sample_instance_playing (p->data, true) ? Off : On;
#endif
}
break;
}
}
break;
default:
return Off;
}
return On;
}

Am I doing something wrong?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The speed of the sample is affected by the sample speed. Make sure it is set to 1.0.

Attach the affected sound file and tell me what you used to play it.

Code belongs in <code>code goes here</code> tags. It makes it much easier to read.

Go to: