示例#1
0
// ---------------------------------------------------------------------------
void CUARFCN::ReadConf(ini_t *pini)
{
	pini->Select("BNDS");

	m_bBandEnable[0] = pini->Get("I", 1);
	m_bBandEnable[1] = pini->Get("II", 1);
	m_bBandEnable[2] = pini->Get("III", 1);
	m_bBandEnable[3] = pini->Get("IV", 1);
	m_bBandEnable[4] = pini->Get("V", 1);
	m_bBandEnable[5] = pini->Get("VI", 1);
	m_bBandEnable[6] = pini->Get("VII", 1);
	m_bBandEnable[7] = pini->Get("VIII", 1);
	m_bBandEnable[8] = pini->Get("IX", 1);
	m_bBandEnable[9] = pini->Get("X", 1);
	m_bBandEnable[10] = pini->Get("XI", 1);
	m_bBandEnable[11] = pini->Get("XII", 1);
	m_bBandEnable[12] = pini->Get("XIII", 1);
	m_bBandEnable[13] = pini->Get("XIV", 1);

	SetBands(true); // ULRX
	SetBands(false); // DLTX

	SetChannels(true); // ULRX
	SetChannels(false); // DLTX

	SetFrequency(true); // ULRX
	SetFrequency(false); // DLTX

};
示例#2
0
void CUARFCN::Initialize()
{
	SetBands(true); // ULRX
	SetBands(false); // DLTX

	SetChannels(true); // ULRX
	SetChannels(false); // DLTX

	SetFrequency(true); // ULRX
	SetFrequency(false); // DLTX
};
static int mtk_pcm_dl2_start(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;

	pr_warn("%s\n", __func__);
	/* here start digital part */

	SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I07,
		      Soc_Aud_InterConnectionOutput_O03);
	SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I08,
		      Soc_Aud_InterConnectionOutput_O04);

#ifdef CONFIG_MTK_FPGA
	/* set loopback test interconnection */
	SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I07,
		      Soc_Aud_InterConnectionOutput_O09);
	SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I08,
		      Soc_Aud_InterConnectionOutput_O10);
#endif

	SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, true);

	SetSampleRate(Soc_Aud_Digital_Block_MEM_DL2, runtime->rate);
	SetChannels(Soc_Aud_Digital_Block_MEM_DL2, runtime->channels);
	SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL2, true);

	SetIrqMcuCounter(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->period_size);
	SetIrqMcuSampleRate(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->rate);
	EnableAfe(true);
	return 0;
}
static int mtk_pcm_I2S0dl1_start(struct snd_pcm_substream *substream)
{
    struct snd_pcm_runtime *runtime = substream->runtime;
    printk("%s\n", __func__);
    // here start digital part

    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O00);
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O01);
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O03);
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O04);

    SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, true);

    SetSampleRate(Soc_Aud_Digital_Block_MEM_DL1, runtime->rate);
    SetChannels(Soc_Aud_Digital_Block_MEM_DL1, runtime->channels);
    SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1, true);

    EnableAfe(true);

#ifdef _DEBUG_6328_CLK
    //Debug 6328 Digital to Analog path clock and data work or not. and read TEST_OUT(0x206)
//    Ana_Set_Reg(AFE_MON_DEBUG0, 0x4600 , 0xcf00); // monitor 6328 digitala data sent to analog or not
    Ana_Set_Reg(AFE_MON_DEBUG0, 0x4200 , 0xcf00); // monitor 6328 digitala data sent to analog or not    
    Ana_Set_Reg(TEST_CON0, 0x0e00 , 0xffff);
#endif    

#if 0 // test 6328 sgen
    Ana_Set_Reg(AFE_SGEN_CFG0 , 0x0080 , 0xffff);
    Ana_Set_Reg(AFE_SGEN_CFG1 , 0x0101 , 0xffff);    
    Ana_Set_Reg(AFE_AUDIO_TOP_CON0, 0x0000, 0xffff);   //power on clock    
    //    Ana_Set_Reg(PMIC_AFE_TOP_CON0, 0x0002, 0x0002);   //UL from sinetable
    Ana_Set_Reg(PMIC_AFE_TOP_CON0, 0x0001, 0x0001);   //DL from sinetable      
#endif
    return 0;
}
示例#5
0
// CONSTRUCTOR
OSndStreamWAV::OSndStreamWAV()
	:OSndStream()
{
	SetStreamType( SNDSTREAM_WAV );
	m_pSndFile=NULL;
	SetFileExtention( _T( "wav" ) );
	m_OutputFormat = SF_FORMAT_PCM_16;
	SetSampleRate( 44100 );
	SetChannels( 2 );
}
示例#6
0
static int mtk_pcm_dl1bt_start(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	AudDrv_Clk_On();
	SetMemifSubStream(Soc_Aud_Digital_Block_MEM_DL1, substream);
	if (runtime->format == SNDRV_PCM_FORMAT_S32_LE ||
	    runtime->format == SNDRV_PCM_FORMAT_U32_LE) {
		SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL1,
					     AFE_WLEN_32_BIT_ALIGN_8BIT_0_24BIT_DATA);
		SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL2,
					     AFE_WLEN_32_BIT_ALIGN_8BIT_0_24BIT_DATA);
		/* BT SCO only support 16 bit */
		SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O02);
	} else {
		SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL1, AFE_WLEN_16_BIT);
		SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL2, AFE_WLEN_16_BIT);
		SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT,
					  Soc_Aud_InterConnectionOutput_O02);
	}

	/* here start digital part */
	SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I05,
		      Soc_Aud_InterConnectionOutput_O02);
	SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I06,
		      Soc_Aud_InterConnectionOutput_O02);
	SetConnection(Soc_Aud_InterCon_ConnectionShift,
		      Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O02);
	SetConnection(Soc_Aud_InterCon_ConnectionShift,
		      Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O02);

	/* set dl1 sample ratelimit_state */
	SetSampleRate(Soc_Aud_Digital_Block_MEM_DL1, runtime->rate);
	SetChannels(Soc_Aud_Digital_Block_MEM_DL1, runtime->channels);
	SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1, true);

	/* here to set interrupt */
	SetIrqMcuCounter(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->period_size >> 1);
	SetIrqMcuSampleRate(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->rate);
	SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, true);

	if (GetMemoryPathEnable(Soc_Aud_Digital_Block_DAI_BT) == false) {
		/* set merge interface */
		SetMemoryPathEnable(Soc_Aud_Digital_Block_DAI_BT, true);
	} else {
		SetMemoryPathEnable(Soc_Aud_Digital_Block_DAI_BT, true);
	}

	SetVoipDAIBTAttribute(runtime->rate);
	SetDaiBtEnable(true);

	EnableAfe(true);

	return 0;
}
示例#7
0
bool retro_load_game(const struct retro_game_info *info)
{
   int i;
   static char ROMName_buffer[MAXCARTS][1024];
   enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;

   if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
   {
      if (log_cb)
         log_cb(RETRO_LOG_INFO, "RGB565 is not supported.\n");
      return false;
   }

   environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &ProgDir);

   check_variables();
   set_input_descriptors();

   Verbose=1;

   UPeriod=100;

   strcpy(ROMName_buffer[0], info->path);
   ROMName[0]=ROMName_buffer[0];
   SETJOYTYPE(0,1);
