Esempio n. 1
0
bool CClientSound::SetFxEffect ( int iFxEffect, bool bEnable )
{
    if ( m_pSound )
    {
        if ( iFxEffect >= 0 )
        {
            if ( bEnable )
            {
                if ( !m_FxEffects[iFxEffect] )
                {
                    m_FxEffects[iFxEffect] = BASS_ChannelSetFX ( m_pSound, iFxEffect, 0 );
                    if ( m_FxEffects[iFxEffect] )
                        return true;
                }
            }
            else
            {
                if ( BASS_ChannelRemoveFX ( m_pSound, m_FxEffects[iFxEffect] ) )
                {
                    m_FxEffects[iFxEffect] = 0;
                    return true;
                }
            }
        }
    }
    return false;
}
Esempio n. 2
0
bool TEffect::ApplyInternal(bass_p pChannel)
{
	if (IsRemoved()) return false;
	bUpdated = true;

	iErrorCode = BASS_OK;

	if (eType == BASS_FX_UNKNOWN)
	{
		iErrorCode = BASS_ERROR_ILLPARAM;
		return false;
	}

	if (pChannel == BASS_NULL)
	{
		iErrorCode = BASS_ERROR_HANDLE;
		return false;
	}

	bass_p pOldChannel = this->pChannel;

	if (pOldChannel != pChannel)
	{
		this->pChannel = pChannel;

		if (pOldChannel != BASS_NULL && pFX != BASS_NULL)
		{
			BASS_ChannelRemoveFX(pOldChannel, pFX);
			pFX = BASS_NULL;
		}
	}
	else
	{
		if (pFX != BASS_NULL && bEnabled)
		{
			return true;
		}
	}

	if (!bEnabled)
	{
		RemoveFX();
		return true;
	}

	pFX = BASS_ChannelSetFX(pChannel, eType, 0);
	iErrorCode = BASS_ErrorGetCode();

	if (iErrorCode != BASS_OK)
	{
		RemoveFX();
		return false;
	}

	UpdateInternal();
	ResetInternal();
	return true;
}
Esempio n. 3
0
void FXToggled(GtkToggleButton *obj, gpointer data)
{ // toggle effects
	const gchar *objname=gtk_widget_get_name(GTK_WIDGET(obj));
	int n=atoi(objname+2);
	if (fx[n]) {
		BASS_ChannelRemoveFX(stream,fx[n]);
		fx[n]=0;
	} else
		fx[n]=BASS_ChannelSetFX(stream,fxtype[n],0);
}
Esempio n. 4
0
void TEffect::RemoveFX()
{
	if (pChannel != BASS_NULL && pFX != BASS_NULL)
	{
		BASS_ChannelRemoveFX(pChannel, pFX);
	}

	ResetInternal();

	pFX = BASS_NULL;
	bUpdated = true;
}
Esempio n. 5
0
HFX CALLBACK SetCustFX (DWORD chan, DWORD type, int priority) {
if (type!=CUST_FX_TYPE_ID) return NULL;
BASS_CHANNELINFO info;
BASS_ChannelGetInfo(chan, &info);
HCustFX* hc = malloc(sizeof(HCustFX));
if (!hc) return NULL;
hc->flags = info.flags&( BASS_SAMPLE_FLOAT | BASS_SAMPLE_8BITS );
hc->push = BASS_StreamCreate(info.freq, info.chans, hc->flags | BASS_STREAM_DECODE, STREAMPROC_PUSH, NULL);
hc->pitch = BASS_FX_TempoCreate(hc->push, BASS_STREAM_DECODE);
HFX hfx = bassfunc->SetFX(chan, CustFXDSPProc, hc, priority, &CustFXFuncs);
if (hfx&&hc->pitch&&hc->push) return hfx;
if (hfx) BASS_ChannelRemoveFX(chan, hfx);
if (hc->pitch) BASS_StreamFree(hc->pitch);
if (hc->push) BASS_StreamFree(hc->push);
free(hc);
return NULL;
}
Esempio n. 6
0
//
// Copy state stored in m_EnabledEffects to actual BASS sound
//
void CBassAudio::ApplyFxEffects(void)
{
    for (uint i = 0; i < NUMELMS(m_FxEffects) && NUMELMS(m_EnabledEffects); i++)
    {
        if (m_EnabledEffects[i] && !m_FxEffects[i])
        {
            // Switch on
            m_FxEffects[i] = BASS_ChannelSetFX(m_pSound, i, 0);
            if (!m_FxEffects[i])
                m_FxEffects[i] = INVALID_FX_HANDLE;
        }
        else if (!m_EnabledEffects[i] && m_FxEffects[i])
        {
            // Switch off
            if (m_FxEffects[i] != INVALID_FX_HANDLE)
                BASS_ChannelRemoveFX(m_pSound, m_FxEffects[i]);
            m_FxEffects[i] = 0;
        }
    }
}
Esempio n. 7
0
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	DWORD a=0;
	float freq;
	char c[30];

	BASS_BFX_PEAKEQ eq;		// dsp peaking equalizer
	BASS_BFX_PHASER phs;	// dsp phaser

	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case ID_OPEN:
					{
						char file[MAX_PATH]="";
						ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0";
						ofn.lpstrFile=file;
						if (GetOpenFileName(&ofn)) {
							memcpy(path,file,ofn.nFileOffset);
							path[ofn.nFileOffset-1]=0;

							// free previous dsp effects & handles
							BASS_StreamFree(chan);	// free stream
							BASS_MusicFree(chan);	// free music

							if(!(chan=BASS_StreamCreateFile(FALSE, file, 0, 0, BASS_SAMPLE_LOOP|floatable))&&
								!(chan=BASS_MusicLoad(FALSE, file, 0, 0, BASS_MUSIC_LOOP|BASS_MUSIC_RAMP|floatable,0))){
								// not a WAV/MP3 or MOD
								MESS(ID_OPEN,WM_SETTEXT,0,"click here to open a file && play it...");
								Error("Selected file couldnt be loaded!");
								break;
							}

							// update the Button to show the loaded file name
							MESS(ID_OPEN,WM_SETTEXT,0,GetFileName(file));

							// set dsp effects
							SendMessage(win,WM_COMMAND,IDC_CHKEQ,l);
							SendMessage(win,WM_COMMAND,IDC_CHKPHS,l);

							// get current sample rate
							BASS_ChannelGetAttribute(chan, BASS_ATTRIB_FREQ, &freq);
							oldfreq = freq;

							// set the dx sample rate & view
							MESS(IDC_DXRATE,TBM_SETRANGEMAX,0,(long)(freq * 1.3f));
							MESS(IDC_DXRATE,TBM_SETRANGEMIN,0,(long)(freq * 0.7f));
							MESS(IDC_DXRATE,TBM_SETPOS,TRUE,(long)freq);
							MESS(IDC_DXRATE,TBM_SETPAGESIZE,0,(long)(freq * 0.01f));	// by 1%

							sprintf(c,"DirectX Samplerate = %dHz", (long)freq);
							MESS(IDC_SDXRATE,WM_SETTEXT,0,c);

							// play it!
							BASS_ChannelPlay(chan, FALSE);
						}
					}
					return 1;

				case IDC_CHKEQ:
					if (MESS(IDC_CHKEQ,BM_GETCHECK,0,0))
						SetDSP_EQ(0.0f, 2.5f, 0.0f, 125.0f, 1000.0f, 8000.0f);
					else
						BASS_ChannelRemoveFX(chan, fxEQ);
				return 1;

				case IDC_CHKPHS:
					if(MESS(IDC_CHKPHS,BM_GETCHECK,0,0)){
						fxPhaser=BASS_ChannelSetFX(chan, BASS_FX_BFX_PHASER,0);

						BASS_FXGetParameters(fxPhaser, &phs);
							phs.fWetMix = (float)MESS(IDC_WETMIX,TBM_GETPOS,0,0) / 1000.0f;
							phs.fDryMix = (float)MESS(IDC_DRYMIX,TBM_GETPOS,0,0) / 1000.0f;
							phs.fFeedback = (float)MESS(IDC_FEEDBACK,TBM_GETPOS,0,0) / 1000.0f;
							phs.fRate = (float)MESS(IDC_RATE,TBM_GETPOS,0,0) / 10.0f;
							phs.fRange = (float)MESS(IDC_RANGE,TBM_GETPOS,0,0) / 10.0f;
							phs.fFreq = (float)MESS(IDC_FREQ,TBM_GETPOS,0,0) / 10.0f;
						BASS_FXSetParameters(fxPhaser, &phs);
					}else
						BASS_ChannelRemoveFX(chan, fxPhaser);
				return 1;

			}
			return 1;

		case WM_VSCROLL:
			if(l){
				UpdateFX(GetDlgCtrlID((HWND)l)-IDC_SLDEQ1);
			}
		return 1;

		case WM_HSCROLL:
			if(!BASS_ChannelIsActive(chan)) break;

			switch (GetDlgCtrlID((HWND)l)) {
				case IDC_DXRATE:
					BASS_ChannelSetAttribute(chan, BASS_ATTRIB_FREQ, (float)MESS(IDC_DXRATE, TBM_GETPOS, 0, 0));

					sprintf(c,"DirectX Samplerate = %dHz", MESS(IDC_DXRATE, TBM_GETPOS, 0, 0));
					MESS(IDC_SDXRATE,WM_SETTEXT,0,c);

					// update all bands fCenters after changing samplerate
					{
						int i;
						for(i=0;i<3;i++){
							eq.lBand = i;
							BASS_FXGetParameters(fxEQ, &eq);
								eq.fCenter = eq.fCenter * (float)MESS(IDC_DXRATE, TBM_GETPOS, 0, 0) / oldfreq;
							BASS_FXSetParameters(fxEQ, &eq);
						}
						oldfreq = (float)MESS(IDC_DXRATE, TBM_GETPOS, 0, 0);
					}
				break;

				case IDC_DRYMIX:
				case IDC_WETMIX:
				case IDC_FEEDBACK:
				case IDC_RATE:
				case IDC_RANGE:
				case IDC_FREQ:
					BASS_FXGetParameters(fxPhaser, &phs);
						phs.fWetMix = (float)MESS(IDC_WETMIX,TBM_GETPOS,0,0) / 1000.0f;
						phs.fDryMix = (float)MESS(IDC_DRYMIX,TBM_GETPOS,0,0) / 1000.0f;
						phs.fFeedback = (float)MESS(IDC_FEEDBACK,TBM_GETPOS,0,0) / 1000.0f;
						phs.fRate = (float)MESS(IDC_RATE,TBM_GETPOS,0,0) / 10.0f;
						phs.fRange = (float)MESS(IDC_RANGE,TBM_GETPOS,0,0) / 10.0f;
						phs.fFreq = (float)MESS(IDC_FREQ,TBM_GETPOS,0,0) / 10.0f;
					BASS_FXSetParameters(fxPhaser, &phs);
			}
			return 1;

		case WM_INITDIALOG:
			win=h;
			GetCurrentDirectory(MAX_PATH,path);
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.hInstance=inst;
			ofn.nMaxFile=MAX_PATH;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;

			// enable floating-point DSP
			BASS_SetConfig(BASS_CONFIG_FLOATDSP, TRUE);

			// setup output - default device, 44100hz, stereo, 16 bits
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				return 1;
			}

			// check for floating-point capability
			floatable = BASS_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT, 0, 0);
			if (floatable) {
				BASS_StreamFree(floatable);  //woohoo!
			    floatable = BASS_SAMPLE_FLOAT;
			}

			// initialize dsp eq sliders
			MESS(IDC_SLDEQ1,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(IDC_SLDEQ1,TBM_SETPOS,TRUE,10);

			MESS(IDC_SLDEQ2,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(IDC_SLDEQ2,TBM_SETPOS,TRUE,10);

			MESS(IDC_SLDEQ3,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(IDC_SLDEQ3,TBM_SETPOS,TRUE,10);

			// dx rate
			MESS(IDC_DXRATE,TBM_SETRANGEMAX,0,(long)(44100.0f*1.3f));
			MESS(IDC_DXRATE,TBM_SETRANGEMIN,0,(long)(44100.0f*0.7f));
			MESS(IDC_DXRATE,TBM_SETPOS,TRUE,44100);
			MESS(IDC_DXRATE,TBM_SETPAGESIZE,0,(long)(44100.0f*0.01f));	// by 1%

			// DryMix
			MESS(IDC_DRYMIX,TBM_SETRANGE,0,MAKELONG(-2000,2000));
			MESS(IDC_DRYMIX,TBM_SETPOS,TRUE,-999);

			// WetMix
			MESS(IDC_WETMIX,TBM_SETRANGE,0,MAKELONG(-2000,2000));
			MESS(IDC_WETMIX,TBM_SETPOS,TRUE,999);

			// Feedback
			MESS(IDC_FEEDBACK,TBM_SETRANGE,0,MAKELONG(-1000,1000));
			MESS(IDC_FEEDBACK,TBM_SETPOS,TRUE,-60);

			// Rate
			MESS(IDC_RATE,TBM_SETRANGE,0,MAKELONG(0,100));
			MESS(IDC_RATE,TBM_SETPOS,TRUE,2);

			// Range
			MESS(IDC_RANGE,TBM_SETRANGE,0,MAKELONG(0,100));
			MESS(IDC_RANGE,TBM_SETPOS,TRUE,60);

			// Freq
			MESS(IDC_FREQ,TBM_SETRANGE,0,MAKELONG(0,10000));
			MESS(IDC_FREQ,TBM_SETPOS,TRUE,1000);

			Font=CreateFont(-12,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_STRING_PRECIS,
				            CLIP_STROKE_PRECIS,DRAFT_QUALITY,DEFAULT_PITCH | FF_DONTCARE,
							"MS Sans Serif");
			// set the font for check boxes
			MESS(IDC_CHKEQ, WM_SETFONT, Font, TRUE);
			MESS(IDC_CHKPHS,WM_SETFONT, Font, TRUE);
		return 1;

		case WM_CLOSE:
			EndDialog(h,0);
			return 0;
		break;
	}
	return 0;
}
Esempio n. 8
0
void main(int argc, char **argv)
{
	const char *fxname[9]={"CHORUS","COMPRESSOR","DISTORTION","ECHO",
		"FLANGER","GARGLE","I3DL2REVERB","PARAMEQ","REVERB"};
	HFX fx[9]={0}; // effect handles
	INPUT_RECORD keyin;
	DWORD r,buflen;

	printf("BASS Simple Sinewave Synth\n"
			"--------------------------\n");

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		printf("An incorrect version of BASS.DLL was loaded");
		return;
	}

	// 10ms update period
	BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD,10);

	// setup output - get latency
	if (!BASS_Init(-1,44100,BASS_DEVICE_LATENCY,0,NULL))
		Error("Can't initialize device");

	BASS_GetInfo(&info);
	// default buffer size = update period + 'minbuf' + 1ms extra margin
	BASS_SetConfig(BASS_CONFIG_BUFFER,10+info.minbuf+1);
	buflen=BASS_GetConfig(BASS_CONFIG_BUFFER);
	// if the device's output rate is unknown default to 44100 Hz
	if (!info.freq) info.freq=44100;
	// create a stream, stereo so that effects sound nice
	stream=BASS_StreamCreate(info.freq,2,0,(STREAMPROC*)WriteStream,0);

	printf("device latency: %dms\n",info.latency);
	printf("device minbuf: %dms\n",info.minbuf);
	printf("ds version: %d (effects %s)\n",info.dsver,info.dsver<8?"disabled":"enabled");
	printf("press these keys to play:\n\n"
		"  2 3  5 6 7  9 0  =\n"
		" Q W ER T Y UI O P[ ]\n\n"
		"press -/+ to de/increase the buffer\n"
		"press spacebar to quit\n\n");
	if (info.dsver>=8) // DX8 effects available
		printf("press F1-F9 to toggle effects\n\n");
	printf("using a %dms buffer\r",buflen);

	BASS_ChannelPlay(stream,FALSE);

	while (ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE),&keyin,1,&r)) {
		int key;
		if (keyin.EventType!=KEY_EVENT) continue;
		if (keyin.Event.KeyEvent.wVirtualKeyCode==VK_SPACE) break;
		if (keyin.Event.KeyEvent.bKeyDown) {
			if (keyin.Event.KeyEvent.wVirtualKeyCode==VK_SUBTRACT
				|| keyin.Event.KeyEvent.wVirtualKeyCode==VK_ADD) {
				// recreate stream with smaller/larger buffer
				BASS_StreamFree(stream);
				if (keyin.Event.KeyEvent.wVirtualKeyCode==VK_SUBTRACT)
					BASS_SetConfig(BASS_CONFIG_BUFFER,buflen-1); // smaller buffer
				else 
					BASS_SetConfig(BASS_CONFIG_BUFFER,buflen+1); // larger buffer
				buflen=BASS_GetConfig(BASS_CONFIG_BUFFER);
				printf("using a %dms buffer\t\t\r",buflen);
				stream=BASS_StreamCreate(info.freq,2,0,(STREAMPROC*)WriteStream,0);
				// set effects on the new stream
				for (r=0;r<9;r++) if (fx[r]) fx[r]=BASS_ChannelSetFX(stream,BASS_FX_DX8_CHORUS+r,0);
				BASS_ChannelPlay(stream,FALSE);
			}
			if (keyin.Event.KeyEvent.wVirtualKeyCode>=VK_F1
				&& keyin.Event.KeyEvent.wVirtualKeyCode<=VK_F9) {
				r=keyin.Event.KeyEvent.wVirtualKeyCode-VK_F1;
				if (fx[r]) {
					BASS_ChannelRemoveFX(stream,fx[r]);
					fx[r]=0;
					printf("effect %s = OFF\t\t\r",fxname[r]);
				} else {
					// set the effect, not bothering with parameters (use defaults)
					if (fx[r]=BASS_ChannelSetFX(stream,BASS_FX_DX8_CHORUS+r,0))
						printf("effect %s = ON\t\t\r",fxname[r]);
				}
			}
		}
		for (key=0;key<KEYS;key++)
			if (keyin.Event.KeyEvent.wVirtualKeyCode==keys[key]) {
				if (keyin.Event.KeyEvent.bKeyDown && vol[key]<MAXVOL) {
					pos[key]=0;
					vol[key]=MAXVOL+DECAY/2; // start key (setting "vol" slightly higher than MAXVOL to cover any rounding-down)
				} else if (!keyin.Event.KeyEvent.bKeyDown && vol[key])
					vol[key]-=DECAY; // trigger key fadeout
				break;
			}
	}

	BASS_Free();
}
Esempio n. 9
0
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	switch (m) {
		case WM_TIMER:
			{ // display current latency (input+output buffer level)
				char buf[20];
				latency=(latency*3+BASS_ChannelGetData(chan,NULL,BASS_DATA_AVAILABLE)
					+BASS_ChannelGetData(rchan,NULL,BASS_DATA_AVAILABLE))/4;
				sprintf(buf,"%d",(int)(BASS_ChannelBytes2Seconds(chan,latency)*1000));
				MESS(15,WM_SETTEXT,0,buf);
			}
			break;

		case WM_COMMAND:
			switch (LOWORD(w)) {
				case IDCANCEL:
					DestroyWindow(h);
					break;
				case 10:
					if (HIWORD(w)==CBN_SELCHANGE) { // input selection changed
						int i;
						float level;
						input=MESS(10,CB_GETCURSEL,0,0); // get the selection
						for (i=0;BASS_RecordSetInput(i,BASS_INPUT_OFF,-1);i++) ; // 1st disable all inputs, then...
						BASS_RecordSetInput(input,BASS_INPUT_ON,-1); // enable the selected input
						BASS_RecordGetInput(input,&level); // get the level
						MESS(11,TBM_SETPOS,TRUE,level*100);
					}
					break;
				case 20: // toggle chorus
					if (fx[0]) {
						BASS_ChannelRemoveFX(chan,fx[0]);
						fx[0]=0;
					} else
						fx[0]=BASS_ChannelSetFX(chan,BASS_FX_DX8_CHORUS,0);
					break;
				case 21: // toggle gargle
					if (fx[1]) {
						BASS_ChannelRemoveFX(chan,fx[1]);
						fx[1]=0;
					} else
						fx[1]=BASS_ChannelSetFX(chan,BASS_FX_DX8_GARGLE,0);
					break;
				case 22: // toggle reverb
					if (fx[2]) {
						BASS_ChannelRemoveFX(chan,fx[2]);
						fx[2]=0;
					} else
						fx[2]=BASS_ChannelSetFX(chan,BASS_FX_DX8_REVERB,0);
					break;
				case 23: // toggle flanger
					if (fx[3]) {
						BASS_ChannelRemoveFX(chan,fx[3]);
						fx[3]=0;
					} else
						fx[3]=BASS_ChannelSetFX(chan,BASS_FX_DX8_FLANGER,0);
					break;
			}
			break;

		case WM_HSCROLL:
			if (l) { // set input source level
				float level=SendMessage((HWND)l,TBM_GETPOS,0,0)/100.f;
				if (!BASS_RecordSetInput(input,0,level)) // failed to set input level
					BASS_RecordSetInput(-1,0,level); // try master level instead
			}
			break;

		case WM_INITDIALOG:
			win=h;
			MESS(11,TBM_SETRANGE,FALSE,MAKELONG(0,100)); // initialize input level slider
			MessageBox(win,
				"Do not set the input to 'WAVE' / 'What you hear' (etc...) with\n"
				"the level set high, as that is likely to result in nasty feedback.\n",
				"Feedback warning",MB_ICONWARNING);
			if (!Initialize()) {
				DestroyWindow(win);
				break;
			}
			SetTimer(h,1,250,NULL);
			return 1;

		case WM_DESTROY:
			KillTimer(h,1);
			// release it all
			BASS_RecordFree();
			BASS_Free();
			break;
	}
	return 0;
}
HRESULT CBSoundBuffer::ApplyFX(TSFXType Type, float Param1, float Param2, float Param3, float Param4)
{
	switch(Type)
	{
	case SFX_ECHO:
#ifdef USE_BASS_FX
		if (m_EffectHandle != 0)
		{
			BASS_ChannelRemoveFX(m_Stream, m_EffectHandle);
		}
		m_EffectHandle = BASS_ChannelSetFX(
			m_Stream,
			BASS_FX_BFX_ECHO4,
			0);

		if (m_EffectHandle != 0) 
		{
			BASS_BFX_ECHO4 params;
			/*
			 * try to be as close as possible to the DSFX echo, it will never be perfect though
			 * 
			 * fDryMix = reverse of fWetDryMix (scaled from 0..100 into 0..1)
			 * fWetMix = fWetDryMix (converted from logarithmic to linear) 
			 * fDelay  = mean of fLeftDelay and fRightDelay (converted from milliseconds to seconds)
			 * ignored = fFeedback (the BASS feedback parameter is used to create reverb)
			 */
			params.fDryMix = ((100.0f - Param1) / 100.0f);
			params.fWetMix = (Param1 / 100.0f);
			params.fFeedback = 0;
			params.fDelay = (Param3 + Param4) / 2.0f / 1000.0f;
			params.bStereo = false;
			params.lChannel = BASS_BFX_CHANALL;

			Game->LOG(0, "Echo params: Dry=%.2f Wet=%.2f Fedback=%.2f Delay=%.2f", params.fDryMix, params.fWetMix, params.fFeedback, params.fDelay);

			BOOL status = BASS_FXSetParameters(
				m_EffectHandle,
				(void *) &params);

			Game->LOG(0, "Echo status=%s", (status == TRUE) ? "OK" : "ERROR");
			if (status == FALSE)
			{
				Game->LOG(0, "Echo error=%d", BASS_ErrorGetCode());
			}
		}
#endif
		break;

	case SFX_REVERB:
#ifdef USE_BASS_FX
		if (m_EffectHandle != 0)
		{
			BASS_ChannelRemoveFX(m_Stream, m_EffectHandle);
		}	
		m_EffectHandle = BASS_ChannelSetFX(
			m_Stream,
			BASS_FX_BFX_ECHO4,
			0);
		if (m_EffectHandle != 0) 
		{
			BASS_BFX_ECHO4 params;
			/*
			 * try to be as close as possible to the DSFX reverb, it will never be perfect though
			 * 
			 * fDryMix = fInGain (converted from logarithmic to linear)
			 * fWetMix = fReverbMix (converted from logarithmic to linear) multiplied ("attenuated") with fDryMix
			 * fDelay  = fReverbTime (converted from milliseconds to seconds)
			 * ignored = fHighFreqRTRatio (no equivalent in BASS)
			 */
			params.fDryMix = pow(10.0f, (Param1 / 10.0f));
			params.fWetMix = pow(10.0f, (Param2 / 10.0f)) * params.fDryMix;
			params.fFeedback = 0.7f;
			params.fDelay = ((Param3 / 1000.0f) / 10.0f);

			// test a different approach, where only the feedback parameter is affected by the fReverbTime
			params.fDryMix = 0.999f;
			params.fWetMix = 0.7f;
			params.fFeedback = 0.5f + ((Param3 / 3000.0f) * 0.2f);
			params.fDelay = 0.005f;

			params.bStereo = false;
			params.lChannel = BASS_BFX_CHANALL;

			Game->LOG(0, "Reverb params: Dry=%.2f Wet=%.2f Fedback=%.2f Delay=%.2f", params.fDryMix, params.fWetMix, params.fFeedback, params.fDelay);

			BOOL status = BASS_FXSetParameters(
				m_EffectHandle,
				(void *) &params);

			Game->LOG(0, "Reverb status=%s", (status == TRUE) ? "OK" : "ERROR");
			if (status == FALSE)
			{
				Game->LOG(0, "Reverb error=%d", BASS_ErrorGetCode());
			}
		}
#endif
		break;

	case SFX_REVERB_PRESET:
		// TODO need to check whether context is already in use
#ifdef USE_LIBEFFECTS_REVERB
		int status;
		uint32_t replyCount;
		char replydata[8];

		m_context.hInstance  = NULL;
		m_context.boolAuxiliary  = 0;

	    m_context.boolPreset     = 1;
	    m_context.curPreset  = REVERB_PRESET_LAST + 1;

	    switch (int (Param1))
	    {
	    case 0:
	    	m_context.nextPreset = REVERB_PRESET_NONE;
	    	break;
	    case 1:
	    	m_context.nextPreset = REVERB_PRESET_SMALLROOM;
	    	break;
	    case 2:
	    	m_context.nextPreset = REVERB_PRESET_MEDIUMROOM;
	    	break;
	    case 3:
	    	m_context.nextPreset = REVERB_PRESET_LARGEROOM;
	    	break;
	    case 4:
	    	m_context.nextPreset = REVERB_PRESET_MEDIUMHALL;
	    	break;
	    case 5:
	    	m_context.nextPreset = REVERB_PRESET_LARGEHALL;
	    	break;
	    case 6:
	    	m_context.nextPreset = REVERB_PRESET_PLATE;
	    	break;
	    default:
	    	m_context.nextPreset = REVERB_PRESET_NONE;
	    	break;
	    }

		Game->LOG(0, "====> Next preset=%d.\n", m_context.nextPreset);

		status = Reverb_init(&m_context);

		if (status != 0)
		{
			Game->LOG(0, "Reverb init error=%d", status);
			return S_FALSE;
		}

		m_context.config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_WRITE;

	    m_context.InFrames32  = (LVM_INT32 *)malloc(LVREV_MAX_FRAME_SIZE * sizeof(LVM_INT32) * 2);

		if (m_context.InFrames32 == NULL)
		{
			Game->LOG(0, "Reverb malloc failed (1)!");
			Reverb_free(&m_context);
			m_context.hInstance = NULL;
			return S_FALSE;
		}
		else
		{
			// Game->LOG(0, "Malloc inframes addr 0x%08X!", (uint32_t*) m_context.InFrames32);
		}

	    m_context.OutFrames32 = (LVM_INT32 *)malloc(LVREV_MAX_FRAME_SIZE * sizeof(LVM_INT32) * 2);

		if (m_context.OutFrames32 == NULL)
		{
			Game->LOG(0, "Reverb malloc failed (2)!");
			free(m_context.InFrames32);
			Reverb_free(&m_context);
			m_context.hInstance = NULL;
			return S_FALSE;
		}
		else
		{
			// Game->LOG(0, "Malloc outframes addr 0x%08X!", (uint32_t*) m_context.OutFrames32);
		}

	    replyCount = sizeof(int);

	    status = Reverb_command(&m_context, EFFECT_CMD_ENABLE, 0, NULL, &replyCount, replydata);

		if (status != 0)
		{
			Game->LOG(0, "Reverb command error=%d", status);
			free(m_context.OutFrames32);
			free(m_context.InFrames32);
			Reverb_free(&m_context);
			m_context.hInstance = NULL;
			return S_FALSE;
		}

		m_BASS_DSP_handle = BASS_ChannelSetDSP(m_Stream, DSPProc, (void *) this, 0);

		if (m_BASS_DSP_handle == 0)
		{
			Game->LOG(0, "BASS error: %d while adding DSP effect", BASS_ErrorGetCode());
			free(m_context.OutFrames32);
			free(m_context.InFrames32);
			Reverb_free(&m_context);
			m_context.hInstance = NULL;
			return S_FALSE;
		}

	//	Game->LOG(0, "Preset reverb active, ptr=0x%08X.", (uint32_t) m_pContext);
		Game->LOG(0, "Preset reverb active.");

#endif
		break;

	default:
#ifdef USE_BASS_FX
		if (m_EffectHandle != 0)
		{
			BASS_ChannelRemoveFX(m_Stream, m_EffectHandle);
			m_EffectHandle = 0;
		}
#endif

#ifdef USE_LIBEFFECTS_REVERB
	if (m_BASS_DSP_handle != 0)
	{
		if (BASS_ChannelRemoveDSP(m_Stream, m_BASS_DSP_handle) == FALSE)
		{
			Game->LOG(0, "BASS error: %d while removing old DSP effect", BASS_ErrorGetCode());
		}
		m_BASS_DSP_handle = 0;
	}
	if (m_context.hInstance != NULL)
	{
		free(m_context.InFrames32);
		free(m_context.OutFrames32);
		Reverb_free(&m_context);
		m_context.hInstance = NULL;
	}
#endif
		break;
	}

	return S_OK;
}
HRESULT CBSoundBuffer::LoadFromFile(const char* Filename, bool ForceReload)
{
	if (m_Stream)
	{
		BASS_StreamFree(m_Stream);
		m_Stream = NULL;
	}

	if (m_File) Game->m_FileManager->CloseFile(m_File);
	
	m_File = Game->m_FileManager->OpenFile(Filename);
	if (!m_File)
	{
		Game->LOG(0, "Error opening sound file '%s'", Filename);
		return E_FAIL;
	}
	
	BASS_FILEPROCS fileProc;
	fileProc.close = CBSoundBuffer::FileCloseProc;
	fileProc.read = CBSoundBuffer::FileReadProc;
	fileProc.seek = CBSoundBuffer::FileSeekProc;
	fileProc.length = CBSoundBuffer::FileLenProc;

	m_Stream = BASS_StreamCreateFileUser(STREAMFILE_NOBUFFER, 0, &fileProc, (void*)m_File);
	if (!m_Stream)
	{
		Game->LOG(0, "BASS error: %d while loading '%s'", BASS_ErrorGetCode(), Filename);
		return E_FAIL;
	}

	CBUtils::SetString(&m_Filename, Filename);

#ifdef USE_BASS_FX
	if (m_EffectHandle != 0)
	{
		BASS_ChannelRemoveFX(m_Stream, m_EffectHandle);
		m_EffectHandle = 0;
	}
#endif

#ifdef USE_LIBEFFECTS_REVERB
	if (m_BASS_DSP_handle != 0)
	{
		if (BASS_ChannelRemoveDSP(m_Stream, m_BASS_DSP_handle) == FALSE)
		{
			Game->LOG(0, "BASS error: %d while removing ond DSP effect from '%s'", BASS_ErrorGetCode(), Filename);
		}
		m_BASS_DSP_handle = 0;
	}
	if (m_context.hInstance != NULL)
	{
		free(m_context.InFrames32);
		free(m_context.OutFrames32);
		Reverb_free(&m_context);
		m_context.hInstance = NULL;
	}
#endif

	/*
	HRESULT res;
	bool NewlyCreated = false;

	if(!m_SoundBuffer || ForceReload || m_Streamed){
		if(!m_File) m_File = Game->m_FileManager->OpenFile(Filename);
		if(!m_File){
			Game->LOG(0, "Error opening sound file '%s'", Filename);
			return E_FAIL;
		}
		// switch to streamed for big files
		if(!m_Streamed && (m_File->GetSize() > MAX_NONSTREAMED_FILE_SIZE && !Game->m_ForceNonStreamedSounds)) SetStreaming(true);
	}

	// create buffer
	if(!m_SoundBuffer){
		NewlyCreated = true;
		
		res = InitializeBuffer(m_File);
		if(FAILED(res)){
			Game->LOG(res, "Error creating sound buffer for file '%s'", Filename);
			return res;
		}
	}



	// store filename
	if(!m_Filename){
		m_Filename = new char[strlen(Filename)+1];
		strcpy(m_Filename, Filename);
	}

	// close file (if not streaming)
	if(!m_Streamed && m_File){
		Game->m_FileManager->CloseFile(m_File);
		m_File = NULL;
	}
	*/

	return S_OK;
}
Esempio n. 12
0
bool BassPlayer::unregisterEQ() {
    if (!_fxEQ) return false;
    bool res = BASS_ChannelRemoveFX(chan, _fxEQ);
    _fxEQ = 0;
    return res;
}