Changeset 2935 for trunk/src


Ignore:
Timestamp:
Feb 27, 2000, 9:29:47 PM (25 years ago)
Author:
sandervl
Message:

Implemented waveOutGetPosition

Location:
trunk/src/winmm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/winmm/dwaveout.cpp

    r2812 r2935  
    1 /* $Id: dwaveout.cpp,v 1.14 2000-02-17 14:09:30 sandervl Exp $ */
     1/* $Id: dwaveout.cpp,v 1.15 2000-02-27 20:29:46 sandervl Exp $ */
    22
    33/*
     
    3131#include "dwaveout.h"
    3232
    33 #define DBG_LOCALLOG    DBG_dwaveout
     33#define DBG_LOCALLOG    DBG_dwaveout
    3434#include "dbglocal.h"
    3535
     
    6565
    6666   if(!ulError)
    67         callback((ULONG)this, WOM_OPEN, dwInstance, 0, 0);
     67    callback((ULONG)this, WOM_OPEN, dwInstance, 0, 0);
    6868}
    6969/******************************************************************************/
     
    7676
    7777   if(!ulError)
    78         PostMessageA(hwndCallback, WOM_OPEN, 0, 0);
     78    PostMessageA(hwndCallback, WOM_OPEN, 0, 0);
    7979}
    8080/******************************************************************************/
     
    157157   DeviceId = AmpOpenParms.usDeviceID;
    158158   if(rc) {
    159 #ifdef DEBUG
    160     WriteLog("MCI_OPEN failed\n");
    161 #endif
     159    dprintf(("MCI_OPEN failed\n"));
    162160    mciError(rc);
    163161    ulError = MMSYSERR_NODRIVER;
     
    169167                        (PVOID)&GenericParms, 0);
    170168    if(rc) {
    171 #ifdef DEBUG
    172         WriteLog("MCI_ACQUIREDEVICE failed\n");
    173 #endif
     169        dprintf(("MCI_ACQUIREDEVICE failed\n"));
    174170        mciError(rc);
    175171        ulError = MMSYSERR_NOTENABLED;
     
    209205
    210206   if(!ulError) {
    211         // Generic parameters
    212         GenericParms.hwndCallback = 0;   //hwndFrame
    213 
    214         // Stop the playback.
    215         mciSendCommand(DeviceId, MCI_STOP,MCI_WAIT, (PVOID)&GenericParms,0);
    216 
    217         mciSendCommand(DeviceId,
     207    // Generic parameters
     208    GenericParms.hwndCallback = 0;   //hwndFrame
     209
     210    // Stop the playback.
     211    mciSendCommand(DeviceId, MCI_STOP,MCI_WAIT, (PVOID)&GenericParms,0);
     212
     213    mciSendCommand(DeviceId,
    218214                  MCI_BUFFER,
    219215                  MCI_WAIT | MCI_DEALLOCATE_MEMORY,
     
    221217                  0);
    222218
    223         // Generic parameters
    224         GenericParms.hwndCallback = 0;   //hwndFrame
    225 
    226         // Close the device
    227         mciSendCommand(DeviceId, MCI_CLOSE, MCI_WAIT, (PVOID)&GenericParms, 0);
     219    // Generic parameters
     220    GenericParms.hwndCallback = 0;   //hwndFrame
     221
     222    // Close the device
     223    mciSendCommand(DeviceId, MCI_CLOSE, MCI_WAIT, (PVOID)&GenericParms, 0);
    228224   }
    229225
    230226   if(wmutex)
    231         wmutex->enter(VMUTEX_WAIT_FOREVER);
     227        wmutex->enter(VMUTEX_WAIT_FOREVER);
    232228
    233229   State = STATE_STOPPED;
    234230
    235231   if(waveout == this) {
    236     waveout = this->next;
     232        waveout = this->next;
    237233   }
    238234   else {
    239     DartWaveOut *dwave = waveout;
    240 
    241     while(dwave->next != this) {
    242         dwave = dwave->next;
    243     }
    244     dwave->next = this->next;
     235        DartWaveOut *dwave = waveout;
     236
     237        while(dwave->next != this) {
     238            dwave = dwave->next;
     239        }
     240        dwave->next = this->next;
    245241   }
    246242   if(wmutex)
    247     wmutex->leave();
     243        wmutex->leave();
    248244
    249245   if(!ulError) {
    250         if(mthdCallback) {
    251                 callback((ULONG)this, WOM_CLOSE, dwInstance, 0, 0);
    252         }
    253         else
    254         if(hwndCallback)
    255                 PostMessageA(hwndCallback, WOM_CLOSE, 0, 0);
     246        if(mthdCallback) {
     247            callback((ULONG)this, WOM_CLOSE, dwInstance, 0, 0);
     248        }
     249        else
     250        if(hwndCallback)
     251            PostMessageA(hwndCallback, WOM_CLOSE, 0, 0);
    256252   }
    257253
    258254   if(wmutex)
    259     delete wmutex;
     255        delete wmutex;
    260256
    261257   if(MixBuffer)
    262     free(MixBuffer);
     258        free(MixBuffer);
    263259   if(MixSetupParms)
    264     free(MixSetupParms);
     260        free(MixSetupParms);
    265261   if(BufferParms)
    266     free(BufferParms);
     262        free(BufferParms);
    267263}
    268264/******************************************************************************/
     
    292288
    293289   if(rc) {
    294         return 0; //no devices present
     290        return 0; //no devices present
    295291   }
    296292
     
    311307 int i, buflength;
    312308
    313   if(fMixerSetup == FALSE) {
    314 #ifdef DEBUG
    315     WriteLog("device acquired\n");
    316 #endif
    317     /* Set the MixSetupParms data structure to match the loaded file.
    318      * This is a global that is used to setup the mixer.
    319      */
    320     memset(MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) );
    321 
    322     MixSetupParms->ulBitsPerSample = BitsPerSample;
    323     MixSetupParms->ulSamplesPerSec = SampleRate;
    324     MixSetupParms->ulFormatTag     = MCI_WAVE_FORMAT_PCM;
    325     MixSetupParms->ulChannels      = nChannels;
    326 
    327 #ifdef DEBUG
    328     WriteLog("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels);
    329 #endif
     309  if(fMixerSetup == FALSE)
     310  {
     311        dprintf(("device acquired\n"));
     312        /* Set the MixSetupParms data structure to match the loaded file.
     313         * This is a global that is used to setup the mixer.
     314         */
     315        memset(MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) );
     316
     317        MixSetupParms->ulBitsPerSample = BitsPerSample;
     318        MixSetupParms->ulSamplesPerSec = SampleRate;
     319        MixSetupParms->ulFormatTag     = MCI_WAVE_FORMAT_PCM;
     320        MixSetupParms->ulChannels      = nChannels;
     321
     322        dprintf(("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels));
    330323
    331324        /* Setup the mixer for playback of wave data
    332325         */
    333     MixSetupParms->ulFormatMode = MCI_PLAY;
     326        MixSetupParms->ulFormatMode = MCI_PLAY;
    334327        MixSetupParms->ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
    335328        MixSetupParms->pmixEvent    = WaveOutHandler;
     
    341334                            0);
    342335
    343     if ( rc != MCIERR_SUCCESS ) {
    344         mciError(rc);
    345         mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
    346                    (PVOID)&GenericParms, 0);
    347         return(MMSYSERR_NOTSUPPORTED);
    348     }
     336        if ( rc != MCIERR_SUCCESS ) {
     337            mciError(rc);
     338            mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
     339                           (PVOID)&GenericParms, 0);
     340            return(MMSYSERR_NOTSUPPORTED);
     341        }
    349342
    350343        /*
     
    352345         * device buffers from the Amp-Mixer
    353346         */
    354 #ifdef DEBUG
    355     WriteLog("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength);
    356 #endif
     347        dprintf(("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength));
     348
    357349#if 1
    358     ulBufSize = pwh->dwBufferLength/2;
     350        ulBufSize = pwh->dwBufferLength/2;
    359351#else
    360     if(pwh->dwBufferLength >= 512 && pwh->dwBufferLength <= 1024)
    361         ulBufSize = pwh->dwBufferLength;
    362     else    ulBufSize = 1024;
    363 #endif
    364 
    365     MixSetupParms->ulBufferSize = ulBufSize;
     352        if(pwh->dwBufferLength >= 512 && pwh->dwBufferLength <= 1024)
     353                ulBufSize = pwh->dwBufferLength;
     354        else    ulBufSize = 1024;
     355#endif
     356
     357        MixSetupParms->ulBufferSize = ulBufSize;
    366358
    367359        BufferParms->ulNumBuffers = PREFILLBUF_DART;
     
    370362
    371363        for(i=0;i<PREFILLBUF_DART;i++) {
    372         MixBuffer[i].ulUserParm = (ULONG)this;
     364            MixBuffer[i].ulUserParm = (ULONG)this;
    373365        }
    374366
     
    380372
    381373        if(ULONG_LOWD(rc) != MCIERR_SUCCESS) {
    382         mciError(rc);
    383         mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
    384                    (PVOID)&GenericParms, 0);
    385         return(MMSYSERR_NOTSUPPORTED);
    386     }
    387 
    388     wmutex->enter(VMUTEX_WAIT_FOREVER);
    389     fMixerSetup = TRUE;
    390 
    391     curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;
     374            mciError(rc);
     375            mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
     376                          (PVOID)&GenericParms, 0);
     377            return(MMSYSERR_NOTSUPPORTED);
     378        }
     379
     380        wmutex->enter(VMUTEX_WAIT_FOREVER);
     381        fMixerSetup = TRUE;
     382
     383        curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;
    392384
    393385        for(i=0;i<PREFILLBUF_DART;i++) {
    394         memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength);
    395     }
    396 #ifdef DEBUG
    397     WriteLog("Dart opened, bufsize = %d\n", MixBuffer[i].ulBufferLength);
    398 #endif
    399 
    400     wavehdr     = pwh;
    401     curhdr      = pwh;
    402     pwh->lpNext = NULL;
    403 
    404     while(TRUE) {
    405         buflength = min((ULONG)MixBuffer[curFillBuf].ulBufferLength - curPlayPos,
    406                 (ULONG)wavehdr->dwBufferLength - curFillPos);
    407 #ifdef DEBUG
    408         WriteLog("Copying %d data; curPlayPos = %d curFillPos = %d\n", buflength, curPlayPos, curFillPos);
    409 #endif
    410         memcpy((char *)MixBuffer[curFillBuf].pBuffer + curPlayPos,
    411                wavehdr->lpData + curFillPos,
    412                buflength);
    413 
    414         curPlayPos  += buflength;
    415         curFillPos += buflength;
    416         if(curFillPos == wavehdr->dwBufferLength) {
    417 #ifdef DEBUG
    418             WriteLog("Processed first win32 buffer\n");
    419 #endif
    420             curFillPos        = 0;
    421             wavehdr->dwFlags |= WHDR_DONE;
    422             curhdr            = NULL;
    423         }
    424         if(curPlayPos == MixBuffer[curPlayBuf].ulBufferLength) {
    425             if(++curPlayBuf == PREFILLBUF_DART) {
    426                 curPlayBuf = 0;
     386            memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength);
     387        }
     388        dprintf(("Dart opened, bufsize = %d\n", MixBuffer[i].ulBufferLength));
     389
     390        wavehdr     = pwh;
     391        curhdr      = pwh;
     392        pwh->lpNext = NULL;
     393
     394        while(TRUE) {
     395            buflength = min((ULONG)MixBuffer[curFillBuf].ulBufferLength - curPlayPos,
     396                            (ULONG)wavehdr->dwBufferLength - curFillPos);
     397            dprintf(("Copying %d data; curPlayPos = %d curFillPos = %d\n", buflength, curPlayPos, curFillPos));
     398
     399            memcpy((char *)MixBuffer[curFillBuf].pBuffer + curPlayPos,
     400                   wavehdr->lpData + curFillPos,
     401                   buflength);
     402
     403            curPlayPos  += buflength;
     404            curFillPos += buflength;
     405            if(curFillPos == wavehdr->dwBufferLength) {
     406                dprintf(("Processed first win32 buffer\n"));
     407                curFillPos        = 0;
     408                wavehdr->dwFlags |= WHDR_DONE;
     409                curhdr            = NULL;
     410            }
     411            if(curPlayPos == MixBuffer[curPlayBuf].ulBufferLength) {
     412                if(++curPlayBuf == PREFILLBUF_DART) {
     413                    curPlayBuf = 0;
     414                    break;
     415                }
     416                curPlayPos = 0;
     417            }
     418            if(curFillPos == 0)
    427419                break;
     420        }
     421        dprintf(("MixSetupParms = %X\n", MixSetupParms));
     422        State = STATE_PLAYING;
     423        wmutex->leave();
     424
     425        MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle,
     426                                 MixBuffer,
     427                                 PREFILLBUF_DART);
     428        dprintf(("Dart playing\n"));
     429  }
     430  else
     431  {
     432        wmutex->enter(VMUTEX_WAIT_FOREVER);
     433        pwh->lpNext   = NULL;
     434        if(wavehdr) {
     435            WAVEHDR *chdr = wavehdr;
     436            while(chdr->lpNext) {
     437                chdr = chdr->lpNext;
    428438            }
    429             curPlayPos = 0;
    430         }
    431         if(curFillPos == 0)
    432             break;
    433     }
    434 #ifdef DEBUG
    435     WriteLog("MixSetupParms = %X\n", MixSetupParms);
    436 #endif
    437     State = STATE_PLAYING;
    438     wmutex->leave();
    439 
    440     MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle,
    441                              MixBuffer,
    442                              PREFILLBUF_DART);
    443 #ifdef DEBUG
    444     WriteLog("Dart playing\n");
    445 #endif
    446   }
    447   else {
    448     wmutex->enter(VMUTEX_WAIT_FOREVER);
    449     pwh->lpNext   = NULL;
    450     if(wavehdr) {
    451         WAVEHDR *chdr = wavehdr;
    452         while(chdr->lpNext) {
    453             chdr = chdr->lpNext;
    454         }
    455         chdr->lpNext = pwh;
    456     }
    457     else    wavehdr = pwh;
    458     wmutex->leave();
    459     if(State != STATE_PLAYING) {//continue playback
    460         restart();
    461     }
     439            chdr->lpNext = pwh;
     440        }
     441        else    wavehdr = pwh;
     442        wmutex->leave();
     443        if(State != STATE_PLAYING) {//continue playback
     444            restart();
     445        }
    462446  }
    463447
     
    471455
    472456  if(State != STATE_PLAYING)
    473     return(MMSYSERR_HANDLEBUSY);
     457        return(MMSYSERR_NOERROR);
    474458
    475459  wmutex->enter(VMUTEX_WAIT_FOREVER);
     
    492476  dprintf(("DartWaveOut::reset %s", (State == STATE_PLAYING) ? "playing" : "stopped"));
    493477  if(State != STATE_PLAYING)
    494     return(MMSYSERR_HANDLEBUSY);
     478        return(MMSYSERR_HANDLEBUSY);
    495479
    496480  memset(&Params, 0, sizeof(Params));
     
    499483  mciSendCommand(DeviceId, MCI_STOP, MCI_WAIT, (PVOID)&Params, 0);
    500484
    501 #ifdef DEBUG
    502   WriteLog("Nr of threads blocked on mutex = %d\n", wmutex->getNrBlocked());
    503 #endif
     485  dprintf(("Nr of threads blocked on mutex = %d\n", wmutex->getNrBlocked()));
    504486
    505487  wmutex->enter(VMUTEX_WAIT_FOREVER);
     
    510492        callback((ULONG)this, WOM_DONE, dwInstance, wavehdr->dwUser, (ULONG)wavehdr);
    511493    }
    512     else
     494    else {
    513495        if(hwndCallback)
    514         PostMessageA(hwndCallback, WOM_DONE, wavehdr->dwUser, (ULONG)wavehdr);
    515 
     496            PostMessageA(hwndCallback, WOM_DONE, wavehdr->dwUser, (ULONG)wavehdr);
     497    }
    516498    wmutex->enter(VMUTEX_WAIT_FOREVER);
    517499    wavehdr = wavehdr->lpNext;
     
    527509MMRESULT DartWaveOut::restart()
    528510{
    529   dprintf(("DartWaveOut::restart"));
    530   wmutex->enter(VMUTEX_WAIT_FOREVER);
    531   State = STATE_PLAYING;
    532   wmutex->leave();
    533   MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle,
    534                           &MixBuffer[curPlayBuf],
    535                           PREFILLBUF_DART);
    536   return(MMSYSERR_NOERROR);
     511    dprintf(("DartWaveOut::restart"));
     512    wmutex->enter(VMUTEX_WAIT_FOREVER);
     513    State = STATE_PLAYING;
     514    wmutex->leave();
     515    MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle,
     516                             &MixBuffer[curPlayBuf],
     517                             PREFILLBUF_DART);
     518    return(MMSYSERR_NOERROR);
     519}
     520/******************************************************************************/
     521/******************************************************************************/
     522ULONG DartWaveOut::getPosition()
     523{
     524 MCI_STATUS_PARMS mciStatus = {0};
     525 ULONG rc, nrbytes;
     526
     527    if(State != STATE_PLAYING)
     528        return 0;
     529
     530    mciStatus.ulItem = MCI_STATUS_POSITION;
     531    rc = mciSendCommand(DeviceId, MCI_STATUS, MCI_STATUS_ITEM|MCI_WAIT, (PVOID)&mciStatus, 0);
     532    if((rc & 0xFFFF) == MCIERR_SUCCESS) {
     533        nrbytes = (mciStatus.ulReturn * getAvgBytesPerSecond())/1000;
     534        return nrbytes;;
     535    }
     536    mciError(rc);
     537    return 0xFFFFFFFF;
    537538}
    538539/******************************************************************************/
     
    560561                       0);
    561562  if (rc != 0) {
    562     return(FALSE);
     563        return(FALSE);
    563564  }
    564565  DeviceId = mciOpenParms.usDeviceID;
     
    591592                      0);
    592593  if((rc & 0xFFFF) != MCIERR_SUCCESS) {
    593         mciError(rc);
    594         winrc = FALSE;
    595   }
    596   else  winrc = TRUE;
     594        mciError(rc);
     595        winrc = FALSE;
     596  }
     597  else  winrc = TRUE;
    597598
    598599  // Close the device
     
    608609
    609610  mciGetErrorString(ulError, szError, sizeof(szError));
    610   WriteLog("WINMM: DartWaveOut: %s\n", szError);
     611  dprintf(("WINMM: DartWaveOut: %s\n", szError));
    611612#endif
    612613}
     
    637638
    638639#ifdef DEBUG1
    639   WriteLog("WINMM: handler %d\n", curPlayBuf);
     640  dprintf(("WINMM: handler %d\n", curPlayBuf));
    640641#endif
    641642  if(ulFlags == MIX_STREAM_ERROR) {
     
    653654    if(whdr->dwFlags & WHDR_DONE) {
    654655#ifdef DEBUG1
    655         WriteLog("WINMM: handler buf %X done\n", whdr);
     656        dprintf(("WINMM: handler buf %X done\n", whdr));
    656657#endif
    657658        whdr->dwFlags &= ~WHDR_INQUEUE;
     
    681682
    682683#ifdef DEBUG1
    683   WriteLog("WINMM: handler cur (%d,%d), fill (%d,%d)\n", curPlayBuf, curPlayPos, curFillBuf, curFillPos);
     684  dprintf(("WINMM: handler cur (%d,%d), fill (%d,%d)\n", curPlayBuf, curPlayPos, curFillBuf, curFillPos));
    684685#endif
    685686
     
    693694    curFillPos += buflength;
    694695#ifdef DEBUG1
    695     WriteLog("WINMM: copied %d bytes, cufFillPos = %d, dwBufferLength = %d\n", buflength, curFillPos, curhdr->dwBufferLength);
     696    dprintf(("WINMM: copied %d bytes, cufFillPos = %d, dwBufferLength = %d\n", buflength, curFillPos, curhdr->dwBufferLength));
    696697#endif
    697698    if(curFillPos == curhdr->dwBufferLength) {
    698699#ifdef DEBUG1
    699         WriteLog("Buffer %d done\n", curFillBuf);
     700        dprintf(("Buffer %d done\n", curFillBuf));
    700701#endif
    701702        curFillPos = 0;
     
    747748/******************************************************************************/
    748749MMRESULT DartWaveOut::setVolume(ULONG ulVol)
    749 { 
    750   ULONG ulVolR     = (((ulVol & 0xffff0000) >> 16 )*100)/0xFFFF; // Right Volume 
     750{
     751  ULONG ulVolR     = (((ulVol & 0xffff0000) >> 16 )*100)/0xFFFF; // Right Volume
    751752  ULONG ulVolL      = ((ulVol& 0x0000ffff)*100)/0xFFFF;          // Left Volume
    752753  MCI_SET_PARMS msp = {0};
     
    757758//     one channel Left or Right :-(
    758759//
    759 #ifdef GOOD_AUDIO_CARD_DRIVER 
     760#ifdef GOOD_AUDIO_CARD_DRIVER
    760761
    761762  msp.ulAudio = MCI_SET_AUDIO_LEFT;
  • trunk/src/winmm/dwaveout.h

    r2286 r2935  
    1 /* $Id: dwaveout.h,v 1.7 1999-12-31 13:55:51 sandervl Exp $ */
     1/* $Id: dwaveout.h,v 1.8 2000-02-27 20:29:47 sandervl Exp $ */
    22
    33/*
     
    4242     MMRESULT restart();
    4343     MMRESULT setVolume(ULONG ulVol);
    44      ULONG    getVolume() {return volume; };
    45      int      getState() { return State; };
     44     ULONG    getVolume()               { return volume; };
     45     int      getState()                { return State; };
    4646     MMRESULT reset();
     47     ULONG    getPosition();
     48
     49     ULONG    getSampleRate()           { return SampleRate; };
     50     ULONG    getBitsPerSample()        { return BitsPerSample; };
     51     ULONG    getnumChannels()          { return nChannels; };
     52     ULONG    getAvgBytesPerSecond()    { return (BitsPerSample/8) * nChannels * SampleRate; };
    4753
    4854  static BOOL queryFormat(ULONG formatTag, ULONG nChannels,
    49               ULONG nSamplesPerSec, ULONG sampleSize);
    50 
     55                          ULONG nSamplesPerSec, ULONG sampleSize);
     56 
    5157  static BOOL find(DartWaveOut *dwave);
    5258  static int  getNumDevices();
  • trunk/src/winmm/waveout.cpp

    r2812 r2935  
    1 /* $Id: waveout.cpp,v 1.10 2000-02-17 14:09:33 sandervl Exp $ */
     1/* $Id: waveout.cpp,v 1.11 2000-02-27 20:29:47 sandervl Exp $ */
    22//#undef DEBUG
    33/*
    44 * Wave out MM apis
    55 *
    6  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
    77 *
     8 * waveOutGetPosition partly based on Wine code (dll\winmm\wineoss\audio.c)
     9 * Copyright 1994 Martin Ayotte
    810 *
    911 * Project Odin Software License can be found in LICENSE.TXT
     
    2931#include "winmm.h"
    3032
    31 #define DBG_LOCALLOG    DBG_waveout
     33#define DBG_LOCALLOG    DBG_waveout
    3234#include "dbglocal.h"
    3335
     
    98100  if(DartWaveOut::find(dwave) == TRUE)
    99101  {
    100     if(!(pwh->dwFlags & WHDR_PREPARED) || pwh->lpData == NULL)
    101       return WAVERR_UNPREPARED;
    102 
    103     if(pwh->dwFlags & WHDR_INQUEUE)
    104       return WAVERR_STILLPLAYING;
    105 
    106     pwh->dwFlags |= WHDR_INQUEUE;
    107     pwh->dwFlags &= ~WHDR_DONE;
    108 
    109     return(dwave->write(pwh, cbwh));
    110   }
    111   else
    112     return(MMSYSERR_INVALHANDLE);
     102        if(!(pwh->dwFlags & WHDR_PREPARED) || pwh->lpData == NULL)
     103            return WAVERR_UNPREPARED;
     104
     105        if(pwh->dwFlags & WHDR_INQUEUE)
     106            return WAVERR_STILLPLAYING;
     107
     108        pwh->dwFlags |= WHDR_INQUEUE;
     109        pwh->dwFlags &= ~WHDR_DONE;
     110
     111        return(dwave->write(pwh, cbwh));
     112  }
     113  else  return(MMSYSERR_INVALHANDLE);
    113114}
    114115/******************************************************************************/
     
    120121
    121122  if(DartWaveOut::find(dwave) == TRUE)
    122     return(dwave->reset());
    123   else
    124     return(MMSYSERR_INVALHANDLE);
     123        return(dwave->reset());
     124  else  return(MMSYSERR_INVALHANDLE);
    125125}
    126126/******************************************************************************/
     
    133133  dprintf(("WINMM:waveOutBreakLoop (implemented as reset) %X\n", hwaveout));
    134134  if(DartWaveOut::find(dwave) == TRUE)
    135     return(dwave->reset());
    136   else
    137     return(MMSYSERR_INVALHANDLE);
     135        return(dwave->reset());
     136  else  return(MMSYSERR_INVALHANDLE);
    138137}
    139138/******************************************************************************/
     
    146145  if(DartWaveOut::find(dwave) == TRUE)
    147146  {
    148     if(dwave->getState() == STATE_PLAYING)
    149       return(WAVERR_STILLPLAYING);
    150 
    151     delete dwave;
    152     return(MMSYSERR_NOERROR);
    153   }
    154   else
    155     return(MMSYSERR_INVALHANDLE);
     147        if(dwave->getState() == STATE_PLAYING)
     148            return(WAVERR_STILLPLAYING);
     149
     150        delete dwave;
     151        return(MMSYSERR_NOERROR);
     152  }
     153  else  return(MMSYSERR_INVALHANDLE);
    156154}
    157155/******************************************************************************/
     
    163161
    164162  if(DartWaveOut::find(dwave) == TRUE)
    165     return(dwave->pause());
    166   else
    167     return(MMSYSERR_INVALHANDLE);
     163        return(dwave->pause());
     164  else  return(MMSYSERR_INVALHANDLE);
    168165}
    169166/******************************************************************************/
     
    175172
    176173  if(DartWaveOut::find(dwave) == TRUE)
    177     return(dwave->restart());
    178   else
    179     return(MMSYSERR_INVALHANDLE);
     174        return(dwave->restart());
     175  else  return(MMSYSERR_INVALHANDLE);
    180176}
    181177/******************************************************************************/
     
    190186  if(DartWaveOut::find(dwave) == TRUE)
    191187  {
    192     if(pwh->dwFlags & WHDR_INQUEUE)
    193       return WAVERR_STILLPLAYING;
    194 
    195     pwh->dwFlags |= WHDR_PREPARED;
    196     pwh->dwFlags &= ~WHDR_DONE;
    197     pwh->lpNext   = NULL;
    198     return(MMSYSERR_NOERROR);
    199   }
    200   else
    201     return(MMSYSERR_INVALHANDLE);
     188        if(pwh->dwFlags & WHDR_INQUEUE)
     189            return WAVERR_STILLPLAYING;
     190
     191        pwh->dwFlags |= WHDR_PREPARED;
     192        pwh->dwFlags &= ~WHDR_DONE;
     193        pwh->lpNext   = NULL;
     194        return(MMSYSERR_NOERROR);
     195  }
     196  else  return(MMSYSERR_INVALHANDLE);
    202197}
    203198/******************************************************************************/
     
    212207  if(DartWaveOut::find(dwave) == TRUE)
    213208  {
    214     if(pwh->dwFlags & WHDR_INQUEUE)
    215       return WAVERR_STILLPLAYING;
    216 
    217     pwh->dwFlags &= ~WHDR_PREPARED;
    218     pwh->dwFlags |= WHDR_DONE;
    219    return(MMSYSERR_NOERROR);
    220   }
    221   else
    222    return(MMSYSERR_INVALHANDLE);
     209        if(pwh->dwFlags & WHDR_INQUEUE)
     210            return WAVERR_STILLPLAYING;
     211
     212        pwh->dwFlags &= ~WHDR_PREPARED;
     213        pwh->dwFlags |= WHDR_DONE;
     214        return(MMSYSERR_NOERROR);
     215  }
     216  else  return(MMSYSERR_INVALHANDLE);
    223217}
    224218/******************************************************************************/
     
    230224{
    231225  DartWaveOut *dwave = (DartWaveOut *)hwo;
    232   dprintf(("WINMM:waveOutGetPosition - not implemented\n"));
    233   if(DartWaveOut::find(dwave) == TRUE)
    234     return(MMSYSERR_NOERROR);
    235   else
    236     return(MMSYSERR_INVALHANDLE);
     226
     227  if(pmmt == NULL)     
     228        return MMSYSERR_INVALPARAM;
     229
     230  if(DartWaveOut::find(dwave) == TRUE)
     231  {
     232   ULONG position;
     233
     234        position = dwave->getPosition();
     235        if(position == -1) {
     236            return MMSYSERR_HANDLEBUSY; //todo correct error value
     237        }
     238        switch (pmmt->wType) {
     239        case TIME_BYTES:
     240                pmmt->u.cb = position;
     241                break;
     242        case TIME_SAMPLES:
     243                pmmt->u.sample = position * 8 / dwave->getBitsPerSample();
     244                break;
     245        case TIME_SMPTE:
     246        {
     247                ULONG timeval = position / (dwave->getAvgBytesPerSecond() / 1000);
     248                pmmt->u.smpte.hour = timeval / 108000;
     249                timeval -= pmmt->u.smpte.hour * 108000;
     250                pmmt->u.smpte.min = timeval / 1800;
     251                timeval -= pmmt->u.smpte.min * 1800;
     252                pmmt->u.smpte.sec = timeval / 30;
     253                timeval -= pmmt->u.smpte.sec * 30;
     254                pmmt->u.smpte.frame = timeval;
     255                pmmt->u.smpte.fps = 30;
     256                break;
     257            }
     258        default:
     259                dprintf(("waveOutGetPosition: Format %d not supported ! use TIME_MS !\n", pmmt->wType));
     260                pmmt->wType = TIME_MS;
     261        case TIME_MS:
     262                pmmt->u.ms = position / (dwave->getAvgBytesPerSecond() / 1000);
     263                dprintf(("WINMM:waveOutGetPosition: TIME_MS pos=%d ms=%d time=%d", position, pmmt->u.ms, GetCurrentTime()));
     264                break;
     265        }
     266        return MMSYSERR_NOERROR;
     267  }
     268  else  return(MMSYSERR_INVALHANDLE);
    237269}
    238270/******************************************************************************/
     
    243275              UINT, cbwoc)
    244276{
    245   dprintf(("WINMM:waveOutGetDevCapsA"));
    246 
    247277  if(DartWaveOut::getNumDevices() == 0) {
    248         memset(pwoc, 0, sizeof(*pwoc));
    249         return MMSYSERR_NODRIVER;
     278        memset(pwoc, 0, sizeof(*pwoc));
     279        return MMSYSERR_NODRIVER;
    250280  }
    251281
     
    278308
    279309  if(DartWaveOut::getNumDevices() == 0) {
    280         memset(pwoc, 0, sizeof(*pwoc));
    281         return MMSYSERR_NODRIVER;
     310        memset(pwoc, 0, sizeof(*pwoc));
     311        return MMSYSERR_NODRIVER;
    282312  }
    283313  // we have to fill in this thing
     
    313343{
    314344  char * theMsg = getWinmmMsg( wError );
    315   if ( theMsg )
    316     strncpy( lpText, theMsg, cchText );
    317   else
    318   {
    319     char errMsg[100];
    320     sprintf( errMsg, "Unknown error number %d", wError );
    321     strncpy( lpText, errMsg, cchText );
     345  if(theMsg) {
     346        strncpy( lpText, theMsg, cchText );
     347  }
     348  else
     349  {
     350        char errMsg[100];
     351        sprintf( errMsg, "Unknown error number %d", wError );
     352        strncpy( lpText, errMsg, cchText );
    322353  }
    323354  return MMSYSERR_NOERROR;
    324355}
    325 
     356/******************************************************************************/
     357/******************************************************************************/
    326358ODINFUNCTION3(MMRESULT, waveOutGetErrorTextW,
    327359              MMRESULT, wError,
     
    330362{
    331363  char * theMsg = getWinmmMsg( wError );
    332   if ( theMsg )
    333     AsciiToUnicode( theMsg, lpText );
    334   else
    335   {
    336     char errMsg[100];
    337     sprintf( errMsg, "Unknown error number %d", wError );
    338     AsciiToUnicode( errMsg, lpText );
     364  if(theMsg) {
     365        AsciiToUnicode( theMsg, lpText );
     366  }
     367  else
     368  {
     369        char errMsg[100];
     370        sprintf( errMsg, "Unknown error number %d", wError );
     371        AsciiToUnicode( errMsg, lpText );
    339372  }
    340373  return MMSYSERR_NOERROR;
    341374}
    342 
     375/******************************************************************************/
     376/******************************************************************************/
    343377ODINFUNCTION2(MMRESULT, waveOutGetID,
    344378              HWAVEOUT, hwo,
     
    348382  if(DartWaveOut::find(dwave) == TRUE)
    349383  {
    350     *puDeviceID = 1;
    351     return MMSYSERR_NOERROR;
    352   }
    353   else
    354     return(MMSYSERR_INVALHANDLE);
    355 }
    356 
     384        *puDeviceID = 1;
     385        return MMSYSERR_NOERROR;
     386  }
     387  else  return(MMSYSERR_INVALHANDLE);
     388}
     389/******************************************************************************/
     390/******************************************************************************/
    357391ODINFUNCTION2(MMRESULT, waveOutGetPitch,
    358392              HWAVEOUT, hwo,
     
    361395  DartWaveOut *dwave = (DartWaveOut *)hwo;
    362396  if(DartWaveOut::find(dwave) == TRUE)
    363     return MMSYSERR_NOTSUPPORTED;
    364   else
    365     return(MMSYSERR_INVALHANDLE);
    366 }
    367 
     397        return MMSYSERR_NOTSUPPORTED;
     398  else  return(MMSYSERR_INVALHANDLE);
     399}
     400/******************************************************************************/
     401/******************************************************************************/
    368402ODINFUNCTION2(MMRESULT, waveOutSetPitch,
    369403              HWAVEOUT, hwo,
     
    372406  DartWaveOut *dwave = (DartWaveOut *)hwo;
    373407  if(DartWaveOut::find(dwave) == TRUE)
    374     return MMSYSERR_NOTSUPPORTED;
    375   else
    376     return(MMSYSERR_INVALHANDLE);
    377 }
    378 
     408        return MMSYSERR_NOTSUPPORTED;
     409  else  return(MMSYSERR_INVALHANDLE);
     410}
     411/******************************************************************************/
     412/******************************************************************************/
    379413ODINFUNCTION2(MMRESULT, waveOutGetVolume,
    380414              HWAVEOUT, hwo,
     
    384418  if(DartWaveOut::find(dwave) == TRUE)
    385419  {
    386     if (pdwVolume!=NULL)
    387       *pdwVolume=dwave->getVolume();
    388     return MMSYSERR_NOERROR;   
     420        if(pdwVolume!=NULL)
     421            *pdwVolume=dwave->getVolume();
     422        return MMSYSERR_NOERROR;
    389423  }
    390424  else
     
    392426//    return(MMSYSERR_INVALHANDLE);
    393427}
    394 
     428/******************************************************************************/
     429/******************************************************************************/
    395430ODINFUNCTION2(MMRESULT, waveOutSetVolume,
    396431              HWAVEOUT, hwo,
     
    406441//    return(MMSYSERR_INVALHANDLE);
    407442}
    408 
     443/******************************************************************************/
     444/******************************************************************************/
    409445ODINFUNCTION2(MMRESULT, waveOutGetPlaybackRate,
    410446              HWAVEOUT, hwo,
     
    414450  if(DartWaveOut::find(dwave) == TRUE)
    415451  {
    416     return MMSYSERR_NOTSUPPORTED;
    417   }
    418   else
    419     return(MMSYSERR_INVALHANDLE);
    420 }
    421 
     452        return MMSYSERR_NOTSUPPORTED;
     453  }
     454  else  return(MMSYSERR_INVALHANDLE);
     455}
     456/******************************************************************************/
     457/******************************************************************************/
    422458ODINFUNCTION2(MMRESULT, waveOutSetPlaybackRate,
    423459              HWAVEOUT, hwo,
     
    427463  if(DartWaveOut::find(dwave) == TRUE)
    428464  {
    429     return MMSYSERR_NOTSUPPORTED;
    430   }
    431   else
    432     return(MMSYSERR_INVALHANDLE);
    433 }
    434 
     465        return MMSYSERR_NOTSUPPORTED;
     466  }
     467  else  return(MMSYSERR_INVALHANDLE);
     468}
     469/******************************************************************************/
     470/******************************************************************************/
    435471ODINFUNCTION4(MMRESULT, waveOutMessage,
    436472              HWAVEOUT, hwo,
     
    447483    return(MMSYSERR_INVALHANDLE);
    448484}
    449 
    450 
     485/******************************************************************************/
     486/******************************************************************************/
     487
     488
Note: See TracChangeset for help on using the changeset viewer.