//   ProgDir=".";

   static Image fMSX_image;
   fMSX_image.Cropped = 0;
   fMSX_image.D = 16;
   fMSX_image.Data = image_buffer;
   fMSX_image.W = image_buffer_width;
   fMSX_image.H = image_buffer_height;
   fMSX_image.L = image_buffer_width;

   GenericSetVideo(&fMSX_image,0,0,image_buffer_width,image_buffer_height);

   for(i = 0; i < 80; i++)
      SetColor(i, 0, 0, 0);

   for(i = 0; i < 256; i++)
     BPal[i]=PIXEL(((i>>2)&0x07)*255/7,((i>>5)&0x07)*255/7,(i&0x03)*255/3);

   memset((void *)XKeyState,0xFF,sizeof(XKeyState));

   InitSound(SND_RATE, 0);
   SetChannels(255/MAXCHANNELS, (1<<MAXCHANNELS)-1);

   ExitNow = 1;
   StartMSX(Mode,RAMPages,VRAMPages);
   printf ("Mode %i, RAMPages %i, VRAMPages %i", Mode, RAMPages, VRAMPages);
   return true;
}
示例#8
0
/*--------------------------------------------------------------------------------*/
void BiQuadFilterBank::AddFilter(const BiQuadCoeffs& coeffs)
{
  FILTER *filter;

  if ((filter = new FILTER) != NULL)
  {
    filter->coeffs = coeffs;
    filters.push_back(filter);
  }

  // ensure the added filter has the right number of channels
  if (nchannels) SetChannels(nchannels);
}
static int mtk_pcm_fmtx_start(struct snd_pcm_substream *substream)
{
    struct snd_pcm_runtime *runtime = substream->runtime;
    AudDrv_Clk_On();

    //    mtk_wcn_cmb_stub_audio_ctrl((CMB_STUB_AIF_X)CMB_STUB_AIF_2);

    SetMemifSubStream(Soc_Aud_Digital_Block_MEM_DL1, substream);
    if (runtime->format == SNDRV_PCM_FORMAT_S32_LE || runtime->format == SNDRV_PCM_FORMAT_U32_LE)
    {
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL1, AFE_WLEN_32_BIT_ALIGN_8BIT_0_24BIT_DATA);
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL2, AFE_WLEN_32_BIT_ALIGN_8BIT_0_24BIT_DATA);
        SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O00); // FM Tx only support 16 bit
        SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O01); // FM Tx only support 16 bit
    }
    else
    {
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL1, AFE_WLEN_16_BIT);
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL2, AFE_WLEN_16_BIT);
        SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O00);
        SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O01);
    }

    // here start digital part
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O00);
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O01);

    // set dl1 sample ratelimit_state
    SetSampleRate(Soc_Aud_Digital_Block_MEM_DL1, runtime->rate);
    SetChannels(Soc_Aud_Digital_Block_MEM_DL1, runtime->channels);

    // start MRG I2S Out
    SetMemoryPathEnable(Soc_Aud_Digital_Block_MRG_I2S_OUT, true);
    SetMrgI2SEnable(true, runtime->rate) ;

    // start 2nd I2S Out

    Set2ndI2SOutAttribute(runtime->rate) ;
    Set2ndI2SOutEnable(true);

    SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1, true);

    // here to set interrupt
    SetIrqMcuCounter(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, (runtime->period_size * 2 / 3));
    SetIrqMcuSampleRate(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->rate);
    SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, true);

    EnableAfe(true);

    return 0;
}
static int mtk_pcm_i2s0_start(struct snd_pcm_substream *substream)
{
    struct snd_pcm_runtime *runtime = substream->runtime;
    uint32 u32AudioI2S = 0;
    AudDrv_Clk_On();
    SetMemifSubStream(Soc_Aud_Digital_Block_MEM_DL1, substream);
    if (runtime->format == SNDRV_PCM_FORMAT_S32_LE || runtime->format == SNDRV_PCM_FORMAT_S32_LE)
    {
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL1, AFE_WLEN_32_BIT_ALIGN_8BIT_0_24BIT_DATA);
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL2, AFE_WLEN_32_BIT_ALIGN_8BIT_0_24BIT_DATA);
    }
    else
    {
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL1, AFE_WLEN_16_BIT);
        SetMemIfFetchFormatPerSample(Soc_Aud_Digital_Block_MEM_DL2, AFE_WLEN_16_BIT);
    }

    SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O00);
    SetoutputConnectionFormat(OUTPUT_DATA_FORMAT_16BIT, Soc_Aud_InterConnectionOutput_O01);

    // here start digital part
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O00);
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O01);


    u32AudioI2S = SampleRateTransform(runtime->rate) << 8;
    u32AudioI2S |= Soc_Aud_I2S_FORMAT_I2S << 3; // us3 I2s format
    u32AudioI2S |= Soc_Aud_I2S_WLEN_WLEN_32BITS << 1; // 32 BITS

    if (mi2s0_hdoutput_control == true)
    {
        u32AudioI2S |= Soc_Aud_LOW_JITTER_CLOCK << 12 ; //Low jitter mode
    }

    printk(" u32AudioI2S= 0x%x\n", u32AudioI2S);
    Afe_Set_Reg(AFE_I2S_CON3, u32AudioI2S | 1, AFE_MASK_ALL);

    SetSampleRate(Soc_Aud_Digital_Block_MEM_DL1, runtime->rate);
    SetChannels(Soc_Aud_Digital_Block_MEM_DL1, runtime->channels);
    SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1, true);

    // here to set interrupt
    SetIrqMcuCounter(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->period_size);
    SetIrqMcuSampleRate(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, runtime->rate);
    SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, true);

    EnableAfe(true);

    return 0;
}
static int mtk_pcm_dl1_start(struct snd_pcm_substream *substream)
{
    struct snd_pcm_runtime *runtime = substream->runtime;
    printk("%s\n", __func__);
    // here start digital part

    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O03);
    SetConnection(Soc_Aud_InterCon_Connection, Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O04);

    SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, true);

    SetSampleRate(Soc_Aud_Digital_Block_MEM_DL1, runtime->rate);
    SetChannels(Soc_Aud_Digital_Block_MEM_DL1, runtime->channels);
    SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1, true);

    EnableAfe(true);

    return 0;
}
示例#12
0
double CUARFCN::selectBand(bool ULRX, int bandInd)
{
	double dFreq;
	SelectionContainer *Bands;
	if (ULRX)
	{
		Bands = &cmbULRXBands;
	}
	else
	{
		Bands = &cmbDLTXBands;
	};

	if (Bands == NULL)
		return 0;

	Bands->itemIndex = bandInd;
	SetChannels(ULRX);
	dFreq = SetFrequency(ULRX);
	return dFreq;
}
示例#13
0
BiQuadFilterBank::BiQuadFilterBank(const BiQuadFilterBank& obj) : nchannels(0)
{
  // duplicate passed object include audio state

  SetChannels(obj.nchannels);
  SetFilters((uint_t)obj.filters.size());
  
  uint_t i, j;
  for (i = 0; i < filters.size(); i++)
  {
    const FILTER& srcfilter = *obj.filters[i];
    FILTER&       dstfilter = *filters[i];

    // copy filter coeffs and interpolation state
    dstfilter.coeffs = srcfilter.coeffs;

    for (j = 0; j < srcfilter.channels.size(); j++)
    {
      // copy audio state
      dstfilter.channels[j].CopyAudioState(srcfilter.channels[j]);
    }
  }
}
示例#14
0
/*--------------------------------------------------------------------------------*/
void BiQuadFilterBank::SetFilters(uint_t n)
{
  // remove filters from end if necessary
  while (filters.size() > n)
  {
    FILTER *filter = filters.back();
    delete filter;
    filters.pop_back();
  }

  // add filters if necessary
  while (filters.size() < n)
  {
    FILTER *filter;

    if ((filter = new FILTER) != NULL)
    {
      filters.push_back(filter);
    }
  }

  // ensure the added filters have the right number of channels
  if (nchannels) SetChannels(nchannels);
}
示例#15
0
/*  MATLAB TO C-CALL LINKING FUNCTION  */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
	char     *Family;
	int      i, FunctionType, NumberOfAverages, ChanTypeFlag, WaitOnSPFlag, status, SleepTimeInt;
	int      nrowsDeviceNum, ncolsDeviceNum;
	int      nrowsSectorNum, ncolsSectorNum;
	int      nrowsNewSP, ncolsNewSP;
	int      nrowst, ncolst;
	double   *AM, *SectorNum, *DeviceNum, *NewSP, *t, *tout, *ErrorFlag, t0=0, SleepTime, Time0;


	/* Check Inputs */
	if (nrhs < 4)
		mexErrMsgTxt("More input arguments needed (4 to get a channel, 5 to set a channel) (alslink.c).");

	/* Input 1: Function type (int, scalar) */
	/* 0 -> GetChannels                     */
	/* 1 -> SetChannels                     */
	FunctionType = (int) mxChkGetScalar(INPUT1);


	/* Input 2: Family name (string) */	
	Family = mxCalloc(50, sizeof(char));
	mxChkGetString(INPUT2, Family);  

	
	/* Input 3: Sector (column vector) */
	nrowsSectorNum = (int) mxGetM(INPUT3);
	ncolsSectorNum = (int) mxGetN(INPUT3);
	if (!mxIsNumeric(INPUT3) || mxIsComplex(INPUT3) || 
		!mxIsDouble(INPUT3) ||
		ncolsSectorNum != 1)
		mexErrMsgTxt("SectorNum must be a column vector equal to DeviceNum.");
	SectorNum = mxGetPr(INPUT3); 
	

	/* Input 4: Magnet Numbers (column vector) */
	nrowsDeviceNum = (int) mxGetM(INPUT4);
	ncolsDeviceNum = (int) mxGetN(INPUT4);
	if (!mxIsNumeric(INPUT4) || mxIsComplex(INPUT4) || 
		!mxIsDouble(INPUT4) ||
		ncolsDeviceNum != 1 || nrowsSectorNum != nrowsDeviceNum)
		mexErrMsgTxt("DeviceNum must be a column vector equal to SectorNum.");
	DeviceNum = mxGetPr(INPUT4);  


	if (FunctionType == 0) {      /* Get channels */
		/* Input 5: NumberOfAverages (int, scalar) */
		if (nrhs >= 5)
			NumberOfAverages = (int) mxChkGetScalar(INPUT5);
		else
			NumberOfAverages = 1;	


		/* Input 6: ChanTypeFlag (int, scalar) */
		if (nrhs >= 6)
			ChanTypeFlag = (int) mxChkGetScalar(INPUT6);
		else
			ChanTypeFlag = 0;	/* Default: AM */

		/* Input 7 */
		if (nrhs >= 7) {
			nrowst = (int) mxGetM(INPUT7);
			ncolst = (int) mxGetN(INPUT7);
			if (!mxIsNumeric(INPUT7) || mxIsComplex(INPUT7) || 
				!mxIsDouble(INPUT7) ||
				(nrowst != 1))
				mexErrMsgTxt("t must be a row vector.");
			t = mxGetPr(INPUT7);
		} else {
			nrowst = 1;
			ncolst = 1;
			t = &t0;
  		}



		/* Create output vectors */
		OUTPUT1 = mxCreateDoubleMatrix((unsigned int) nrowsDeviceNum, (unsigned int) ncolst, mxREAL);
		AM = mxGetPr(OUTPUT1);

		if (nlhs >= 2) {
			OUTPUT2 = mxCreateDoubleMatrix((unsigned int) nrowst, (unsigned int) ncolst, mxREAL);
			tout = mxGetPr(OUTPUT2);
		}


		/* Data Loop */
		Time0 = GetTime(); 
		for (i=0; i<ncolst; i++) {
			/* Delay between sample points */
			SleepTime = t[i] - (GetTime()-Time0) - .002;
			if (SleepTime > 0) {
				SleepTimeInt = (int)  (1000 * SleepTime);
				/* printf(" SleepTime = %f %d\n", SleepTime, SleepTimeInt); */
				sca_sleep(SleepTimeInt, 100000);
			}
			
			/* Get outputs */
			status = GetChannels(Family, SectorNum, DeviceNum, &(AM[i*nrowsDeviceNum]), nrowsDeviceNum, NumberOfAverages, ChanTypeFlag);

			if (nlhs >= 2)
				tout[i] = GetTime() - Time0;  
		}

		if (nlhs >= 3) {
			OUTPUT3 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL);
			ErrorFlag = mxGetPr(OUTPUT3);
			*ErrorFlag = (double) status;
		}

	} else if (FunctionType == 1) {       /* Set channels */
		if (nrhs < 5)
			mexErrMsgTxt("Atleast 5 input arguments needed for setting channels (alslink.c).");

		/* Input 5: Magnet Numbers (column vector) */
		nrowsNewSP = (int) mxGetM(INPUT5);
		ncolsNewSP = (int) mxGetN(INPUT5);
		if (!mxIsNumeric(INPUT5) || mxIsComplex(INPUT5) || 
			!mxIsDouble(INPUT5) ||
			ncolsDeviceNum != 1 || nrowsNewSP != nrowsDeviceNum)
			mexErrMsgTxt("NewSP must be a column vector equal to SectorNum & DeviceNum.");
		NewSP = mxGetPr(INPUT5);  


		/* Input 6: ChanTypeFlag (int, scalar) */
		if (nrhs >= 6)
			ChanTypeFlag = (int) mxChkGetScalar(INPUT6);
		else
			ChanTypeFlag = 1;	/* Default: AC */


		/* Input 7: WaitOnSPFlag (int, scalar) */
		if (nrhs >= 7)
			WaitOnSPFlag = (int) mxChkGetScalar(INPUT7);
		else
			WaitOnSPFlag = 1;	/* Default: wait */


		/* Create output vectors */
		if (nlhs >= 1) {
			OUTPUT1 = mxCreateDoubleMatrix((unsigned int) nrowsDeviceNum, (unsigned int) 1, mxREAL);
			AM = mxGetPr(OUTPUT1);
		}

		if (nlhs >= 2) {
			OUTPUT2 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL);
			tout = mxGetPr(OUTPUT2);
		}


		/* Data Loop */
		Time0 = GetTime(); 

		status = SetChannels(Family, SectorNum, DeviceNum, NewSP, nrowsDeviceNum, ChanTypeFlag, WaitOnSPFlag);
			
		if (nlhs >= 3) {
			OUTPUT3 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL);
			ErrorFlag = mxGetPr(OUTPUT3);
			*ErrorFlag = (double) status;
		}
		
		if (nlhs >= 1)
			status = GetChannels(Family, SectorNum, DeviceNum, AM, nrowsDeviceNum, 1, 0);

		if (nlhs >= 2)
			*tout = GetTime() - Time0;  


	} else
		mexErrMsgTxt("No function type defined.");
	

	mxFree(Family);
}
示例#16
0
BOOL ISndStreamMPEG::OpenStream(CString strFileName)
{
	DWORD	dwID3TagOffset = 0;
	INT		nXingTagOffset = 0;

	// Set buffer to hold maximum MP3 frame
	SetBufferSize( MAXSIZE_MP3FRAME );

	// Get the DLL functions
	m_hDLL=LoadLibrary("MpgLib.dll");

	// just for development purposes, try to load the DLL from the devo path
#ifdef _DEBUG
	if (m_hDLL==NULL)
		m_hDLL=LoadLibrary(g_config.GetAppPath()+"\\MpgLibDLL\\Debug\\MpgLib.dll");
#else
	if (m_hDLL==NULL)
		m_hDLL=LoadLibrary(g_config.GetAppPath()+"\\MpgLibDLL\\Release\\MpgLib.dll");
#endif
	if (m_hDLL==NULL)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	//Get pointer to functions 
	m_pOpenStream	=(MPGLIB_OPENSTREAM)GetProcAddress(m_hDLL,TEXT_MPGLIB_OPENSTREAM);
	m_pDecode		=(MPGLIB_DECODECHUNK)GetProcAddress(m_hDLL,TEXT_MPGLIB_DECODECHUNK);
	m_pCloseStream	=(MPGLIB_CLOSESTREAM)GetProcAddress(m_hDLL,TEXT_MPGLIB_CLOSESTREAM);
	m_pVersion		=(MPGLIB_VERSION)GetProcAddress(m_hDLL,TEXT_MPGLIB_VERSION);
	m_pGetBitRate	=(MPGLIB_GETBITRATE)GetProcAddress(m_hDLL,TEXT_MPGLIB_GETBITRATE);
	m_pFlush		=(MPGLIB_GETBITRATE)GetProcAddress(m_hDLL,TEXT_MPGLIB_FLUSH);

	// Check if all functions are available
	if ( (m_pOpenStream==NULL) || (m_pDecode==NULL) || (m_pCloseStream==NULL)|| (m_pVersion==NULL))
	{
		ASSERT(FALSE);
		return FALSE;
	}

	// Register the file name
	SetFileName(strFileName);



	// Get MP3 ID3V2 Tag offset
	CID3Tag	ID3Tag;

	ID3Tag.Init();
	ID3Tag.OpenFile( GetFileName() );
	ID3Tag.LoadTag();


	if ( ID3Tag.IsV2Tag() )  
	{
		dwID3TagOffset = ID3Tag.GetTagSize();
	}


	// Open MPEG stream
	if (! (m_pFile = fopen( GetFileName(), "rb" ) ) )
	{
		ASSERT(FALSE);
		return FALSE;
	}

	m_dwCurrentFilePos = 0;


	if ( dwID3TagOffset )
	{
		fseek(m_pFile, dwID3TagOffset, SEEK_SET );
	}		

	fread( m_pbDataInBuffer, 1024, 1, m_pFile );

	// Clear header information
	m_Header.Init();

	// get Xing VBR header if available
	if ( m_Header.ReadHeader( m_pbDataInBuffer, 1024, &nXingTagOffset ) == FALSE )
	{
		return FALSE;
	}

	// Extract properties from header information

	SetSampleRate( m_Header.GetSampleRate() );
	SetBitRate( m_Header.GetSampleRate() );

	// Get file size
	fseek( m_pFile, 0, SEEK_END );
	m_dwTotalFileSize= ftell( m_pFile );

	// seek back to beginning of stream
	fseek( m_pFile, dwID3TagOffset + nXingTagOffset, SEEK_SET );

	m_dwBytesToDo=m_dwTotalFileSize-nXingTagOffset-dwID3TagOffset;

	// Initialize MPEG structure
	m_pOpenStream(&m_hStream);

	SetChannels(m_Header.GetChannels());

	m_dwSkipBytes=1105*sizeof(SHORT)*m_Header.GetChannels();

	// Return Success
	return TRUE;
}
示例#17
0
int InitMachine(void)
{
  int J;

  /* Initialize variables */
  UseZoom       = UseZoom<1? 1:UseZoom>5? 5:UseZoom;
  InMenu        = 0;
  FastForward   = 0;
  OutImage.Data = 0;
  KeyReady      = 0;

  /* Initialize system resources */
  if (!InitQNX(Title,UseZoom*WIDTH,UseZoom*HEIGHT))
	  return 0;

  /* Set visual effects */
  BPSSetEffects(UseEffects);

  /* Create main image buffer */
  if(!NewImage(&OutImage,WIDTH,HEIGHT)) { TrashQNX(); return(0); }
  ClearImage(&OutImage,PIXEL(0,0,0));
  CropImage(&ScrImage,&OutImage,XOFFSET,YOFFSET,(TI83_FAMILY?5:4)*TIWIDTH,4*TIHEIGHT);

  /* Initialize video to main image */
  SetVideo(&OutImage,0,0,WIDTH,HEIGHT);

  /* Set colors */
  XPal[0] = White = PIXEL(255,255,255);
  XPal[1] = Black = PIXEL(0,0,0);

  /* Attach keyboard handler */
  SetKeyHandler(HandleKeys);

  /* Attach mouse handler */
  SetMouseHandler(HandleMouse);

  /* Initialize sound */
  InitSound(UseSound,150);
  SndSwitch=(1<<4)-1;
  SndVolume=255/4;
  SetChannels(SndVolume,SndSwitch);

  /* Initialize sync timer if needed */
  if((SyncFreq>0)&&!SetSyncTimer(SyncFreq*UPeriod/100)) SyncFreq=0;

	deviceinfo_details_t* data;
	deviceinfo_get_details(&data);
	const char* os = deviceinfo_details_get_device_os(data);

	if (strcmp(os, "BlackBerry 10") == 0)
	{
		int i = 0;
		while (TouchMap[i].KeyCode)
		{
			TouchMap[i].X = TouchMap[i].X * 1.28;
			TouchMap[i].W = TouchMap[i].W * 1.28;
			TouchMap[i].Y = TouchMap[i].Y * 1.25;
			TouchMap[i].H = TouchMap[i].H * 1.25;
			i++;
		}
	}

	deviceinfo_free_details(&data);

  /* Done */
  return(1);
}
示例#18
0
BOOL ISndStreamWinAmp::OpenStream( const CUString& strFileName )
{

	DWORD		i = 0;
	BOOL	bFound = FALSE;

	LTRACE2( _T( "ISndStreamWinAmp::OpenStream( %s )" ), strFileName );

	int nPos = 0;

	CUString strExt( _T( "wav" ) );

	g_bFinished = FALSE;
	g_bInitialized = FALSE;
	g_bOutOpened = FALSE;

	g_eFinished.ResetEvent();


	FlushFIFO( );


	nPos = strFileName.ReverseFind('.');

	if ( nPos >= 0  )
	{
		strExt = strFileName.Right( strFileName.GetLength() - nPos - 1  );
		strExt.MakeLower();
	}

	// Set the buffer size
	SetBufferSize( 9000 );

	SetFileName( strFileName );

	int nRet = 0;
	// loop through the available plugings 

	for ( i=0; i < gs_vWinAmpProps.size(); i++ )
	{
		m_WinAmpProp = gs_vWinAmpProps[i];


//		m_WinAmpProp.pModule->Init( );

		// check if the module can handle the file format
		if ( ( nRet = m_WinAmpProp.pModule->IsOurFile( (LPSTR)GetDosFileName( strFileName ) ) ) )
		{
			bFound = TRUE;
			break;
		}
/*
		if ( ( 0 == strExt.CompareNoCase( _T( "flac" ) ) ) && ( 0 == strExt.CompareNoCase(  m_WinAmpProp.strExt ) ) )
		{
			bFound = TRUE;
			break;
		}
*/
		CUString strPluginExt( m_WinAmpProp.pModule->FileExtensions, CP_UTF8 );
		strPluginExt.MakeLower();

		// check first on extention
		if ( strPluginExt.Find( strExt ) >=0 )
		{
			bFound = TRUE;
			break;
		}

//		m_WinAmpProp.pModule->Quit( );
	}

	if ( !bFound ) 
	{
		LTRACE2( _T( "ISndStreamWinAmp::OpenStream Failed, no proper plugin found!" ) );
		return FALSE;
	}

	if (   0 == m_WinAmpProp.pModule->UsesOutputPlug ) 
	{
		LTRACE2( _T( "ISndStreamWinAmp::OpenStream; Failed, does not use Output Plugin " ) );
		return FALSE;
	}

	LTRACE2( _T( "ISndStreamWinAmp::OpenStream found proper plugin ( %s )" ) , m_WinAmpProp.pModule->description );

	// setup proper function calls
	m_WinAmpProp.pModule->SetInfo = SetInfo;
	m_WinAmpProp.pModule->SAAddPCMData = SAAddPCMData;
	m_WinAmpProp.pModule->SAGetMode = SAGetMode;
	m_WinAmpProp.pModule->SAAdd = SAAdd;
	m_WinAmpProp.pModule->VSAAddPCMData = VSAAddPCMData;
	m_WinAmpProp.pModule->VSAGetMode = VSAGetMode;
	m_WinAmpProp.pModule->VSAAdd = VSAAdd;
	m_WinAmpProp.pModule->VSASetInfo = VSASetInfo;
	m_WinAmpProp.pModule->dsp_isactive = dsp_isactive;
	m_WinAmpProp.pModule->dsp_dosamples = dsp_dosamples;
	m_WinAmpProp.pModule->EQSet = EQSet;
	m_WinAmpProp.pModule->SAVSADeInit = WMIN_SAVSADeInit;
	m_WinAmpProp.pModule->SAVSAInit = WMIN_SAVSAInit;

	m_WinAmpProp.pModule->outMod = &g_OutModule;

	g_OutModule.version = OUT_VER;
	g_OutModule.description = g_lpszOutModuleName;
	g_OutModule.id = 33;

	g_OutModule.Config = OutConfig;
	g_OutModule.About = OutAbout;

	g_OutModule.Init = OutInit;
	g_OutModule.Quit = OutQuit;
	g_OutModule.Open = OutOpen;
	g_OutModule.Close = OutClose;
	g_OutModule.Write = OutWrite;
	g_OutModule.CanWrite = OutCanWrite;
	g_OutModule.IsPlaying = OutIsPlaying;
	g_OutModule.Pause = OutPause;
	g_OutModule.SetVolume = OutSetVolume;
	g_OutModule.SetPan = OutSetPan;
	g_OutModule.Flush = OutFlush;
	g_OutModule.GetOutputTime = OutGetOutputTime;
	g_OutModule.GetWrittenTime = OutGetWrittenTime;

	SetChannels( 2 );
	SetSampleRate( 44100 );
	SetBitRate( 176000 * 8 );
	
//	m_dwSamples=wfInfo.samples;

	m_dwTotalFileSize = 1000;
	m_dwCurrentFilePos = 0;


	// start the decoding thread
	if ( 0 != m_WinAmpProp.pModule->Play( (LPSTR)GetDosFileName( strFileName ) ) )
	{
		return FALSE;
	}

	// Wait till output device has been opened by the
	// input plugin
	while ( FALSE == g_bOutOpened )
	{
		::Sleep( 5 );
	}

	SetChannels( g_nNumChannels );
	SetSampleRate( g_nOutSampleRate );
	SetBitRate( g_nBitRate );

	g_bInitialized = TRUE;

	// return Success
	return TRUE;
}
示例#19
0
status_t OpenSoundDeviceEngine::AcceptFormatFor(int fmt, media_format &format, bool rec)
{
	status_t err;
	int afmt = 0;
	char buf[1024];
	CALLED();
	fmt &= rec ? Info()->iformats : Info()->oformats;

	if (fmt == 0)
		return B_MEDIA_BAD_FORMAT;
	media_format wc;
	err = WildcardFormatFor(fmt, wc);
	if (err < B_OK)
		return err;

	err = Open(rec ? OPEN_READ : OPEN_WRITE);
	if (err < B_OK)
		return err;

	if (format.type == B_MEDIA_RAW_AUDIO) {
		media_multi_audio_format &raw = format.u.raw_audio;

		// channel count
		raw.channel_count = MAX((unsigned)(Info()->min_channels), MIN((unsigned)(Info()->max_channels), raw.channel_count));
		err = SetChannels(raw.channel_count);
		if (err < B_OK) {
			Close();
			return err;
		}

		PRINT(("%s:step1  fmt=0x%08x, raw.format=0x%08lx\n", __FUNCTION__, fmt, raw.format));
		// if specified, try it
		if (raw.format)
			afmt = OpenSoundDevice::convert_media_format_to_oss_format(raw.format);
		afmt &= fmt;
		PRINT(("%s:step2 afmt=0x%08x\n", __FUNCTION__, afmt));
		// select the best as default
		if (afmt == 0) {
			afmt = OpenSoundDevice::select_oss_format(fmt);
			raw.format = OpenSoundDevice::convert_oss_format_to_media_format(afmt);
			//Close();
			//return B_MEDIA_BAD_FORMAT;
		}
		PRINT(("%s:step3 afmt=0x%08x\n", __FUNCTION__, afmt));
		// convert back
		raw.format = OpenSoundDevice::convert_oss_format_to_media_format(afmt);
		PRINT(("%s:step4 afmt=0x%08x, raw.format=0x%08lx\n", __FUNCTION__, afmt, raw.format));
		raw.valid_bits = OpenSoundDevice::convert_oss_format_to_valid_bits(afmt);

		err = SetFormat(afmt);
		if (err < B_OK) {
			Close();
			return err;
		}

		// endianness
		raw.byte_order = OpenSoundDevice::convert_oss_format_to_endian(afmt);

		// sample rate
		raw.frame_rate = OpenSoundDevice::select_oss_rate(Info(), raw.frame_rate);		// measured in Hertz
		//raw.frame_rate = OpenSoundDevice::convert_oss_rate_to_media_rate(Info()->max_rate);		// measured in Hertz
		err = SetSpeed(OpenSoundDevice::convert_media_rate_to_oss_rate(raw.frame_rate));
		if (err < B_OK) {
			Close();
			return err;
		}

		// retrieve the driver buffer size (it's important to do this
		// after all the other setup, since OSS may have adjusted it, and
		// also weird things happen if this ioctl() is done before other
		// setup itctl()s)
		audio_buf_info abinfo;
		memset(&abinfo, 0, sizeof(audio_buf_info));
		if (ioctl(fFD, SNDCTL_DSP_GETOSPACE, &abinfo, sizeof(audio_buf_info)) < 0) {
			fprintf(stderr, "failed to retrieve driver buffer size!\n");
			abinfo.bytes = 0;
		}
		fDriverBufferSize = abinfo.bytes;

		raw.buffer_size = fDriverBufferSize;

	} else if (format.type == B_MEDIA_ENCODED_AUDIO) {
		media_raw_audio_format &raw = format.u.encoded_audio.output;
		// XXX: do we really have to do this ?
		raw.channel_count = MAX((unsigned)(Info()->min_channels), MIN((unsigned)(Info()->max_channels), raw.channel_count));
		raw.byte_order = B_MEDIA_HOST_ENDIAN;
		raw.frame_rate = OpenSoundDevice::select_oss_rate(Info(), raw.frame_rate);		// measured in Hertz
		//raw.frame_rate = OpenSoundDevice::convert_oss_rate_to_media_rate(Info()->max_rate);		// measured in Hertz
		raw.buffer_size = DEFAULT_BUFFER_SIZE;

	} else {
		PRINT(("%s: unknown media type\n", __FUNCTION__));
		Close();
		return EINVAL;
	}
	// cache it
	fMediaFormat = format;

	string_for_format(format, buf, 1024);
	PRINT(("%s: %s\n", __FUNCTION__, buf));
	return B_OK;
}
示例#20
0
status_t OpenSoundDeviceEngine::SpecializeFormatFor(int fmt, media_format &format, bool rec)
{
	status_t err;
	int afmt = 0;
	CALLED();
	fmt &= rec ? Info()->iformats : Info()->oformats;
	if (fmt == 0)
		return B_MEDIA_BAD_FORMAT;
	media_format wc;
	err = WildcardFormatFor(fmt, wc);
	if (err < B_OK)
		return err;

	err = Open(rec ? OPEN_READ : OPEN_WRITE);
	if (err < B_OK)
		return err;

	if (format.type == B_MEDIA_RAW_AUDIO) {
		media_multi_audio_format &raw = format.u.raw_audio;

		PRINT(("%s:step1  fmt=0x%08x, raw.format=0x%08lx\n", __FUNCTION__, fmt, raw.format));
		// select the best as default
		if (!raw.format) {
			afmt = OpenSoundDevice::select_oss_format(fmt);
			raw.format = OpenSoundDevice::convert_oss_format_to_media_format(afmt);
		}
		// if specified, try it
		if (raw.format)
			afmt = OpenSoundDevice::convert_media_format_to_oss_format(raw.format);
		afmt &= fmt;
		PRINT(("%s:step2 afmt=0x%08x\n", __FUNCTION__, afmt));
		if (afmt == 0) {
			Close();
			return B_MEDIA_BAD_FORMAT;
		}
		// convert back
		raw.format = OpenSoundDevice::convert_oss_format_to_media_format(afmt);
		PRINT(("%s:step4 afmt=0x%08x, raw.format=0x%08lx\n", __FUNCTION__, afmt, raw.format));
		if (!raw.valid_bits)
			raw.valid_bits = OpenSoundDevice::convert_oss_format_to_valid_bits(afmt);
		if (raw.valid_bits != OpenSoundDevice::convert_oss_format_to_valid_bits(afmt)) {
			Close();
			return B_MEDIA_BAD_FORMAT;
		}

		err = SetFormat(afmt);
		if (err < B_OK) {
			Close();
			return err;
		}

		// endianness
		if (!raw.byte_order)
			raw.byte_order = OpenSoundDevice::convert_oss_format_to_endian(afmt);
		if ((int)raw.byte_order != OpenSoundDevice::convert_oss_format_to_endian(afmt)) {
			Close();
			return B_MEDIA_BAD_FORMAT;
		}

		// channel count
		if (raw.channel_count == 0)
			raw.channel_count = (unsigned)Info()->min_channels;
		if ((int)raw.channel_count < Info()->min_channels
			|| (int)raw.channel_count > Info()->max_channels)
			return B_MEDIA_BAD_FORMAT;
		err = SetChannels(raw.channel_count);
		if (err < B_OK) {
			Close();
			return err;
		}

		// sample rate
		if (!raw.frame_rate)
			raw.frame_rate = Info()->max_rate;
		//raw.frame_rate = OpenSoundDevice::convert_oss_rate_to_media_rate(Info()->max_rate);		// measured in Hertz
		err = SetSpeed(OpenSoundDevice::convert_media_rate_to_oss_rate(raw.frame_rate));
		if (err < B_OK) {
			Close();
			return err;
		}

#if 0
		raw.buffer_size = DEFAULT_BUFFER_SIZE
						* (raw.format & media_raw_audio_format::B_AUDIO_SIZE_MASK)
						* raw.channel_count;
#endif
		audio_buf_info abinfo;
		if (ioctl(fFD, rec?SNDCTL_DSP_GETISPACE:SNDCTL_DSP_GETOSPACE, &abinfo, sizeof(abinfo)) < 0) {
			PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n",
				__FUNCTION__, "SNDCTL_DSP_GET?SPACE", strerror(errno)));
			return -1;
		}
		PRINT(("OSS: %cSPACE: { bytes=%d, fragments=%d, fragsize=%d, fragstotal=%d }\n", rec?'I':'O', abinfo.bytes, abinfo.fragments, abinfo.fragsize, abinfo.fragstotal));
		// cache the first one in the Device
		// so StartThread() knows the number of frags
		//if (!fFragments.fragstotal)
		//	memcpy(&fFragments, &abinfo, sizeof(abinfo));

		// make sure buffer size is less than the driver's own buffer ( /2 to keep some margin )
		if (/*rec && raw.buffer_size &&*/ (int)raw.buffer_size > abinfo.fragsize * abinfo.fragstotal / 4)
			return B_MEDIA_BAD_FORMAT;
		if (!raw.buffer_size)
			raw.buffer_size = abinfo.fragsize;//XXX
