Strange error message in stream

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Strange error message in stream

Post by Newbie »

I have a strange error message :

*** ASSERTION FAILURE ***
Assertion "streams[(hnd)].initted" failed at snd_stream.c:537 in `snd_stream_volume'

i tried to simply change volume of a stream.

Thanks for your help.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Strange error message in stream

Post by bogglez »

I haven't used that API before, but it seems like you have used an invalid handle or not initialized that handle properly.

Compare your code with the sound examples, e.g.
$KOS_BASE/examples/dreamcast/cpp/modplug_test,
sound/ghettoplay-vorbis,
sound/hello-mp3 and
sound/hello-ogg.
Spoiler!

Code: Select all

#include <kos.h>
#include <modplug/stdafx.h>
#include <modplug/sndfile.h>

uint16 sound_buffer[65536] = {0};
CSoundFile *soundfile;

void *mod_callback(snd_stream_hnd_t hnd, int len, int * actual) {
    int res;

    res = soundfile->Read(sound_buffer, len) * 4/*samplesize*/;

    //printf("res: %i, len: %i\n",res,len);
    if(res < len) {
        soundfile->SetCurrentPos(0);
        soundfile->Read(&sound_buffer[res], len - res);
    }

    *actual = len;

    return sound_buffer;
}

extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);

int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;
    uint8 *mod_buffer;
    uint32 hnd;
    char filename[] = "/rd/test.s3m";

    printf("modplug_test beginning\n");

    snd_stream_init();

    hnd = fs_open(filename, O_RDONLY);

    if(!hnd) {
        printf("Error reading %s\n", filename);
        return 0;
    }

    printf("Filesize: %i\n", fs_total(hnd));
    mod_buffer = (uint8 *)malloc(fs_total(hnd));

    if(!mod_buffer) {
        printf("Not enough memory\n");
        return 0;
    }

    printf("Memory allocated\n");

    if(fs_read(hnd, mod_buffer, fs_total(hnd)) != fs_total(hnd)) {
        printf("Read error\n");
        free(mod_buffer);
        return 0;
    }

    printf("File read\n");

    soundfile = new CSoundFile;

    if(!soundfile) {
        printf("Not enough memory\n");
        free(mod_buffer);
        return 0;
    }

    printf("CSoundFile created\n");

    if(!soundfile->Create(mod_buffer, fs_total(hnd))) {
        printf("Mod not loaded\n");
        free(mod_buffer);
        delete soundfile;
        return 0;
    }

    printf("Mod loaded\n");
    soundfile->SetWaveConfig(44100, 16, 2);
    printf("Type: %i\n", soundfile->GetType());
    printf("Title: %s\n", soundfile->GetTitle());

    /*fs_close(hnd);
    free(mod_buffer);*/

    snd_stream_hnd_t shnd = snd_stream_alloc(mod_callback, SND_STREAM_BUFFER_MAX);
    snd_stream_start(shnd, 44100, 1);

    while(1) {
        /* Check key status */
        cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

        if(cont) {
            state = (cont_state_t *)maple_dev_status(cont);

            if(state && state->buttons & CONT_START)
                break;
        }

        snd_stream_poll(shnd);

        timer_spin_sleep(10);
    }

    delete soundfile;

    snd_stream_destroy(shnd);

    snd_stream_shutdown();

    return 0;
}
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: Strange error message in stream

Post by Newbie »

You're right, the handle i use is invalid in a special case in my code.
In fact, i have forgotten to reset it's value when stream is stopped
by user input so the second round it try to play it crashes ..

Thanks, i fix it.
Post Reply