#include #include #include #include #include "pokesound.h" #include "cli.h" /* -------------------------------------------------------------- */ int do_message(char *texte) { int len, foo; fprintf(stderr, ">>> %s ( '%s' )\n", __func__, texte); len = strlen(texte) + 7; for (foo=0; foo>> %s ( '%s' )\n", __func__, texte); buffname = strtok(texte, " \t"); fprintf(stderr, " buffname = %s\n", buffname); /* some checks in the symbol table */ /* is there free room in the table */ #if 0 if ((foo=symb_count_free(0)) < 1) { fprintf(stderr, "ERR in %s: symbols table is full\n", __func__); exit(1); } fprintf(stderr, " %d free symbols\n", foo); #endif /* oh, may be I know this symbol ? */ foo = symb_index(buffname); fprintf(stderr, " index of '%s' is %d\n", buffname, foo); if (foo >= 0) { fprintf(stderr, "ERR symbol '%s' already defined\n", buffname); exit(2); } /* * get the remaining of the command line */ cptr = strtok(NULL, " \t"); fprintf(stderr, " [%s]\n", cptr); if (1 != sscanf(cptr, "%f", &duration)) { fprintf(stderr, "%s floating point error\n", __func__); exit(2); } fprintf(stderr, " duration = %.2f s.\n", duration); /* * build a soundbuffer */ get_context(&contexte); print_context(&contexte); sndbuff = create_soundbuff(&contexte, duration); fprintf(stderr, " sndbuff at %p\n", sndbuff); foo = proto_fade_in (sndbuff, 0.78); foo = proto_fade_out (sndbuff, 4.55); /* * and put it in the symbol table */ foo = symb_insert(buffname, SYM_T_BUFFER, sndbuff); fprintf(stderr, " sym insert -> %d\n", foo); return -1; } /* -------------------------------------------------------------- */ int do_export(char *texte) { char *buffname, *filename; SndPk_sndbuff *addr; int foo; fprintf(stderr, ">>> %s ( '%s' )\n", __func__, texte); buffname = strtok(texte, " \t"); filename = strtok(NULL, " \t"); fprintf(stderr, " writing '%s' to '%s'\n", buffname, filename); addr = symb_get_addr(buffname); fprintf(stderr, " ---> %p\n", addr); dump_line("in do_export", (char *)addr, 20); foo = write_soundbuff(filename, addr); if (foo) { fprintf(stderr, "ERR %s = %d\n", __func__, foo); exit(1); } return 0; } /* -------------------------------------------------------------- */ int do_load_file(char *texte) { char *buffname, *filename; SndPk_sndbuff *buffer; int foo; fprintf(stderr, ">>> %s ( '%s' )\n", __func__, texte); buffname = strtok(texte, " \t"); filename = strtok(NULL, " \t"); if (NULL == filename) { fprintf(stderr, "FATAL: fname is null in %s\n", __func__); exit(1); } fprintf(stderr, " loading '%s' in '%s'\n", filename, buffname); buffer = read_wave_from_file(filename); if (NULL==buffer) { fprintf(stderr, "Oups in %s\n", __func__); return -2; } /* oh, may be I know this symbol ? */ foo = symb_index(buffname); fprintf(stderr, " index of '%s' is %d\n", buffname, foo); if (foo >= 0) { fprintf(stderr, "ERR symbol '%s' already defined\n", buffname); exit(2); } foo = symb_insert(buffname, SYM_T_BUFFER, buffer); if (foo) { fprintf(stderr, "error %d in symb insert\n", foo); return foo; } return 0; } /* -------------------------------------------------------------- */ int do_pokewave(char *texte) { char *to_name, *from_name, *cptr; SndPk_sndbuff *to_buff, *from_buff; float fval; int foo; fprintf(stderr, ">>> %s ( '%s' )\n", __func__, texte); to_name = strtok(texte, " \t"); from_name = strtok(NULL, " \t"); fprintf(stderr, " poking '%s' to '%s'\n", from_name, to_name); to_buff = symb_get_addr(to_name); from_buff = symb_get_addr(from_name); fprintf(stderr, " %p -> %p\n", from_buff, to_buff); cptr = strtok(NULL, " \t"); if ( 1 != sscanf(cptr, "%f", &fval)) { return -1; } foo = poke_un_fragment(from_buff, to_buff, fval); if (foo) { fprintf(stderr, "%s: err %d while poking\n", __func__, foo); return foo; } return 0; } /* -------------------------------------------------------------- */ void dump_line(char *titre, char *ligne, int combien) { int foo; unsigned char *ptr; fprintf(stderr, " Dump: %s\n", titre); ptr = (unsigned char *)ligne; for (foo=0; foo