locked
Any have have the idea of WaveOutOpen() function ??? plz.. RRS feed

  • Question

  • i have problem in WaveOutOpen() function;
    when i call this function it create a thread in my program,
    which not destroyed until main() return/exit;
    How i should destroy this thread ???

    Thursday, July 10, 2008 7:48 AM

Answers

All replies

  • Try calling waveOutClose.

     

    - Mike

     

    Thursday, July 10, 2008 11:10 PM
  • Actually,  In my programmed two thread is created one thread by WaveOutOpen()
    and second thread by WaveOutWrite(), but WaveOutClose() destroyed only WaveOutWrite() thread  & return
    "(MMRESULT)MMSYSERR_NOERROR", & WaveOutWrite() thread remain there, i checked this in debugger by running line by line & noting the address of the threads as they created... , i have attached my code plz. see it,



    #include <windows.h>
    #include <mmsystem.h>
    #include <stdio.h>
    #include <mmreg.h>
    #include<sys/stat.h>
    #include<sys/types.h>


    HWAVEOUT hWaveOut;


    int main()
    {
       
        WAVEFORMATEX *wfx1, wfx; 
        wfx1 = new WAVEFORMATEX;
       

       
        wfx1->nSamplesPerSec = 44100; 
        wfx1->wBitsPerSample = 16;    
        wfx1->nChannels      = 2;     
        wfx1->cbSize          = 0;
        wfx1->wFormatTag      = WAVE_FORMAT_PCM;
        wfx1->nBlockAlign     = 4;
        wfx1->nAvgBytesPerSec = wfx1->nBlockAlign * wfx1->nSamplesPerSec;


        FILE *hAndle;
       
       
       
        if( (hAndle = fopen("al05_44_2.mp4.raw","rb"))==NULL)
                printf("unable to open the *.raw file \n");
        else
                printf("file is open \n");



      
       
        char *buffer;
        buffer = new char[4096];
           
        DWORD number = 1;
        int Count = 0;
        WAVEHDR whdr;



        whdr.dwFlags = 0;
        whdr.dwLoops = 5;
        whdr.dwBufferLength = 4096;
        whdr.lpData = buffer;
       
       



        MMRESULT Pheader,Uheader,OutWrite,Wclose;


        if(waveOutOpen(&hWaveOut, WAVE_MAPPER, wfx1, 0,0, CALLBACK_NULL) == MMSYSERR_NOERROR)
                    printf("The Wave Mapper device was opened successfully!\n");
          

       
        free(wfx1);
       


        while(number != 0)
        {
           
            printf("Count %d",Count);
            Count++;
            number = fread(buffer, sizeof(char), 4096, hAndle);
            printf("Numer reads is %d \n",number);
      



            Pheader = waveOutPrepareHeader(hWaveOut, &whdr,sizeof(WAVEHDR));
            switch(Pheader)
            {

                case MMSYSERR_NOERROR:
                    break;


                case MMSYSERR_INVALHANDLE:
                    printf(" Specified device handle is invalid \n");
                    break;


                case MMSYSERR_NODRIVER:
                    printf(" No device driver is present \n");
                    break;


                case MMSYSERR_NOMEM:
                    printf(" No Memory \n");
                    break;


                default :
                    printf(" Unknown error \n");
                   
            }




           
           
           



            OutWrite = waveOutWrite(hWaveOut, &whdr, sizeof(WAVEHDR));
            switch(OutWrite)
                {

                    case MMSYSERR_NOERROR:
                        break;


                    case MMSYSERR_INVALHANDLE:
                        printf(" Specified device handle is invalid \n");
                        break;


                    case MMSYSERR_NODRIVER:
                        printf(" No device driver is present \n");
                        break;


                    case MMSYSERR_NOMEM:
                        printf(" Unable to allocate or lock memory \n");
                        break;


                    case WAVERR_UNPREPARED:
                        printf(" Wave header is Unprepared \n");
                        break;


                    default :
                        printf(" Unknown error \n");
                       
                }
            
       
           
            //unsigned int start = GetTickCount();
            while((Uheader = waveOutUnprepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR))) == WAVERR_STILLPLAYING)
                    Sleep(1);
            //printf("Time taken %d\n",GetTickCount()-start);
            switch(Uheader)
                    {
                        case WAVERR_STILLPLAYING:
                            printf(" Still playing ?? \n");
                            break;


                        case MMSYSERR_NOERROR:
                            break;


                        case MMSYSERR_INVALHANDLE:
                            printf(" Specified device handle is invalid \n");
                            break;


                        case MMSYSERR_NODRIVER:
                            printf(" No device driver is present \n");
                            break;


                        case MMSYSERR_NOMEM:
                            printf(" Unable to allocate or lock memory \n");
                            break;


                        default :
                            printf(" Unknown error \n");
                           
                    }
           


           
           
            memset( buffer, 0,4096 );
               

        }

               
           
           
        waveOutReset(hWaveOut);
        Wclose = waveOutClose(hWaveOut);
        if(Wclose != MMSYSERR_NOERROR)
            printf("waveoutclose() error");
       
       
       
        free(buffer);
        getchar();
        fclose(hAndle);
        return 0; 
       
    }



    Friday, July 11, 2008 5:37 AM