Exemplo n.º 1
0
void MmeGrabber::shutdown()
{
	MMRESULT s;

	/* fprintf(stderr, "vic: Called MmeGrabber::shutdown\n"); */
	if (!running_)
		return;

	wantgrab_ = 0;
	running_ = 0;
	s = videoStreamReset(handle_);
	(void)mme_error(s, "couldn't reset mme stream");
	while(outstanding_) {
		mmeWaitForCallbacks();
		mmeProcessCallbacks();
	}
	s = videoStreamUnprepareHeader(handle_, vh_, sizeof(*vh_));
	(void)mme_error(s, "couldn't unprepare mme video header");
	s = videoStreamFini(handle_);
	(void)mme_error(s, "couldn't shutdown mme stream");
	running_ = 0;


	mmeFreeBuffer(vh_->lpData);
}
Exemplo n.º 2
0
static void
MME_CloseDevice(_THIS)
{
    if (this->hidden != NULL) {
        MMRESULT result;

        if (this->hidden->mixbuf) {
            result = mmeFreeBuffer(this->hidden->mixbuf);
            if (result != MMSYSERR_NOERROR)
                SetMMerror("mmeFreeBuffer", result);
            this->hidden->mixbuf = NULL;
        }

        if (this->hidden->shm) {
            if (this->hidden->shm->sound) {
                result = waveOutClose(this->hidden->shm->sound);
                if (result != MMSYSERR_NOERROR)
                    SetMMerror("waveOutClose()", result);
                mmeProcessCallbacks();
            }
            result = mmeFreeMem(this->hidden->shm);
            if (result != MMSYSERR_NOERROR)
                SetMMerror("mmeFreeMem()", result);
            this->hidden->shm = NULL;
        }

        SDL_free(this->hidden);
        this->hidden = NULL;
    }
}
Exemplo n.º 3
0
static void MME_WaitAudio(_THIS)
{
    while ( inUse[next_buffer] ) {
	mmeWaitForCallbacks();
	mmeProcessCallbacks();
    }
}
Exemplo n.º 4
0
static void
MME_WaitDevice(_THIS)
{
    while (inUse[this->hidden->next_buffer]) {
        mmeWaitForCallbacks();
        mmeProcessCallbacks();
    }
}
Exemplo n.º 5
0
static void MME_WaitDone(_THIS)
{
    MMRESULT result;
    int i;

    if ( shm->sound ) {
	for (i = 0; i < NUM_BUFFERS; i++)
	    while ( inUse[i] ) {
		mmeWaitForCallbacks();
		mmeProcessCallbacks();
	    }
	result = waveOutReset(shm->sound);
	if ( result != MMSYSERR_NOERROR )
	    SetMMerror("waveOutReset()", result);
	mmeProcessCallbacks();
    }
}
Exemplo n.º 6
0
void MmeGrabber::dispatch(int mask)
{
    /*    fprintf(stderr, "vic: Called MmeGrabber::dispatch\n"); */
    while (mmeCheckForCallbacks())
      mmeProcessCallbacks();
    if (wantgrab_ && running_ ) {
	wantgrab_ = 0;
	mmeMaster->grab();
    }
}
Exemplo n.º 7
0
Arquivo: sound.c Projeto: bernds/UAE
__inline__ void check_sound_buffers (void)
{
    if (((char *)sndbufpt - (char *)mme_sndbufpt) < sndbufsize)
	return 0;
    if (mmeCheckForCallbacks())
	mmeProcessCallbacks();
    if (mme_free_bufs >= SOUND_NUMBUF)
	return 0;
    WaveHeader->lpData = (LPSTR)mme_sndbufpt;
    WaveHeader->dwBufferLength = ((char *)sndbufpt - (char *)mme_sndbufpt);
    mme_nextbuf++;
    if (mme_nextbuf == SOUND_NUMBUF) {
	mme_sndbufpt = sndbuffer;
	mme_nextbuf = 0;
    }
    else mme_sndbufpt += bytes_per_sample*sndbufsize*2;
    sndbufpt = mme_sndbufpt;
    if (waveOutWrite(mme_handle, WaveHeader,
		     sizeof(WAVEHDR)) == MMSYSERR_NOERROR)
	mme_free_bufs++;
    return 1;
}
Exemplo n.º 8
0
static void MME_CloseAudio(_THIS)
{
    MMRESULT result;

    if ( mixbuf ) {
	result = mmeFreeBuffer(mixbuf);
	if (result != MMSYSERR_NOERROR )
	    SetMMerror("mmeFreeBuffer", result);
	mixbuf = NULL;
    }

    if ( shm ) {
	if ( shm->sound ) {
	    result = waveOutClose(shm->sound);
	    if (result != MMSYSERR_NOERROR )
		SetMMerror("waveOutClose()", result);
	    mmeProcessCallbacks();
	}
	result = mmeFreeMem(shm);
	if (result != MMSYSERR_NOERROR )
	    SetMMerror("mmeFreeMem()", result);
	shm = NULL;
    }
}
Exemplo n.º 9
0
void play_sound_mmov( char* FileName , int verbose )
{
    HWAVEOUT hwaveout;
    MMRESULT status;
    int mask1;
    int allDone;

    static int uDeviceId = WAVE_MAPPER;
    static int AdpcmBitsPerSample = 16;
    static int AdpcmSamplesPerBlock = 0;
    static int sizeBuffers = 0;
    static int msBuffers = 0;
    static int numBuffers = 4;
    static struct mmov_soundformat sound_format =
    {
	{
	    DEFAULT_ENCODING,
	    DEFAULT_NCHANNELS,
	    DEFAULT_SAMPLERATE,
    	    0,
	    0,
	    DEFAULT_SAMPLESIZE,
	    NUM_DATA
	}, {
	    0, 0, 0, 0, 0, 0, 0, 0,
	    0, 0, 0, 0, 0, 0, 0, 0,
	    0, 0, 0, 0, 0, 0, 0, 0,
	    0, 0, 0, 0, 0, 0, 0, 0
	}
    };

   Verbose = verbose;
   play_state = MMOV_START;

    /* Open the Wave In file */
    if (mmcWaveInFileOpen (FileName, &sound_format.wave, &wavefilestatus) != 0)
    {
	mmcVerboseDisplay(Verbose,"Error opening input file");
	mmov_cleanup();
       return;
    }

    if ( sound_format.wave.wFormatTag == WAVE_FORMAT_PCM)
      mmcVerboseDisplay(Verbose,"PCM file");
    else if ( sound_format.wave.wFormatTag == WAVE_FORMAT_MULAW)
      mmcVerboseDisplay(Verbose,"mu-law file");
    else if ( sound_format.wave.wFormatTag == WAVE_FORMAT_IMA_ADPCM)
      mmcVerboseDisplay(Verbose,"IMA file");
    else
      mmcVerboseDisplay(Verbose,"Unknown sound format %d",
				sound_format.wave.wFormatTag);
    mmcVerboseDisplay(Verbose,"Channels = %d ",  sound_format.wave.nChannels );
    mmcVerboseDisplay(Verbose,"Sample rate = %d",
		      sound_format.wave.nSamplesPerSec);
    mmcVerboseDisplay(Verbose,
		      "Sample size = %d", sound_format.wave.wBitsPerSample );

    if( sound_format.wave.nChannels == 0)
      sound_format.wave.nChannels = DEFAULT_NCHANNELS;
    if( sound_format.wave.nSamplesPerSec == 0)
      sound_format.wave.nSamplesPerSec = DEFAULT_SAMPLERATE;
    if( sound_format.wave.wBitsPerSample == 0)
      sound_format.wave.wBitsPerSample = DEFAULT_SAMPLESIZE;

    if ( sound_format.wave.wFormatTag == WAVE_FORMAT_IMA_ADPCM ) {
      AdpcmSamplesPerBlock = *(Uint16 *)(&sound_format.extra_data[0]);
    }

    if ( ( sound_format.wave.wFormatTag == WAVE_FORMAT_PCM) ||
	( sound_format.wave.wFormatTag == WAVE_FORMAT_MULAW) ) {
      mask1 = WAVE_FORMAT_FIX_BLOCK_ALIGN | WAVE_FORMAT_FIX_AVG_BPS;
      mmcWaveFormatFix((LPPCMWAVEFORMAT)(&sound_format), mask1 );
    }

    if ( sound_format.wave.wFormatTag == WAVE_FORMAT_IMA_ADPCM) {
      sizeBuffers = sound_format.wave.nBlockAlign;
      msBuffers = sizeBuffers * 1000 /
	  (DIV_ROUND_UP_(AdpcmBitsPerSample,8) *
	   sound_format.wave.nSamplesPerSec *
	   sound_format.wave.nChannels);


    } else {
      if (!msBuffers && !sizeBuffers)
	msBuffers = 1000/numBuffers;

      if (msBuffers)
	sizeBuffers =
	  ROUND_UP_(DIV_ROUND_UP_(msBuffers *
				DIV_ROUND_UP_( sound_format.wave.wBitsPerSample,
					      8) *
				sound_format.wave.nSamplesPerSec *
				sound_format.wave.nChannels,1000), BUFFER_PAD);
      else
	{
	  sizeBuffers = ROUND_UP_(sizeBuffers, BUFFER_PAD);
	  msBuffers = sizeBuffers * 1000 /
	    (DIV_ROUND_UP_( sound_format.wave.wBitsPerSample,8) *
	     sound_format.wave.nSamplesPerSec *
	     sound_format.wave.nChannels);
	}
    }


    mmcVerboseDisplay(Verbose, "Buffer size = %d bytes or %d milliseconds",
		      sizeBuffers, msBuffers);

    hwaveout = NULL;

    status = mmcWaveOutOpen(&sound_format.wave, uDeviceId, &mmov_driver ,
			    WAVE_OPEN_SHAREABLE, &hwaveout);

    if (status != MMSYSERR_NOERROR)
     {
	mmov_cleanup();
	return;
     }

   if (mmcBuffersCreate (&mmov_buffer, numBuffers, sizeBuffers, BUFFER_PAD)
	!= MMSYSERR_NOERROR)
     {
	mmov_cleanup();
	return;
     }

    for (;;)
    {
	switch ( play_state )
	{
	  case MMOV_START:
	    break;

	  case MMOV_PLAY:
	    status = mmcWaveOutQueueBufferAll (hwaveout, &mmov_buffer, Verbose,
					       &wavefilestatus, &allDone);
	    if (allDone)
	      play_state = MMOV_WAITING;
	    else
	     {
		if (status != MMSYSERR_NOERROR)
		  {
		     mmov_cleanup();
		     return;
		  }
	     }
	    break;

	  case MMOV_WAITING:
	    if ((mmcBufferFind(&mmov_buffer,Filling) != mmcBufferNone) ||
		(mmcBufferFind(&mmov_buffer,Full) != mmcBufferNone) ||
		(mmcBufferFind(&mmov_buffer,Playing) != mmcBufferNone))
	      break;
	    play_state = MMOV_CLOSE;

	  case MMOV_CLOSE:
	   status = mmcWaveOutClose (hwaveout, &mmov_buffer);
	   if (status != MMSYSERR_NOERROR)
		  {
		     mmov_cleanup();
		     return;
		  }
	    mmov_cleanup();
	   return;

	  default:
	    mmcVerboseDisplay(Verbose,"Unknown play_state %d", play_state);
	    mmov_cleanup();
	   return;
	}

	mmeWaitForCallbacks (); /* block so we don't hog 100% of the CPU */
	mmeProcessCallbacks ();
    }
}