⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hxaudev.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
( 
    const 	BOOL	bFlush
)
{
    HX_RESULT 	theErr = HXR_OK;
    if ( bFlush )
    {
        theErr = Reset();
    }
    else
    {
        theErr = Drain();
    }
    if ( !theErr )
        theErr = _Imp_Close();
    
    m_eState = E_DEV_CLOSED;
    
    return HXR_OK;
}

HX_RESULT CHXAudioDevice::Seek( UINT32  ulSeekTime)
{
    _Imp_Seek(ulSeekTime);
    return HXR_OK;
}


/************************************************************************
 *  Method:
 *		IHXAudioDevice::Pause
 *	Purpose:
 *		Pause the audio device.
 */
STDMETHODIMP CHXAudioDevice::Pause
(
)
{
    HX_RESULT 	theErr = HXR_OK;

    m_bPaused = TRUE;

    theErr = _Imp_Pause();

    m_eState = E_DEV_PAUSED;

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::Resume
 *	Purpose:
 *		Resume the audio device.
 */
STDMETHODIMP CHXAudioDevice::Resume
(
)
{
    HX_RESULT 	theErr = HXR_OK;

    m_bPaused = FALSE;

    theErr = _Imp_Resume();

    m_eState = E_DEV_RESUMED;

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::Write
 *	Purpose:
 *		Write data to the audio device.
 */
STDMETHODIMP CHXAudioDevice::Write
(
    const HXAudioData*	pAudioHdr
)
{
    HX_RESULT theErr = _Imp_Write( pAudioHdr );
    return theErr;
}


/************************************************************************
 *  Method:
 *		IHXAudioDevice::SetCallback
 *	Purpose:
 */
/*
STDMETHODIMP CHXAudioDevice::SetCallback
( 
)
{
    return HXR_OK;

}
*/

/************************************************************************
 *  Method:
 *		IHXAudioDevice::SetBuffering
 *	Purpose:
 *		Let the Audio Device manage the audio buffers.
 */
STDMETHODIMP CHXAudioDevice::SetBuffering
(
    const BOOL	bSetBuffering
)
{
    m_bBuffer = bSetBuffering;
    return HXR_OK;
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::InitVolume
 *	Purpose:
 *		Initialize the volume. Return TRUE if device supports volume.
 */
STDMETHODIMP_(BOOL) CHXAudioDevice::InitVolume
(
    const UINT16    uMinVolume,
    const UINT16    uMaxVolume
)
{
    m_uMinVolume = uMinVolume;
    m_uMaxVolume = uMaxVolume;

    return (_Imp_SupportsVolume());
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::SetVolume
 *	Purpose:
 *		Set the volume.
 */
STDMETHODIMP CHXAudioDevice::SetVolume 
(
    const UINT16    uVolume
)
{
    m_uCurVolume = uVolume;
    return _Imp_SetVolume( uVolume );
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::GetVolume
 *	Purpose:
 *		Get the volume.
 */
STDMETHODIMP_(UINT16) CHXAudioDevice::GetVolume()
{
    return _Imp_GetVolume();
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::Reset
 *	Purpose:
 *		Reset audio. Stop playback and flush all buffers.
 */
STDMETHODIMP CHXAudioDevice::Reset ()
{
    return( _Imp_Reset() );
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::Drain
 *	Purpose:
 *		Drain remaining audio with playback. 
 */
STDMETHODIMP CHXAudioDevice::Drain()
{
    return( _Imp_Drain() );
}

/************************************************************************
 *  Method:
 *              IHXAudioDevice::CheckFormat
 *      Purpose:
 *		Check to see if the audio device will accept this audio
 *		format.
 */
STDMETHODIMP CHXAudioDevice::CheckFormat( const HXAudioFormat* pFormat )
{
    return( _Imp_CheckFormat( pFormat ) );
}

/************************************************************************
 *  Method:
 *		IHXAudioDevice::GetCurrentAudioTime
 *	Purpose:
 *		Get the current time from the audio device.
 *              We added this to support the clock available in the
 *              Window's audio driver.
 */
STDMETHODIMP CHXAudioDevice::GetCurrentAudioTime 
(
    ULONG32&	ulCurrentTime
)
{
    return _Imp_GetCurrentTime( ulCurrentTime );
}

/************************************************************************
 *  Method:
 *		CHXAudioDevice::GetAudioFd
 *	Purpose:
 */
STDMETHODIMP CHXAudioDevice::GetAudioFd()
{
	return _Imp_GetAudioFd();
}

/************************************************************************
 *  Method:
 *		CHXAudioDevice::OnTimeSync
 *	Purpose:
 *		Get the audio time from the platform specific function
 *		GetCurrentAudioTime() and pass this up to the audio
 *		session.
 */
HX_RESULT    CHXAudioDevice::OnTimeSync()
{
    HX_RESULT theErr = HXR_OK;
    // Ignore this if we're paused!
    if (!m_bPaused)
    {
        ULONG32 ulAudioTime = 0;
        theErr = _Imp_GetCurrentTime( ulAudioTime );

        if (m_pDeviceResponse)
        {
            theErr = m_pDeviceResponse->OnTimeSync(ulAudioTime);
        }
    }
    return theErr;
}


UINT16 CHXAudioDevice::NumberOfBlocksRemainingToPlay()
{
    return _NumberOfBlocksRemainingToPlay();
}

BOOL CHXAudioDevice::IsWaveOutDevice()
{
    return _IsWaveOutDevice();
}

BOOL CHXAudioDevice::_IsWaveOutDevice()
{
    return TRUE;
}

/*************************************************************************
 * Test code..
 *
 */ 
#ifdef _TESTING_STR

#include <stdio.h>
#ifndef _WINDOWS
#include <unistd.h>             // for getopt()
#else
#include <io.h>			// for open()
#define O_NONBLOCK  0
#endif
#include <stdlib.h>             // for atoi()
#include <sys/types.h>          // for open()
#include <sys/stat.h>           // for open()
#include <fcntl.h>                      // for open()

#define INITGUID 1

#include "hxcom.h"
#include "hxausvc.h"
#include "hxaudev.h"

int opt_debug = 0xff;

int process_id(void)
{
return 10; 
}

#define BLOCK_SIZE  3176

void main( int argc, char **argv )
{
	CHXAudioDevice* mydev = 0;
	HX_RESULT theErr = HXR_OK;

	mydev = CHXAudioDevice::Create();

	printf("main: created: %x\n", mydev);

	HXAudioFormat audioFmt;
	audioFmt.uChannels = 1;
	audioFmt.uBitsPerSample= 16;
	audioFmt.ulSamplesPerSec= 11025; //44100; // 22050;  //11025;
	audioFmt.uMaxBlockSize = BLOCK_SIZE;
	
	printf("main: Format:\n");
	printf("main: Channels:         %d\n", audioFmt.uChannels );
	printf("main: Bits Per Sample   %d\n", audioFmt.uBitsPerSample);
	printf("main: SamplesPerSec     %d\n", audioFmt.ulSamplesPerSec);
	printf("main: MaxBlockSize      %d\n", audioFmt.uMaxBlockSize);
	printf("main: Check Format: err: %d\n", theErr);

        theErr = mydev->CheckFormat( &audioFmt );

	if ( !theErr )
	{
		IHXAudioDeviceResponse*        playerResponse = 0;
		theErr = mydev->Open( &audioFmt, playerResponse );
	}

	if ( !theErr )
	{
		theErr = mydev->Pause();
		theErr = mydev->Resume();
	}

	HXAudioData audioHdr;
	if ( !theErr )
	{
		audioHdr.ulAudioTime = 66;

		// Initialize the volume to 0,100
		if ( mydev->InitVolume( HX_MIN_VOLUME, HX_MAX_VOLUME ) )
			printf("main: SupportsVolume is TRUE\n");
		else
			printf("main: SupportsVolume is FALSE\n");

		UINT16	curVol = 0;
		theErr = mydev->GetVolume( curVol );
		printf("main: GetVolume: %d\n", curVol);

		UINT16	newVol = HX_INIT_VOLUME;
		theErr = mydev->SetVolume( newVol );
		printf("main: SetVolume: %d\n", newVol);

		curVol = 0;
		theErr = mydev->GetVolume( curVol );
		printf("main: GetVolume: %d\n", curVol);
	}

	// Write some PCM to the device...
	if ( !theErr )
	{
int cnt = 0;
		unsigned char buf[BLOCK_SIZE]; /* Flawfinder: ignore */
		if ( argc > 1 )
		{
			int fd;
			*argv++;
			printf("main: Playing: %s \n", *argv);
			fd = open( *argv,O_RDONLY | O_NONBLOCK ); /* Flawfinder: ignore */
			if ( fd > 0 )
			{
				int nbytes = 0;
				audioHdr.pData = (UCHAR*) new char [BLOCK_SIZE ]; 
				while( (nbytes = read( fd, buf, BLOCK_SIZE)) > 0 ) /* Flawfinder: ignore */
				{
					memcpy(audioHdr.pData,buf, nbytes); /* Flawfinder: ignore */
					// play silence memset(audioHdr.pData, 0, nbytes);
					audioHdr.ulBufLen = nbytes;
        				theErr = mydev->Write( &audioHdr );
cnt++;
				}
			}
		}
printf("Played %d blocks of %d bytes = %d\n", cnt, BLOCK_SIZE, cnt * BLOCK_SIZE);
		for (int i = 0; i<6; i++)
		{
			memset(buf,0,BLOCK_SIZE);
			memcpy(audioHdr.pData,buf, BLOCK_SIZE); /* Flawfinder: ignore */
			audioHdr.ulBufLen = BLOCK_SIZE;
        		theErr = mydev->Write( &audioHdr );
		}
	}

	if ( !theErr )
		theErr = mydev->Close(TRUE);
}

#endif // _TESTING

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -