DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/snd_pc98/sound/getsnd/getsnd.c
00001 #include    "np2glue.h"
00002 //#include      "compiler.h"
00003 #include        "getsnd.h"
00004 
00005 
00006 GETSND getsnd_create(void *datptr, UINT datsize) {
00007 
00008         _GETSND         snd;
00009         BOOL            r;
00010         UINT            size;
00011         UINT            blkwork;
00012         GETSND          ret;
00013 
00014         ZeroMemory(&snd, sizeof(snd));
00015         r = getwave_open(&snd, (UINT8 *)datptr, datsize);
00016 #if defined(SUPPORT_MP3)
00017         if (r == FAILURE) {
00018                 r = getmp3_open(&snd, (UINT8 *)datptr, datsize);
00019         }
00020 #endif
00021 #if defined(SUPPORT_OGG)
00022         if (r == FAILURE) {
00023                 r = getogg_open(&snd, (UINT8 *)datptr, datsize);
00024         }
00025 #endif
00026         if (r == FAILURE) {
00027                 goto gscre_err0;
00028         }
00029 
00030         blkwork = (snd.bit + 7) >> 3;
00031         blkwork *= snd.channels;
00032         blkwork *= snd.blocksamples;
00033         size = blkwork + snd.blocksize;
00034 
00035         ret = (GETSND)_MALLOC(sizeof(_GETSND) + size, "GETSND");
00036         if (ret == NULL) {
00037                 goto gscre_err1;
00038         }
00039         ZeroMemory(ret + 1, size);
00040 
00041         // ワークとか設定。
00042         snd.buffer = (UINT8 *)(ret + 1);
00043         snd.work = snd.buffer + blkwork;
00044         *ret = snd;
00045         if (getsnd_setmixproc(ret, snd.samplingrate, snd.channels) != SUCCESS) {
00046                 TRACEOUT(("err"));
00047                 goto gscre_err1;
00048         }
00049         return(ret);
00050 
00051 gscre_err1:
00052         if (snd.decend) {
00053                 (*snd.decend)(&snd);
00054         }
00055 
00056 gscre_err0:
00057         return(NULL);
00058 }
00059 
00060 
00061 void getsnd_destroy(GETSND snd) {
00062 
00063         if (snd == NULL) {
00064                 goto gsdes_end;
00065         }
00066         if (snd->decend) {
00067                 (*snd->decend)(snd);
00068         }
00069         _MFREE(snd);
00070 
00071 gsdes_end:
00072         return;
00073 }
00074 
00075 UINT getsnd_getpcmbyleng(GETSND snd, void *pcm, UINT leng) {
00076 
00077         UINT8   *pcmp;
00078         UINT8   *pcmterm;
00079 
00080         if (snd == NULL) {
00081                 goto gsgpl_err;
00082         }
00083 
00084         pcmp = (UINT8 *)pcm;
00085         pcmterm = pcmp + leng;
00086         while(pcmp < pcmterm) {
00087                 if (snd->remain != 0) {
00088                         pcmp = (UINT8 *)(*snd->cnv)(snd, pcmp, pcmterm);
00089                 }
00090                 if (snd->remain == 0) {
00091                         snd->buf = snd->buffer;
00092                         snd->remain = (*snd->dec)(snd, snd->buffer);
00093                         if (snd->remain == 0) {
00094                                 break;
00095                         }
00096                 }
00097         }
00098         return((UINT)(pcmp - (UINT8 *)pcm));
00099 
00100 gsgpl_err:
00101         return(0);
00102 }
00103