コード例 #1
0
ファイル: SC_MIDAS.C プロジェクト: en-vorobiov/mpxplay
static long MIDAS_bufspace(struct mpxplay_audioout_info_s *aui)
{
 if(!midashandle)
  MIDAS_start(aui);
 if(midashandle){
  unsigned int bufbytes=MIDASgetStreamBytesBuffered(midashandle);
  if(aui->card_dmasize>=bufbytes)
   return (aui->card_dmasize-bufbytes);
 }
 return 0;
}
コード例 #2
0
ファイル: RAINCORE.C プロジェクト: StepanHrbek/RAIN
static int soundGetStatus(struct Sound *s)
{
    int result=0;
    if (s->playhandle)
    switch (s->type)
    {
        case Module:
            {
            MIDASplayStatus status;
            MIDASgetPlayStatus((MIDASmodulePlayHandle)s->playhandle,&status);
            result=s->loop?1:1-status.songLoopCount;
            }
            break;
        case Sample:
            result=MIDASgetSamplePlayStatus((MIDASsamplePlayHandle)s->playhandle);
            break;
        case Stream:
            {
            int buffered=MIDASgetStreamBytesBuffered((MIDASstreamHandle)s->playhandle);
            result=1;
            #define BUFLEN 4608
            if ( buffered+2*BUFLEN<=s->bufferbytes )
            {
                unsigned char buf[BUFLEN];
                int decoded=MP3read((void *)s->datahandle,s->loop,buf,BUFLEN);
                if ( !decoded ) result=buffered/8;
                MIDASfeedStreamData((MIDASstreamHandle)s->playhandle,buf,decoded,1/*feedAll*/);
            }
            }
            break;
#ifdef DEBUG
        default:
            errAdd(" Get status: Unknown type.");
#endif
    }
    MIDASreportErr();
    return result;
}
コード例 #3
0
ファイル: thread.c プロジェクト: cdrr/MAME_hack
int main(int argc, char *argv[])
{
    char        oldTitle[256];
    unsigned    i;
/*    char        *foo;*/

    MIDASstartup();
    
    /* Keep the test somewhat reproducable: */
    srand(17);

    setbuf(stdout, NULL);

    puts("MIDAS stream test\n\n"
         "The sound output may sound strange, but the program should _NOT_ "
         "crash");

    puts("Trying to get window handle");

    /* Hack - try to figure out our console window's window handle: */
    GetConsoleTitle(oldTitle, 255);
    SetConsoleTitle("DirectSound TestiKala");
    Sleep(250);
    EnumWindows(&EnumWindowsProc, (LPARAM) NULL);
    SetConsoleTitle(oldTitle);

    printf("%P, %u\n", consoleHwnd, sizeof(HWND));

    if ( consoleHwnd == NULL )
        Error("Couldn't find window handle");

    puts("Trying to use DirectSound primary buffer mode");
    MIDASsetOption(MIDAS_OPTION_DSOUND_HWND, (DWORD) consoleHwnd);
    MIDASsetOption(MIDAS_OPTION_DSOUND_MODE, MIDAS_DSOUND_PRIMARY);

    /* Initialize MIDAS and start background playback: */
    if ( !MIDASinit() )
        MIDASerror();
/*    if ( !MIDASstartBackgroundPlay(0) )
        MIDASerror();*/

#ifdef _MSC_VER   
    if ( _beginthread(PollThread, 4096, NULL) == -1 )
        Error("Unable to create polling thread");
#else    
    if ( _beginthread(PollThread, NULL, 4096, NULL) == -1 )
        Error("Unable to create polling thread");
#endif    

    /* Open enough channels: */
    if ( !MIDASopenChannels(32) )
        MIDASerror();

    /* Allocate some channels for automatic effects: */
    if ( !MIDASallocAutoEffectChannels(12) )
        MIDASerror();

    /* Load the initial module and sample: */
    puts("Loading modules");
    if ( (module1 = MIDASloadModule(MODULE1)) == NULL )
        MIDASerror();
    if ( (module2 = MIDASloadModule(MODULE2)) == NULL )
        MIDASerror();
    puts("Loading samples");
    if ( (sample1 = MIDASloadRawSample(SAMPLE1, MIDAS_SAMPLE_8BIT_MONO, FALSE))
         == 0 )
        MIDASerror();
    if ( (sample2 = MIDASloadRawSample(SAMPLE2, MIDAS_SAMPLE_16BIT_MONO,
                                       FALSE)) == 0 )
         MIDASerror();

    /* Swap stuff out: */
    /*
    puts("Touching a LOT of memory");
    if ( (foo = malloc(64*1024*1024)) == NULL )
        Error("Out of memory");
    for ( i = 0; i < (64*1024*1024); i++ )
        foo[i] = (i & 255);
        */

    puts("Playing stream");
    if ( (stream1 = MIDASplayStreamWaveFile(STREAM1, 500, TRUE)) == NULL )
        MIDASerror();

    /* Play the module: */
    puts("Playing module");
    if ( (playHandle1 = MIDASplayModule(module1, TRUE)) == 0 )
        MIDASerror();

    /* Play effects for a while: */
    puts("Playing samples");
    for ( i = 0; i < 1000; i++ )
    {
        switch ( rand() & 8 )
        {
            case 0:
                if ( MIDASplaySample(sample1, MIDAS_CHANNEL_AUTO, 0, 22050 +
                                     ((rand() % 30000) - 15000), rand() % 24,
                                     (rand() % 128) - 64) == 0 )
                    MIDASerror();
                break;

            case 8:
                if ( MIDASplaySample(sample2, MIDAS_CHANNEL_AUTO, 0, 22050 +
                                     ((rand() % 30000) - 15000), rand() % 24,
                                     (rand() % 128) - 64) == 0 )
                    MIDASerror();
                break;
        }
                
        Sleep(rand() % 27);
        if ( (rand() % 8) < 2 )
            RandomPriority();

        printf("%u\n", MIDASgetStreamBytesBuffered(stream1));
    }

    puts("Stopping");

    stopPoll = 1;
    while ( stopPoll )
        Sleep(10);

    if ( !MIDASstopStream(stream1) )
        MIDASerror();
    /* Stop playback and uninitialize MIDAS: */
/*    if ( !MIDAScloseChannels() )
        MIDASerror();*/
/*    if ( !MIDASstopBackgroundPlay() )
        MIDASerror();*/
    if ( !MIDASclose() )
        MIDASerror();

    printf("Poll total %u, min %u, max %u, avg %u, count %u\n", pollTotal,
           pollMin, pollMax, pollTotal/(pollCount-100), pollCount);

    return 0;
}