#include <stdio.h>
#include "allegro5/allegro.h"
#include "allegro5/allegro_audio.h"
#include "allegro5/allegro_acodec.h"

ALLEGRO_VOICE*  voice;
ALLEGRO_MIXER*  mixer;
const char* filename;

static bool init( int argc, char ** argv );
static void quit(void);


int main(int argc, char **argv)
{
    ALLEGRO_AUDIO_STREAM* stream;

    if (!init(argc, argv))
        goto err;

    stream = al_load_audio_stream(filename, 4, 2048);
    if (stream) {
        printf("destroy the newly created stream...\n");
        al_destroy_audio_stream(stream);
        printf("done!\n");
    }
err:
    quit();
    return 0;
}





static bool init( int argc, char ** argv ) 
{
    if(argc < 2) {
        fprintf(stderr, "Usage: %s {audio_files}\n", argv[0]);
        return false;
    }
    filename = argv[1];

    if (!al_init()) {
        fprintf(stderr, "Could not init Allegro.\n");
        return false;
    }

    al_init_acodec_addon();

    if (!al_install_audio()) {
        fprintf(stderr, "Could not init sound!\n");
        return false;
    }

    voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16,
        ALLEGRO_CHANNEL_CONF_2);
    if (!voice) {
        fprintf(stderr, "Could not create ALLEGRO_VOICE.\n");
        return false;
    }

    mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
        ALLEGRO_CHANNEL_CONF_2);
    if (!mixer) {
        fprintf(stderr, "Could not create ALLEGRO_MIXER.\n");
        return false;
    }
    fprintf(stderr, "Mixer created.\n");

    if (!al_attach_mixer_to_voice(mixer, voice)) {
        fprintf(stderr, "al_attach_mixer_to_voice failed.\n");
        return false;
    }
    return true;
}

static void quit(void)
{
    al_destroy_mixer(mixer);
    al_destroy_voice(voice);
    al_uninstall_audio();
}




