Esempio n. 1
0
	int Pause() {
		if (waveOutPause(hWaveOut) != MMSYSERR_NOERROR) {
			MessageBox(NULL, L"Failed to Pause wave playback", L"MT32", MB_OK | MB_ICONEXCLAMATION);
			return 9;
		}
		return 0;
	}
Esempio n. 2
0
static
int set_pause(int flag)
{
  static int paused;
  MMRESULT error;

  if (flag && !paused) {
    error = waveOutPause(wave_handle);
    if (error != MMSYSERR_NOERROR) {
      audio_error = error_text(error);
      return -1;
    }
  }
  else if (!flag && paused) {
    error = waveOutRestart(wave_handle);
    if (error != MMSYSERR_NOERROR) {
      audio_error = error_text(error);
      return -1;
    }
  }

  paused = flag;

  return 0;
}
Esempio n. 3
0
/*
 * Stop stream.
 */
PJ_DEF(pj_status_t) pjmedia_snd_stream_stop(pjmedia_snd_stream *stream)
{
    MMRESULT mr;

    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL);

    if (stream->play_strm.hWave.Out != NULL)
    {
	mr = waveOutPause(stream->play_strm.hWave.Out);
	if (mr != MMSYSERR_NOERROR)
	    /* TODO: This macro is supposed to be used for HRESULT, fix. */
	    PJ_RETURN_OS_ERROR(mr);
	PJ_LOG(5,(THIS_FILE, "Stopped WMME playback stream"));
    }

    if (stream->rec_strm.hWave.In != NULL)
    {
	mr = waveInStop(stream->rec_strm.hWave.In);
	if (mr != MMSYSERR_NOERROR)
	    /* TODO: This macro is supposed to be used for HRESULT, fix. */
	    PJ_RETURN_OS_ERROR(mr);
	PJ_LOG(5,(THIS_FILE, "Stopped WMME capture stream"));
    }

    return PJ_SUCCESS;
}
Esempio n. 4
0
// ----------------
// DestroyRunObject
// ----------------
// Destroys the run-time object
// 
short WINAPI DLLExport DestroyRunObject(LPRDATA rdPtr, long fast)
{
	/* Immediately stop playback because the buffers will be gone soon */
	waveOutPause(rdPtr->device);

	/* Tell thread to stop */
	rdPtr->shuttingDown = true;

	/* Wait for thread to finish */
	WaitForSingleObject(rdPtr->thread, INFINITE);
	CloseHandle(rdPtr->thread);
	
	/* Free all buffers */
	for(int i = 0; i < NUM_BUFFERS; ++i)
	{
		waveOutUnprepareHeader(rdPtr->device, &rdPtr->buffers[i], sizeof(WAVEHDR));
		delete[] rdPtr->buffers[i].lpData;
	}

	/* Close audio device */
	waveOutClose(rdPtr->device);

	/* Good bye! */
	delete rdPtr->rRd;
	return 0;
}
// 函数实现
void* renderopen(void *surface, AVRational frate, int pixfmt, int w, int h,
                 int64_t ch_layout, AVSampleFormat sndfmt, int srate)
{
    WAVEFORMATEX wfx = {0};

    RENDER *render = (RENDER*)malloc(sizeof(RENDER));
    memset(render, 0, sizeof(RENDER));
    render->hRenderWnd = (HWND)surface; // save hwnd

    // init for audio
    wfx.cbSize          = sizeof(wfx);
    wfx.wFormatTag      = WAVE_FORMAT_PCM;
    wfx.wBitsPerSample  = 16;    // 16bit
    wfx.nSamplesPerSec  = 44100; // 44.1k
    wfx.nChannels       = 2;     // stereo
    wfx.nBlockAlign     = wfx.nChannels * wfx.wBitsPerSample / 8;
    wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
    waveOutOpen(&(render->hWaveOut), WAVE_MAPPER, &wfx, (DWORD_PTR)waveOutProc, (DWORD)render, CALLBACK_FUNCTION);
    waveOutPause(render->hWaveOut);
    wavqueue_create(&(render->WavQueue), render->hWaveOut, ((int64_t)44100 * 4 * frate.den / frate.num) & ~0x3);

    /* allocate & init swr context */
    render->pSWRContext = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16, 44100,
                          ch_layout, sndfmt, srate, 0, NULL);
    swr_init(render->pSWRContext);

    // init for video
    render->nVideoWidth  = w;
    render->nVideoHeight = h;
    render->nRenderWidth = GetSystemMetrics(SM_CXSCREEN);
    render->nRenderHeight= GetSystemMetrics(SM_CYSCREEN);
    render->nRenderNewW  = render->nRenderWidth;
    render->nRenderNewH  = render->nRenderHeight;
    render->PixelFormat  = (PixelFormat)pixfmt;

    // create sws context
    render->pSWSContext = sws_getContext(
                              render->nVideoWidth,
                              render->nVideoHeight,
                              render->PixelFormat,
                              render->nRenderWidth,
                              render->nRenderHeight,
                              PIX_FMT_RGB32,
                              SWS_BILINEAR,
                              0, 0, 0);

    render->iFrameTick = 1000 * frate.den / frate.num;
    render->iSleepTick = render->iFrameTick;

    // create dc & bitmaps
    render->hRenderDC = GetDC(render->hRenderWnd);
    render->hBufferDC = CreateCompatibleDC(render->hRenderDC);

    // create bmp queue
    bmpqueue_create(&(render->BmpQueue), render->hBufferDC, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 32);

    render->nRenderStatus = 0;
    pthread_create(&(render->hVideoThread), NULL, VideoRenderThreadProc, render);
    return render;
}
void renderpause(void *hrender)
{
    if (!hrender) return;
    RENDER *render = (RENDER*)hrender;
    waveOutPause(render->hWaveOut);
    render->nRenderStatus |= RS_PAUSE;
}
Esempio n. 7
0
BOOL COXSound::PlayWithCallback()
	//	--- In:
	//	--- Out:
	//	--- Returns:	BOOL : TRUE if the function is successful
	//	---	Effect:		Plays a loaded WAVE asynchronously with callback notification
{
	// If playing asynchronously, there MUST be a callback
	// window to handle processing when the Wave completes.

	ASSERT((m_hCallbackWnd != NULL) && ::IsWindow(m_hCallbackWnd));

	if(!::SendMessage(m_hCallbackWnd,WM_OX_SOUNDABOUTTOPLAY,NULL,(LPARAM)this))
	{
		if(m_hWaveOut)
		{
			waveOutPause(m_hWaveOut);
			waveOutReset(m_hWaveOut);
		}

		CloseWaveOutDevice();

		if(!PrepareWaveHeader())
		{
			return FALSE;
		}

		return TRUE;
	}

	return FALSE;
}
Esempio n. 8
0
/* DO NOT CALL FROM CALLBACK THREAD (audio thread)!!!! */
VOID DestroySoundInstance(PSOUNDINSTANCE instance)
{
    UINT index = instance - g_soundInstances;

    if (instance->WaveOut)
    {
        waveOutPause(instance->WaveOut);

        if (instance->Header)
        {
            waveOutUnprepareHeader(instance->WaveOut, instance->Header, sizeof(WAVEHDR));
            free(instance->Header->lpData);
            free(instance->Header);
        }

        waveOutClose(instance->WaveOut);
    }

    ZeroMemory(instance, sizeof(SOUNDINSTANCE));

    if (index < g_nextFreeInstance)
    {
        g_nextFreeInstance = index;
    }
}
Esempio n. 9
0
static void
win32_play_data (Win32_Audio_Data *audio_data)
{	int thisread, readcount ;
		
	readcount = (audio_data->remaining > audio_data->bufferlen) ? audio_data->bufferlen : (int) audio_data->remaining ;

	thisread = (int) sf_read_short (audio_data->sndfile, (short *) (audio_data->whdr [audio_data->current].lpData), readcount) ;

	audio_data->remaining -= thisread ;

	if (thisread > 0)
	{	/* Fix buffer length is only a partial block. */
		if (thisread * sizeof (short) < audio_data->bufferlen)
			audio_data->whdr [audio_data->current].dwBufferLength = thisread * sizeof (short) ;

		/* Queue the WAVEHDR */
		waveOutWrite (audio_data->hwave, (LPWAVEHDR) &(audio_data->whdr [audio_data->current]), sizeof (WAVEHDR)) ;
		}
	else
	{	/* Stop playback */
		waveOutPause (audio_data->hwave) ;

		SetEvent (audio_data->Event) ;
		} ;

	audio_data->current = (audio_data->current + 1) % 2 ;

} /* win32_play_data */
Esempio n. 10
0
void pcm_suspend()
{
        if (wout) {
                waveOutPause(wout);
                soundresume = 1;
        }
}
Esempio n. 11
0
 /***********************************************************************
  * WaveLib_Init
  *  
  *    Audio!
  *
  * Parameters
  *     
  * 
  * Return Value
  *     Handle To This Audio Session
  *
  ***********************************************************************/
 HWAVELIB WaveLib_Init(PCHAR pWaveFile, BOOL bPause)
 {
     PWAVELIB pWaveLib = NULL;
 
     if(pWaveLib = (PWAVELIB)LocalAlloc(LMEM_ZEROINIT, sizeof(WAVELIB)))
     {
         pWaveLib->bPaused = bPause;

         if(WaveLib_OpenWaveSample(pWaveFile, &pWaveLib->WaveSample))
         {
             if(waveOutOpen(&pWaveLib->hWaveOut, WAVE_MAPPER, &pWaveLib->WaveSample.WaveFormatEx, (ULONG)WaveLib_WaveOutputCallback, (ULONG)pWaveLib, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
             {
                WaveLib_UnInit((HWAVELIB)pWaveLib);
                pWaveLib = NULL;
             }
             else
             {
 
                 if(pWaveLib->bPaused)
                 {
                     waveOutPause(pWaveLib->hWaveOut);
                 }

                 WaveLib_CreateThread(pWaveLib);
             }
         }
         else
         {
             WaveLib_UnInit((HWAVELIB)pWaveLib);
             pWaveLib = NULL;
         }
     }

     return (HWAVELIB)pWaveLib;
 }
Esempio n. 12
0
static int winwave_ctl_out (HWVoiceOut *hw, int cmd, ...)
{
    MMRESULT mr;
    WaveVoiceOut *wave = (WaveVoiceOut *) hw;

    switch (cmd) {
    case VOICE_ENABLE:
        {
            va_list ap;
            int poll_mode;

            va_start (ap, cmd);
            poll_mode = va_arg (ap, int);
            va_end (ap);

            if (poll_mode && !wave->event) {
                wave->event = CreateEvent (NULL, TRUE, TRUE, NULL);
                if (!wave->event) {
                    dolog ("DAC CreateEvent: %lx, poll mode will be disabled\n",
                           GetLastError ());
                }
            }

            if (wave->event) {
                int ret;

                ret = qemu_add_wait_object (wave->event, winwave_poll, wave);
                hw->poll_mode = (ret == 0);
            }
            else {
                hw->poll_mode = 0;
            }
            if (wave->paused) {
                mr = waveOutRestart (wave->hwo);
                if (mr != MMSYSERR_NOERROR) {
                    winwave_logerr (mr, "waveOutRestart");
                }
                wave->paused = 0;
            }
        }
        return 0;

    case VOICE_DISABLE:
        if (!wave->paused) {
            mr = waveOutPause (wave->hwo);
            if (mr != MMSYSERR_NOERROR) {
                winwave_logerr (mr, "waveOutPause");
            }
            else {
                wave->paused = 1;
            }
        }
        if (wave->event) {
            qemu_del_wait_object (wave->event, winwave_poll, wave);
        }
        return 0;
    }
    return -1;
}
Esempio n. 13
0
/**
 * win32ao_open(int sample_rate)
 * Setup audio for output at specified rate.
 * returns -1 on error, 0 on happy.
 */
int win32ao_open(int sample_rate, float jitterBufSecs) {
	WAVEFORMATEX waveFormat;
	MMRESULT res;
	int i;

	// create an event by which audio driver will notify us
	whoutEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

	// populate whoutFormat struct
	waveFormat.wFormatTag = WAVE_FORMAT_PCM;
	waveFormat.nChannels = 1;
	waveFormat.nSamplesPerSec = sample_rate;
	waveFormat.nAvgBytesPerSec = sample_rate * SAMPLE_BITS / 8;
	waveFormat.nBlockAlign = SAMPLE_BITS / 8;
	waveFormat.wBitsPerSample = SAMPLE_BITS;
	waveFormat.cbSize = 0;

	whoutBufNo = 0;
	whoutBufIndex = 0;

	// open audio device
	res = waveOutOpen(&waveout, WAVE_MAPPER, &waveFormat,
			  (DWORD) whoutEvent, (DWORD) 0, CALLBACK_EVENT);
	if (checkWaveOutResult(waveout, res, "waveOutOpen"))
		return -1;

	// pause playback (unpause when lo water mark reached)
	res = waveOutPause(waveout);
	if (checkWaveOutResult(waveout, res, "waveOutPause"))
		return -1;

	// compute whoutBufCnt
	whoutBufCnt = (int) ceil(jitterBufSecs * (float) waveFormat.nAvgBytesPerSec
					         / (float) WaveBuf_SIZE);
	if (whoutBufCnt < WaveBuf_N_MIN)
		whoutBufCnt = WaveBuf_N_MIN;

	// create buffers
	whout = (WAVEHDR**) malloc(whoutBufCnt * sizeof(WAVEHDR**));
	for (i = 0; i < whoutBufCnt; ++i) {
		// allocate buffer header
		whout[i] = (WAVEHDR*) calloc(1, sizeof(WAVEHDR));
		if (whout[i] == NULL) {
			perror("calloc WAVEHDR");
			return -1;
		}
		// allocate buffer
		whout[i]->lpData = malloc(WaveBuf_SIZE);
		if (whout[i]->lpData == NULL) {
			perror("malloc lpData");
			return -1;
		}
	}

	return 0;
}
Esempio n. 14
0
int EmuOutMod::Pause(int pause) {
    if(pause) {
        waveOutPause(m_hwo);
        m_playing = false;
    } else {
        waveOutRestart(m_hwo);
        m_playing = true;
    }
    return !pause;
}
Esempio n. 15
0
void COutput::Reset()
{
	if (!m_hwo)
		return;

	if (m_fDoubleBuf) {
		CAutoLock lockDev(&m_csecDevice);
		SetEvent(m_hEvent);
		m_cWritten = 0;
		m_dwWritten = 0;
		m_nCurrent = 0; 
		m_nWriteCur = 0;
		m_fPaused = TRUE;
		m_dwTotalSamples = 0;

		if (m_pHdr) {
			CAutoLock lock(&m_csecBuff);
			for (DWORD i = 0; i < m_cBuf; i++)
				m_pHdr[i].dwUser = 0;
		}
	}
	else {
		CAutoLock lock(&m_csecDevice);
		waveOutPause(m_hwo);
		waveOutReset(m_hwo);

		SetEvent(m_hEvent);
		m_cWritten = 0;
		m_dwWritten = 0;
		m_nCurrent = 0;
		m_nWriteCur = 0;
		waveOutPause(m_hwo);
	}

	m_nLPeek = 0;
	m_nRPeek = 0;
	if (m_fFade) {
		m_nFadeCurrent = FADE_BASE << FADE_BITS;
		m_nFadeSamples = m_pcm.wf.nSamplesPerSec * FADE_TIME / 1000;
		m_nFadeRate = (int)((((double)1 - FADE_BASE) / m_nFadeSamples) * (1 << FADE_BITS));
		m_nFadeRate += 1;
	}
}
Esempio n. 16
0
ModPlay::~ModPlay()
{
	stopped = true; // tell the thread to exit
	waveOutPause(hWaveOut); // make sure no buffers are written and played in case of a race condition
	waveOutReset(hWaveOut); // calls WOM_DONE for all buffers (thread checks if stopped == true and exits)
	WaitForSingleObject(hThread, INFINITE); // Let the thread finish
	waveOutClose(hWaveOut);
	CloseHandle(hEventDone);
	CloseHandle(hThread);
	ModPlug_Unload(modFile);
}
Esempio n. 17
0
int pausesound(AUDIO_t *audio) {
	if (!audio->init) {
		return 0;
	}

	audio->enabled = FALSE;
#ifdef _WINDOWS
	waveOutPause(audio->hWaveOut);
#endif
	return 0;
}
 void MediaObject::pause()
 {
     if (!m_paused) {
         m_paused = true;
         setState(Phonon::PausedState);
         if (!(waveOutPause(m_hWaveOut) == MMSYSERR_NOERROR))
         {
             setError(Phonon::NormalError, QLatin1String("cannot pause (system error)"));
         }
     }
 }
Esempio n. 19
0
// Play audio, starting at a given frame/sample
BOOL CALLBACK aviaudioPlay(HWND hwnd, PAVISTREAM pavi, LONG lStart, LONG lEnd, BOOL fWait)
{
	if (audioPlayable <= 0)
		return FALSE;

	recalc = 1;

	//CString tx;
	//tx.Format("audioPlayable %d",audioPlayable);
	//MessageBox(NULL,tx,"Note",MB_OK);

	CString msx;

	if (lStart < 0)
		lStart = ::AVIStreamStart(pavi);

	if (lEnd < 0)
		lEnd = AVIStreamEnd(pavi);

	if (lStart >= lEnd) {
		return FALSE;
	}

	if (!aviaudioOpenDevice(hwnd, pavi)) {
		MessageBox(NULL,"AudioOpen failed","Note",MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	if (!sfPlaying) {
		// We're beginning play, so pause until we've filled the buffers
		// for a seamless start
		waveOutPause(shWaveOut);

		slBegin = lStart;
		slCurrent = lStart;
		slEnd = lEnd;
		sfPlaying = TRUE;
	} else {
		slEnd = lEnd;
	}

	aviaudioiFillBuffers();

	// Now unpause the audio and away it goes!
	waveOutRestart(shWaveOut);

	// Caller wants us not to return until play is finished
	if (fWait) {
		while (swBuffersOut > 0)
			Yield();
	}

	return TRUE;
}
/** Pause audio playback (do not empty the buffer) */
int sa_stream_pause(sa_stream_t *s) {
  int status;

  ERROR_IF_NO_INIT(s);
  
  status = waveOutPause(s->hWaveOut);
  HANDLE_WAVE_ERROR(status, "resuming audio playback");

  s->playing = 0;

  return SA_SUCCESS;
}
Esempio n. 21
0
int
cubeb_stream_stop(cubeb_stream * stm)
{
  MMRESULT r;

  r = waveOutPause(stm->waveout);
  assert(r == MMSYSERR_NOERROR);

  stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED);

  return CUBEB_OK;
}
Esempio n. 22
0
void QAudioOutputPrivate::suspend()
{
    if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState) {
        int delay = (buffer_size-bytesFree())*1000/(settings.frequency()
                *settings.channels()*(settings.sampleSize()/8));
        waveOutPause(hWaveOut);
        Sleep(delay+10);
        deviceState = QAudio::SuspendedState;
        errorState = QAudio::NoError;
        emit stateChanged(deviceState);
    }
}
Esempio n. 23
0
	MMRESULT TinyWaveOut::Pause()
	{
		if (hWaveOut == NULL) return S_FALSE;
		MMRESULT hRes = waveOutPause(hWaveOut);
		if (hRes != MMSYSERR_NOERROR)
		{
			waveOutClose(hWaveOut);
			hWaveOut = NULL;
			return S_FALSE;
		}
		return S_OK;
	}
Esempio n. 24
0
static DWORD CALLBACK
win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD data, DWORD param1, DWORD param2)
{	WIN32_AUDIO_OUT	*win32_out ;
	int		read_count, sample_count, k ;
	short	*sptr ;

	/*
	** I consider this technique of passing a pointer via an integer as
	** fundamentally broken but thats the way microsoft has defined the
	** interface.
	*/
	if ((win32_out = (WIN32_AUDIO_OUT*) data) == NULL)
	{	printf ("win32_audio_out_callback : AUDIO_OUT is NULL.\n") ;
		return 1 ;
		} ;

	if (win32_out->magic != WIN32_MAGIC)
	{	printf ("win32_audio_out_callback : Bad magic number (%d %d).\n", win32_out->magic, WIN32_MAGIC) ;
		return 1 ;
		} ;

	if (msg != MM_WOM_DONE)
		return 0 ;

	/* Do the actual audio. */
	sample_count = win32_out->bufferlen ;

	read_count = win32_out->callback (win32_out->callback_data, win32_out->float_buffer, sample_count) ;

	sptr = (short*) win32_out->whdr [win32_out->current].lpData ;

	for (k = 0 ; k < read_count ; k++)
		sptr [k] = lrint (32767.0 * win32_out->float_buffer [k]) ;

	if (read_count > 0)
	{	/* Fix buffer length is only a partial block. */
		if (read_count * sizeof (short) < win32_out->bufferlen)
			win32_out->whdr [win32_out->current].dwBufferLength = read_count * sizeof (short) ;

		/* Queue the WAVEHDR */
		waveOutWrite (win32_out->hwave, (LPWAVEHDR) &(win32_out->whdr [win32_out->current]), sizeof (WAVEHDR)) ;
		}
	else
	{	/* Stop playback */
		waveOutPause (win32_out->hwave) ;

		SetEvent (win32_out->Event) ;
		} ;

	win32_out->current = (win32_out->current + 1) % 2 ;

	return 0 ;
} /* win32_audio_out_callback */
Esempio n. 25
0
int WaveOut::Pause(int pause)
{
	bool waspaused = _paused;
	if (pause)
	{
		if (!waspaused) waveOutPause(_device);
		_paused = true;
	}
	else
	{
		if (waspaused) waveOutRestart(_device);
		_paused = false;
	}
	return waspaused?1:0;
}
Esempio n. 26
0
void COutput::Pause(BOOL fPause)
{
	if (!m_hwo)
		return;

	if (m_fDoubleBuf)
		m_fPaused = fPause;
	else {
		CAutoLock lock(&m_csecDevice);
		if (fPause)
			waveOutPause(m_hwo);
		else
			waveOutRestart(m_hwo);
	}
}
Esempio n. 27
0
void CWaveDevice::StopFromSoundThread()
//-------------------------------------
{
	MPT_TRACE();
	if(m_hWaveOut)
	{
		CheckResult(waveOutPause(m_hWaveOut));
		m_JustStarted = false;
		{
			MPT_LOCK_GUARD<mpt::mutex> guard(m_PositionWraparoundMutex);
			MemsetZero(m_PositionLast);
			m_PositionWrappedCount = 0;
		}
	}
}
Esempio n. 28
0
  /***********************************************************************
  * WaveLib_Pause
  *  
  *    Audio!
  *
  * Parameters
  *     
  * 
  * Return Value
  *     Handle To This Audio Session
  *
  ***********************************************************************/
 void WaveLib_Pause(HWAVELIB hWaveLib, BOOL bPause)
 {
     PWAVELIB pWaveLib = (PWAVELIB)hWaveLib;

     pWaveLib->bPaused = bPause;

     if(pWaveLib->bPaused)
     {
         waveOutPause(pWaveLib->hWaveOut);
     }
     else
     {
         waveOutRestart(pWaveLib->hWaveOut);
     }
 }
Esempio n. 29
0
static int
winaudio_out_ctl (HWVoiceOut *hw, int cmd, ...)
{
    WinAudioOut*  s = (WinAudioOut*) hw;

    switch (cmd) {
    case VOICE_ENABLE:
        waveOutRestart( s->waveout );
        break;

    case VOICE_DISABLE:
        waveOutPause( s->waveout );
        break;
    }
    return 0;
}
Esempio n. 30
0
int
cubeb_stream_stop(cubeb_stream * stm)
{
  MMRESULT r;

  EnterCriticalSection(&stm->lock);
  r = waveOutPause(stm->waveout);
  LeaveCriticalSection(&stm->lock);

  if (r != MMSYSERR_NOERROR) {
    return CUBEB_ERROR;
  }

  stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED);

  return CUBEB_OK;
}