Example #1
0
bool CClientSound::Play3D ( const SString& strPath, const CVector& vecPosition, bool bLoop )
{
    long lFlags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_3D | BASS_SAMPLE_MONO;
    if ( bLoop )
        lFlags |= BASS_SAMPLE_LOOP;

    // Try to load the sound file
    if (
        ( m_pSound = BASS_StreamCreateFile ( false, strPath, 0, 0, lFlags ) )
     || ( m_pSound = BASS_MusicLoad ( false, strPath, 0, 0, lFlags, 0) )
        )
    {
        m_b3D = true;
        m_strPath = strPath;
        m_vecPosition = vecPosition;
        BASS_3DVECTOR pos ( vecPosition.fX, vecPosition.fY, vecPosition.fZ );
        BASS_ChannelSet3DPosition ( m_pSound, &pos, NULL, NULL );
        BASS_ChannelSet3DAttributes ( m_pSound, BASS_3DMODE_NORMAL, 1.0f, 0.5f, 360, 360, 1.0f );
        BASS_ChannelPlay ( m_pSound, false );
        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency );
        return true;
    }
    g_pCore->GetConsole()->Printf ( "BASS ERROR %d in Play3D  path = %s", BASS_ErrorGetCode(), strPath.c_str() );
    return false;
}
Example #2
0
float CClientSound::GetPlaybackSpeed ( void )
{
    float fSpeed = 1;
    if ( m_pSound )
        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_FREQ, &fSpeed );
    return ( fSpeed / m_fDefaultFrequency );
}
Example #3
0
void CClientSound::ThreadCallback ( HSTREAM pSound )
{
    if ( pSound )
    {
        m_pSound = pSound;
        if ( m_b3D )
        {
            BASS_3DVECTOR pos ( m_vecPosition.fX, m_vecPosition.fY, m_vecPosition.fZ );
            BASS_ChannelSet3DPosition ( pSound, &pos, NULL, NULL );
            BASS_ChannelSet3DAttributes ( pSound, BASS_3DMODE_NORMAL, 1.0f, 0.5f, 360, 360, 1.0f );
        }
        // Set a Callback function for download finished
        BASS_ChannelSetSync ( pSound, BASS_SYNC_DOWNLOAD, 0, &DownloadSync, this );
        BASS_ChannelGetAttribute ( pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency );
        BASS_ChannelPlay ( pSound, false );
    }
    else
        g_pCore->GetConsole()->Printf ( "BASS ERROR %d in PlayStream  b3D = %s  path = %s", BASS_ErrorGetCode(), m_b3D ? "true" : "false", m_strPath.c_str() );
    
    // Call onClientSoundStream LUA event
    CLuaArguments Arguments;
    Arguments.PushBoolean ( pSound ? true : false );
    Arguments.PushNumber ( GetLength () );
    this->CallEvent ( "onClientSoundStream", Arguments, true );
}
Example #4
0
int KNMusicBackendBassThread::volume()
{
    float channelVolume;
    BASS_ChannelGetAttribute(m_channel,
                             BASS_ATTRIB_VOL,
                             &channelVolume);
    return (int)channelVolume*100;
}
Example #5
0
float CBassAudio::GetPan ( void )
{
    if ( m_pSound )
    {
        float fPan = 0.0f;
        BASS_ChannelGetAttribute( m_pSound, BASS_ATTRIB_PAN, &fPan );
        
        return fPan;
    }

    return 0.0f;
}
Example #6
0
bool Player::Load(const char filename[])
{
    BASS_ChannelStop(stream);
    BASS_StreamFree(stream);
    stream = BASS_StreamCreateFile(false, filename, 0, 0, 0);
    if (stream == NULL)
        return false;
    stopped = true;
    paused = false;
    BASS_ChannelGetAttribute(stream, BASS_ATTRIB_FREQ, &defaulSampleRate);
    pitchedSampleRate = defaulSampleRate;
    return true;
}
Example #7
0
void BassSoundEngine::Update(float dwTimeMilliSecond)
{
	if(ScreenState==SCREEN_GAMEMAIN)
	{
		if(BASS_ChannelIsActive(channel[0])!=BASS_ACTIVE_PLAYING || !channel[0]){	
			if(m_pAudio)	// audio stopped, resume audio in video
				m_pAudio->put_Volume(Lin2dB(defaultVolume));
		}else{				// channel 0 is active
			if(m_pAudio)
				m_pAudio->put_Volume(-10000);

			if(pitch_factor!=0)
				SetPitch(pitch_factor,0,true), pitch_factor = 0;

			if(sampleRate_factor!=0)
				SetSampleRate(sampleRate_factor,0,true), sampleRate_factor = 0;

			if(tempo_factor!=0)
				SetTempo(tempo_factor,0,true), tempo_factor = 0;
		}
	}

	for(int i = 0; i < nowChannel; i++)
	{
		if(channel[i]!=NULL)
		{
			float volume;
			BASS_ChannelGetAttribute(channel[i], BASS_ATTRIB_VOL, &volume);
			if(volume==0){
				BASS_ChannelStop(channel[i]);
				channel[i] = NULL;
			}

			if(volume>volumeDes[i])
			{
				volume -= soundSpd*dwTimeMilliSecond;
				if(volume<volumeDes[i]) volume = volumeDes[i];
			}
			if(volume<volumeDes[i])
			{
				volume += soundSpd*dwTimeMilliSecond;
				if(volume>volumeDes[i]) volume = volumeDes[i];
			}
			BASS_ChannelSetAttribute(channel[i], BASS_ATTRIB_VOL, volume);

			if(volume==0)
				FreeChannel(i, true);
		}
	}
}
Example #8
0
float CAudio::GetVolume()
{
	if(m_bIsMuted)
		return 0.0f;

	if(m_dwChannel != 0)
	{
		// Current volume
		float fVolume;
		BASS_ChannelGetAttribute(m_dwChannel, BASS_ATTRIB_VOL, &fVolume);
		return fVolume/0.01f;
	}

	return 0.0f;
}
Example #9
0
pascal OSStatus DirEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	DWORD srcChan=BASS_FX_TempoGetSource(chan);
	float dir;
	BASS_ChannelGetAttribute(srcChan, BASS_ATTRIB_REVERSE_DIR, &dir);

	if(dir<0){
		BASS_ChannelSetAttribute(srcChan, BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD);
		SetControlText(16, "Playing Direction - Forward");
	}else{
		BASS_ChannelSetAttribute(srcChan, BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_REVERSE);
		SetControlText(16,"Playing Direction - Reverse");
	}

	return noErr;
}
Example #10
0
float CAudio::GetVolume()
{
	// Are we muted?
	if(m_bIsMuted)
		return 0.0f;

	// Do we have a valid channel?
	if(m_dwChannel != 0)
	{
		// Get current volume
		float fVolume;
		BASS_ChannelGetAttribute(m_dwChannel, BASS_ATTRIB_VOL, &fVolume);
		return fVolume/0.01f;
	}

	return 0.0f;
}
Example #11
0
HCHANNEL BassSoundEngine::PlayMusic(int sound_id, CHANNEL Ichannel, bool loop, float volume)
{
	if(Ichannel<0||Ichannel>=maxChannel){
		Ichannel = GetNewChannel();
		if(Ichannel<0)
			return NULL;
	}else
		FreeChannel(Ichannel);
	HSTREAM sound = playMusic[sound_id];
	channel[Ichannel] = sound;

	DWORD hr;
	bool useDSP = false;

	// set position
	float freq;
	if(Ichannel==0)
	{
		hr = BASS_ChannelGetAttribute(sound, BASS_ATTRIB_FREQ, &freq);
		hr = SetPosition(0, sound_id, 0);
		hr = BASS_FX_TempoGetRateRatio(sound);
		if(hr>0)
			useDSP = true;
		music_sampleRate = freq;
	}

	// set volume
	volumeDes[Ichannel] = volume*defaultVolume;
	hr = BASS_ChannelSetAttribute(sound, BASS_ATTRIB_VOL, volumeDes[Ichannel]);

	// start play
	hr = BASS_ChannelPlay(sound, useDSP?FALSE:TRUE);

	// set loop
	if(loop)
		hr = BASS_ChannelFlags(sound, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);

	if(Ichannel==0)
		Update(0);

	return sound;
}
Example #12
0
bool CClientSound::Play ( const SString& strPath, bool bLoop )
{
    long lFlags = BASS_STREAM_AUTOFREE;
    if ( bLoop )
        lFlags = BASS_SAMPLE_LOOP;

    // Try to load the sound file
    if (
        ( m_pSound = BASS_StreamCreateFile ( false, strPath, 0, 0, lFlags ) )
     || ( m_pSound = BASS_MusicLoad ( false, strPath, 0, 0, lFlags, 0) )
        )
    {
        m_strPath = strPath;
        BASS_ChannelPlay ( m_pSound, false );
        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency );
        return true;
    }
    g_pCore->GetConsole()->Printf ( "BASS ERROR %d in Play  path = %s", BASS_ErrorGetCode(), strPath.c_str() );
    return false;
}
Example #13
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;
}
Example #14
0
int WINAPI WinMain( HINSTANCE instance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
//void entrypoint(void)
{
    MSG         msg;
    int         done=0;
    WININFO     *info = &wininfo;

	window_init(info);

	long st = GetTickCount();
	
	CLogger* myLogger;
	myLogger = new CLogger();

	GraphicsClass* m_Graphics;
	m_Graphics = new GraphicsClass();

	m_Graphics->Initialize(XRES,YRES,info->hWnd);

	// BASS
	BASS_Init(-1,44100,0,0,NULL);
	//char filename[400]="C:\\My_Projects\\frmwrk\\Debug\\lemonade-merry_xmas_nectas.xm";
	char filename[400]="C:\\My_Projects\\frmwrk\\Debug\\bass_system-questa_sera.xm";
	//char * filename= "dark_rat-xmas.xm";
	DWORD chan;
	float time;
	//chan=BASS_MusicLoad(FALSE,"dark_rat-xmas.xm",0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN,0);
	if (!(chan=BASS_MusicLoad(FALSE,filename,0,0,BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN,0)))
	{
		int k=5;
	}

	float dummy;
	int a;
	for (a=0;BASS_ChannelGetAttribute(chan,BASS_ATTRIB_MUSIC_VOL_CHAN+a,&dummy);a++);
	QWORD pos;
	pos=BASS_ChannelGetLength(chan,BASS_POS_BYTE);

	BASS_ChannelPlay(chan,FALSE);

	// programm loop
	long to=0;
	while( !done )
    {
		pos=BASS_ChannelGetPosition(chan,BASS_POS_BYTE);
		time=BASS_ChannelBytes2Seconds(chan,pos);
	
		myLogger->LogThis("pos");
		myLogger->LogThisFloat((float)pos);
		myLogger->LogThis("time");
		myLogger->LogThisFloat((float)time);

		if (time!=0)
		{
			int k=6;
		}
		long t = GetTickCount();
        if( !to ) to=t; 
        t-=to;

		while( PeekMessage(&msg,0,0,0,PM_REMOVE) )
        {
            if( msg.message==WM_QUIT ) done=1;
		    TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        DrawTime( info, .001f*t );
		m_Graphics->Frame();
		m_Graphics->Render();
	}

	window_end(info);
	
    ExitProcess( 0 );
}
int Player::sampleRate() const {
	float freq;
	BASS_ChannelGetAttribute(_output, BASS_ATTRIB_FREQ, &freq);
	return freq;
}
Example #16
0
//
// This will return false for non streams if the file is not correct
//
bool CBassAudio::BeginLoadingMedia ( void )
{
    assert ( !m_pSound && !m_bPendingPlay );

    // Calc the flags
    long lFlags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_SOFTWARE;   
#if 0   // Everything sounds better in ste-reo
    if ( m_b3D )
        lFlags |= BASS_SAMPLE_MONO;
#endif
    if ( m_bLoop )
        lFlags |= BASS_SAMPLE_LOOP;

    if ( m_bStream )
    {
        //
        // For streams, begin the connect sequence
        //
        assert ( !m_pVars );
        m_pVars = new SSoundThreadVariables ();
        m_pVars->strURL = m_strPath;
        m_pVars->lFlags = lFlags;
        CreateThread ( NULL, 0, reinterpret_cast <LPTHREAD_START_ROUTINE> ( &CBassAudio::PlayStreamIntern ), m_uiCallbackId, 0, NULL );
        m_bPendingPlay = true;
        OutputDebugLine ( "[Bass]        stream connect started" );
    }
    else
    {
        //
        // For non streams, try to load the sound file
        //
        // First x streams need to be decoders rather than "real" sounds but that's dependent on if we need streams or not so we need to adapt.
        /*
            We are the Borg. Lower your shields and surrender your ships. 
            We will add your biological and technological distinctiveness to our own. 
            Your culture will adapt to service us. 
            Resistance is futile.
        */
        long lCreateFlags = BASS_MUSIC_PRESCAN|BASS_STREAM_DECODE;

        if ( !m_pBuffer )
        {
            m_pSound = BASS_StreamCreateFile ( false, m_strPath, 0, 0, lCreateFlags );
            if ( !m_pSound )
                m_pSound = BASS_MusicLoad ( false, m_strPath, 0, 0, BASS_MUSIC_RAMP|BASS_MUSIC_PRESCAN|BASS_STREAM_DECODE, 0 );  // Try again
            if ( !m_pSound && m_b3D )
                m_pSound = ConvertFileToMono ( m_strPath );                       // Last try if 3D
        }
        else
        {
            m_pSound = BASS_StreamCreateFile ( true, m_pBuffer, 0, m_uiBufferLength, lCreateFlags );
            if ( !m_pSound )
                m_pSound = BASS_MusicLoad ( true, m_pBuffer, 0, m_uiBufferLength, lCreateFlags, 0 );
        }

        // Failed to load ?
        if ( !m_pSound )
        {
            g_pCore->GetConsole()->Printf ( "BASS ERROR %d in LoadMedia  path:%s  3d:%d  loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop );
            return false;
        }

        m_pSound = BASS_FX_ReverseCreate ( m_pSound, 2.0f, BASS_STREAM_DECODE | BASS_FX_FREESOURCE | BASS_MUSIC_PRESCAN );
        BASS_ChannelSetAttribute ( m_pSound, BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD );
        // Sucks.
        /*if ( BASS_FX_BPM_CallbackSet ( m_pSound, (BPMPROC*)&BPMCallback, 1, 0, 0, m_uiCallbackId ) == false )
        {
            g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_FX_BPM_CallbackSet  path:%s  3d:%d  loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop );
        }*/

        if ( BASS_FX_BPM_BeatCallbackSet ( m_pSound, (BPMBEATPROC*)&BeatCallback, m_uiCallbackId ) == false )
        {
            g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_FX_BPM_BeatCallbackSet  path:%s  3d:%d  loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop );
        }
        

        if ( !m_pSound )
        {
            g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_FX_ReverseCreate  path:%s  3d:%d  loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop );
            return false;
        }
        m_pSound = BASS_FX_TempoCreate ( m_pSound, lFlags | BASS_FX_FREESOURCE );
        if ( !m_pSound )
        {
            g_pCore->GetConsole()->Printf ( "BASS ERROR %d in CreateTempo  path:%s  3d:%d  loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop );
            return false;
        }
        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_TEMPO, &m_fTempo );
        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_TEMPO_PITCH, &m_fPitch );
        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_TEMPO_FREQ, &m_fSampleRate );
        // Validation of some sort
        if ( m_bLoop && BASS_ChannelFlags ( m_pSound, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP ) == -1 )
            g_pCore->GetConsole()->Printf ( "BASS ERROR %d in LoadMedia ChannelFlags LOOP  path:%s  3d:%d  loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop );

        BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency );
        m_bPendingPlay = true;
        SetFinishedCallbacks ();
        OutputDebugLine ( "[Bass] sound loaded" );
    }

    return true;
}
Example #17
0
//
// Called from the main thread during DoPulse
//
void CBassAudio::CompleteStreamConnect ( HSTREAM pSound )
{
    if ( pSound )
    {
        m_pSound = pSound;

        BASS_ChannelGetAttribute ( pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency );
        BASS_ChannelSetAttribute ( pSound, BASS_ATTRIB_FREQ, m_fPlaybackSpeed * m_fDefaultFrequency );
        if ( !m_b3D )
            BASS_ChannelSetAttribute( pSound, BASS_ATTRIB_VOL, m_fVolume );
        ApplyFxEffects ();
        // Set a Callback function for download finished or connection closed prematurely
        m_hSyncDownload = BASS_ChannelSetSync ( pSound, BASS_SYNC_DOWNLOAD, 0, &DownloadSync, m_uiCallbackId );
        SetFinishedCallbacks ();

        if ( BASS_FX_BPM_CallbackSet ( pSound, (BPMPROC*)&BPMCallback, 1, 0, 0, m_uiCallbackId ) == false )
        {
            g_pCore->GetConsole()->Print ( "BASS ERROR in BASS_FX_BPM_CallbackSet" );
        }
        if ( BASS_FX_BPM_BeatCallbackSet ( pSound, (BPMBEATPROC*)&BeatCallback, m_uiCallbackId ) == false )
        {
            g_pCore->GetConsole()->Print ( "BASS ERROR in BASS_FX_BPM_BeatCallbackSet" );
        }
        // get the broadcast name
        const char* szIcy;
        szIcy = BASS_ChannelGetTags ( pSound, BASS_TAG_ICY );
        if ( 
            ( szIcy = BASS_ChannelGetTags ( pSound, BASS_TAG_ICY ) )
         || ( szIcy = BASS_ChannelGetTags ( pSound, BASS_TAG_WMA ) )
         || ( szIcy = BASS_ChannelGetTags ( pSound, BASS_TAG_HTTP ) )
            )
        {
            if ( szIcy ) 
            {
                for ( ; *szIcy; szIcy += strlen ( szIcy ) + 1 )
                {
                    if ( !strnicmp ( szIcy, "icy-name:", 9 ) ) // ICY / HTTP
                    {
                        m_strStreamName = szIcy + 9;
                        break;
                    }
                    else if ( !strnicmp ( szIcy, "title=", 6 ) ) // WMA
                    {
                        m_strStreamName = szIcy + 6;
                        break;
                    }
                    //g_pCore->GetConsole()->Printf ( "BASS STREAM INFO  %s", szIcy );
                }
            }
        }
        // set sync for stream titles
        m_hSyncMeta = BASS_ChannelSetSync( pSound, BASS_SYNC_META, 0, &MetaSync, m_uiCallbackId ); // Shoutcast
        //g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_SYNC_META", BASS_ErrorGetCode() );
        //BASS_ChannelSetSync(pSound,BASS_SYNC_OGG_CHANGE,0,&MetaSync,this); // Icecast/OGG
        //g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_SYNC_OGG_CHANGE", BASS_ErrorGetCode() );
        //BASS_ChannelSetSync(pSound,BASS_SYNC_WMA_META,0,&MetaSync,this); // script/mid-stream tags
        //g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_SYNC_WMA_META", BASS_ErrorGetCode() );
        //BASS_ChannelSetSync(pSound,BASS_SYNC_WMA_CHANGE,0,&WMAChangeSync,this); // server-side playlist changes
        //g_pCore->GetConsole()->Printf ( "BASS ERROR %d in BASS_SYNC_WMA_CHANGE", BASS_ErrorGetCode() );
    }
    else
        g_pCore->GetConsole()->Printf ( "BASS ERROR %d in PlayStream  b3D = %s  path = %s", BASS_ErrorGetCode(), m_b3D ? "true" : "false", m_strPath.c_str() );

    OutputDebugLine ( "[Bass]        stream connect complete" );

    AddQueuedEvent ( SOUND_EVENT_STREAM_RESULT, m_strStreamName, GetLength (), pSound ? true : false );
}
Example #18
0
BOOL WINAPI CustFXGetParam (HCustFX* hc, float* val) {
return BASS_ChannelGetAttribute(hc->pitch, BASS_ATTRIB_TEMPO_PITCH, val);
}
Example #19
0
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	DWORD p;
	float freq;
	char c[30];

	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 decode bpm & stream
							BASS_FX_BPM_Free(hBPM);

							// free tempo, stream, music & bpm/beat callbacks
							BASS_StreamFree(chan);

							// create decode stream channel
							chan=BASS_StreamCreateFile(FALSE, file, 0, 0, BASS_STREAM_DECODE);

							// create decode music channel
							if (!chan) chan = BASS_MusicLoad(FALSE, file, 0, 0, BASS_MUSIC_RAMP|BASS_MUSIC_PRESCAN|BASS_MUSIC_DECODE, 0);

							if (!chan){
								// not a WAV/MP3 or MOD
								MESS(ID_OPEN,WM_SETTEXT,0,"click here to open a file && play it...");
								Error("Selected file couldn't be loaded!");
								break;
							}

							// get current samplerate
							BASS_ChannelGetAttribute(chan, BASS_ATTRIB_FREQ, &freq);

							// update the position slider
							p = (DWORD)BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE));
							MESS(IDC_POS,TBM_SETRANGEMAX,0,p);
							MESS(IDC_POS,TBM_SETPOS,TRUE,0);

							// create a new stream - decoded & resampled :)
							if (!(chan=BASS_FX_TempoCreate(chan, BASS_SAMPLE_LOOP|BASS_FX_FREESOURCE))){
								MESS(ID_OPEN,WM_SETTEXT,0,"click here to open a file && play it...");
								Error("Couldn't create a resampled stream!");
								BASS_StreamFree(chan);
								BASS_MusicFree(chan);
								break;
							}

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

							// set Volume
							p = MESS(IDC_VOL,TBM_GETPOS,0,0);
							BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, (float)(100 - p)/100.0f);

							// update tempo slider & view
							MESS(IDC_TEMPO,TBM_SETPOS,TRUE,0);
							MESS(IDC_STEMPO,WM_SETTEXT,0,"Tempo = 0%");

							// set rate min/max values according to current frequency
							MESS(IDC_RATE,TBM_SETRANGEMAX,0,(long)(freq * 1.3f));
							MESS(IDC_RATE,TBM_SETRANGEMIN,0,(long)(freq * 0.7f));
							MESS(IDC_RATE,TBM_SETPOS,TRUE,(long)freq);
							MESS(IDC_RATE,TBM_SETPAGESIZE,0,(long)(freq * 0.01f));	// by 1%

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

							// update the approximate time in seconds view
							UpdatePositionLabel();

							// play new created stream
							BASS_ChannelPlay(chan,FALSE);

							// set the callback bpm and beat
							SendMessage(win,WM_COMMAND,IDC_CHKPERIOD,l);
							SendMessage(win,WM_COMMAND,IDC_CHKBEAT,l);

							// get the bpm of 30 seconds from the start
							DecodingBPM(TRUE, 0.0f, 30.0f, file);
						}
					}
				return 1;

				case IDC_CHKPERIOD:
					if(MESS(IDC_CHKPERIOD,BM_GETCHECK,0,0)){
						GetDlgItemText(win, IDC_EPBPM, c, 5);
						BASS_FX_BPM_CallbackSet(chan, (BPMPROC*)GetBPM_Callback, (double)atof(c), 0, BASS_FX_BPM_MULT2, 0);
					}else
						BASS_FX_BPM_Free(chan);
				return 1;

				case IDC_CHKBEAT:
					if(MESS(IDC_CHKBEAT,BM_GETCHECK,0,0)){
						BASS_FX_BPM_BeatCallbackSet(chan, (BPMBEATPROC*)GetBeatPos_Callback, 0);
					}else
						BASS_FX_BPM_BeatFree(chan);
				return 1;
			}
			break;

		case WM_VSCROLL:
			if(GetDlgCtrlID((HWND)l) == IDC_VOL)
				BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, (float)(100 - MESS(IDC_VOL,TBM_GETPOS,0,0))/100.0f);
		break;

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

				switch (GetDlgCtrlID((HWND)l)) {
					case IDC_TEMPO:
							// set new tempo
							BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO, (float)MESS(IDC_TEMPO, TBM_GETPOS, 0, 0));

							// update tempo static text
							sprintf(c,"Tempo = %d%%", MESS(IDC_TEMPO, TBM_GETPOS, 0, 0));
							MESS(IDC_STEMPO,WM_SETTEXT,0,c);
					case IDC_RATE:
						{
							// set new samplerate
							BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO_FREQ, (float)MESS(IDC_RATE, TBM_GETPOS, 0, 0));

							sprintf(c,"Samplerate = %dHz", MESS(IDC_RATE, TBM_GETPOS, 0, 0));
							MESS(IDC_SRATE,WM_SETTEXT,0,c);

							// update the bpm view
							if (MESS(IDC_CHKPERIOD,BM_GETCHECK,0,0))
								sprintf(c,"BPM: %0.2f", GetNewBPM(chan));
							else
								sprintf(c,"BPM: %0.2f", GetNewBPM(hBPM));

							MESS(IDC_SBPM,WM_SETTEXT,0,c);

							// update the approximate time in seconds view
							UpdatePositionLabel();
						}
					break;
					case IDC_POS:
						// change the position
						if (LOWORD(w) == SB_ENDSCROLL) { // seek to new pos
							BASS_ChannelSetPosition(chan, (QWORD)BASS_ChannelSeconds2Bytes(chan, (double)MESS(IDC_POS,TBM_GETPOS,0,0)), BASS_POS_BYTE);

							// get the bpm of last IDC_EPBPM seconds
							GetDlgItemText(win, IDC_EPBPM, c, 5);
							DecodingBPM(FALSE, (double)MESS(IDC_POS,TBM_GETPOS,0,0) - (double)atof(c), (double)MESS(IDC_POS,TBM_GETPOS,0,0),"");
						}
						// update the approximate time in seconds view
						UpdatePositionLabel();
					break;
				}
			}
			return 1;
			break;

		case WM_CLOSE:
			EndDialog(h, 0);
			return 1;
		break;

		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;

			// 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;
			}
    
			// volume
			MESS(IDC_VOL,TBM_SETRANGEMAX,0,100);
			MESS(IDC_VOL,TBM_SETPOS,TRUE,50);
			MESS(IDC_VOL,TBM_SETPAGESIZE,0,5);

			// tempo
			MESS(IDC_TEMPO,TBM_SETRANGEMAX,TRUE,30);
			MESS(IDC_TEMPO,TBM_SETRANGEMIN,TRUE,-30);
			MESS(IDC_TEMPO,TBM_SETPOS,TRUE,0);
			MESS(IDC_TEMPO,TBM_SETPAGESIZE,0,1);

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

			// bpm detection process
			MESS(IDC_PRGRSBPM,PBM_SETRANGE32,0,100);

			// set the bpm period edit box, as a default of 10 seconds :)
			MESS(IDC_EPBPM,WM_SETTEXT,0,"10");

			// set the bpm static text font
			Font = CreateFont(-12,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,ANSI_CHARSET,
			                    OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
								DEFAULT_PITCH | FF_DONTCARE,"Tahoma");
			MESS(IDC_SBPM, WM_SETFONT, Font, TRUE);
			MESS(IDC_SBEAT, WM_SETFONT, Font, TRUE);
			return 1;
	}
	return 0;
}
int Player::volume() const {
	float val;
	BASS_ChannelGetAttribute(_output, BASS_ATTRIB_VOL, &val);
	return val*100.f+0.5f;
}