/*						* (raw.format & media_raw_audio_format::B_AUDIO_SIZE_MASK)
						* raw.channel_count;*/
	} else if (format.type == B_MEDIA_ENCODED_AUDIO) {
		media_raw_audio_format &raw = format.u.encoded_audio.output;
		// XXX: do we really have to do this ?
		raw.channel_count = MAX((unsigned)(Info()->min_channels), MIN((unsigned)(Info()->max_channels), raw.channel_count));
		raw.byte_order = B_MEDIA_HOST_ENDIAN;
		raw.frame_rate = OpenSoundDevice::select_oss_rate(Info(), raw.frame_rate);		// measured in Hertz
		//raw.frame_rate = OpenSoundDevice::convert_oss_rate_to_media_rate(Info()->max_rate);		// measured in Hertz
		raw.buffer_size = DEFAULT_BUFFER_SIZE;

	} else {
		Close();
		return EINVAL;
	}
	// cache it
	fMediaFormat = format;
	char buf[1024];
	string_for_format(format, buf, 1024);
	PRINT(("%s: %s\n", __FUNCTION__, buf));
	return B_OK;
}
示例#21
0
BOOL ISndStreamWAV::OpenStream( const CUString& strFileName )
{
    SF_INFO wfInfo;

    LTRACE( _T( "ISndStreamWAV::OpenStream( %s )" ), strFileName );

    // Set the buffer size
    SetBufferSize(12000);

    memset(&wfInfo,0,sizeof(SF_INFO));

    SetFileName(strFileName);

    // Open stream
    CUStringConvert strCnv;

#ifdef _UNICODE
    m_pSndFile = sf_open((const tchar*)strCnv.ToT( GetFileName() ),
                         SFM_READ,
                         &wfInfo );
#else
    m_pSndFile = sf_open(	strCnv.ToT( GetFileName() ),
                            SFM_READ,
                            &wfInfo );
#endif

    if ( NULL == m_pSndFile )
    {
        LTRACE( _T( "ISndStreamWAV::OpenStream( %s ) failed" ), strFileName );
        ASSERT(FALSE);
        return FALSE;
    }

    SetChannels( wfInfo.channels );
    SetSampleRate(wfInfo.samplerate);


    WORD wBitsPerSample = 0;
    switch ( wfInfo.format & SF_FORMAT_SUBMASK )
    {
    case SF_FORMAT_PCM_S8:
        wBitsPerSample = 8;
        break;
    case SF_FORMAT_PCM_16:
        wBitsPerSample = 16;
        break;
    case SF_FORMAT_PCM_24:
        wBitsPerSample = 24;
        break;
    case SF_FORMAT_PCM_32:
        wBitsPerSample = 32;
        break;
    default:
        wBitsPerSample = 16;
        ASSERT( FALSE );
    }

    SetBitRate( wfInfo.samplerate * wfInfo.channels * wBitsPerSample );

    m_dwSamples = (DWORD)wfInfo.frames;

    m_ddwTotalFileSize = sf_seek( m_pSndFile, 0, SEEK_END ) * wfInfo.channels * ( wBitsPerSample / 8 );

    m_ddwCurrentFilePos = 0;

    sf_seek( m_pSndFile, 0, SEEK_SET );

    // return Success
    return TRUE;
}