void CBSoundBuffer::LoopSyncProc(HSYNC handle, DWORD channel, DWORD data, void* user)
{
	CBSoundBuffer* soundBuf = static_cast<CBSoundBuffer*>(user);
	QWORD pos = BASS_ChannelSeconds2Bytes(channel, (float)soundBuf->GetLoopStart() / 1000.0f);
	
	if (!BASS_ChannelSetPosition(channel, pos, BASS_POS_BYTE))
		BASS_ChannelSetPosition(channel, 0, BASS_POS_BYTE);
}
Exemple #2
0
bool playMOD (int f, int a, int fromTrack) {
	if (soundOK) {

		stopMOD (a);

		setResourceForFatal (f);
		uint32_t length = openFileFromNum (f);
		if (length == 0) return NULL;

		char * memImage;
		memImage = loadEntireFileToMemory (bigDataFile, length);
		if (! memImage) return fatal (ERROR_MUSIC_MEMORY_LOW);

		mod[a] = BASS_MusicLoad (true, memImage, 0, length, BASS_MUSIC_LOOP|BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0);
		delete memImage;

		if (! mod[a]) {

		}
		else
		{
			setMusicVolume (a, defVol);

			if (! BASS_ChannelPlay (mod[a], true) )
				debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode());

			BASS_ChannelSetPosition (mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER);
			BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP);
		}
		setResourceForFatal (-1);
	}
    return true;
}
Exemple #3
0
void CClientSound::SetPlayPosition ( unsigned int uiPosition )
{
    if ( m_pSound )
    {
        BASS_ChannelSetPosition( m_pSound, BASS_ChannelSeconds2Bytes( m_pSound, uiPosition/1000 ), BASS_POS_BYTE );
    }
}
Exemple #4
0
void StreamRender::SlideSuelta(){

    //Timer->start(Render);
    isSlider=false;
     BASS_ChannelSetPosition(stream, segungosTrascurridos, BASS_POS_BYTE);

}
void KNMusicBackendBassThread::setPosition(const qint64 &position)
{
    //Check the channel is null.
    if(!m_channel)
    {
        return;
    }
    //If the state is stopped and the position is not 0, then changed the state
    //to pause.
    if(m_state==Stopped && position!=0)
    {
        //Change to paused.
        setPlayingState(Paused);
    }
    //Change the position, the unit of the position should be translate into
    //second.
    BASS_ChannelSetPosition(
                m_channel,
                BASS_ChannelSeconds2Bytes(m_channel,
                                          //The position here should be the
                                          //'absolute' position.
                                          //That means it should be the position
                                          //plus the start position.
                                          (double)(m_startPosition+position)
                                          /1000.0),
                BASS_POS_BYTE);
    //Check the position.
    checkPosition();
}
Exemple #6
0
// window procedure
LRESULT CALLBACK SpectrumWindowProc(HWND h, UINT m, WPARAM w, LPARAM l)
{
	switch (m) {
		case WM_LBUTTONDOWN:
		case WM_RBUTTONDOWN:
		case WM_MOUSEMOVE:
			if (w&MK_LBUTTON) SetLoopStart(LOWORD(l)*bpp); // set loop start
			if (w&MK_RBUTTON) SetLoopEnd(LOWORD(l)*bpp); // set loop end
			return 0;

		case WM_MBUTTONDOWN:
			BASS_ChannelSetPosition(chan,LOWORD(l)*bpp,BASS_POS_BYTE); // set current pos
			return 0;

		case WM_TIMER:
			InvalidateRect(h,0,0); // refresh window
			return 0;

		case WM_PAINT:
			if (GetUpdateRect(h,0,0)) {
				PAINTSTRUCT p;
				HDC dc;
				if (!(dc=BeginPaint(h,&p))) return 0;
				BitBlt(dc,0,0,WIDTH,HEIGHT,wavedc,0,0,SRCCOPY); // draw peak waveform
				DrawTimeLine(dc,loop[0],0xffff00,12); // loop start
				DrawTimeLine(dc,loop[1],0x00ffff,24); // loop end
				DrawTimeLine(dc,BASS_ChannelGetPosition(chan,BASS_POS_BYTE),0xffffff,0); // current pos
				EndPaint(h,&p);
			}
			return 0;

		case WM_CREATE:
			win=h;
			// initialize output
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				return -1;
			}
			if (!PlayFile()) { // start a file playing
				BASS_Free();
				return -1;
			}
			SetTimer(h,0,100,0); // set update timer (10hz)
			break;

		case WM_DESTROY:
			KillTimer(h,0);
			if (scanthread) { // still scanning
				killscan=TRUE;
				WaitForSingleObject((HANDLE)scanthread,1000); // wait for the thread
			}
			BASS_Free();
			if (wavedc) DeleteDC(wavedc);
			if (wavebmp) DeleteObject(wavebmp);
			PostQuitMessage(0);
			break;
	}
	return DefWindowProc(h, m, w, l);
}
Exemple #7
0
/**
 * This function progress the song
 * @brief Stream::Avance
 */
void Stream::Avance(){

    StreamMath *w_StreamMath = new StreamMath(streamUltimo);
    double pos= w_StreamMath ->Trascurridos()+3;
    QWORD posx =BASS_ChannelSeconds2Bytes( streamUltimo,  pos);
    BASS_ChannelSetPosition(streamUltimo, posx, BASS_POS_BYTE);
    delete w_StreamMath;
}
Exemple #8
0
void StreamRender::SlideBack()
{
    StreamMath *w_StreamMath = new StreamMath(stream);
    double pos = w_StreamMath ->Trascurridos()-3;
    QWORD posx = BASS_ChannelSeconds2Bytes(stream,pos);
    BASS_ChannelSetPosition(stream, posx, BASS_POS_BYTE);
    delete w_StreamMath;
}
bool Seek(HSTREAM stream, int ms)
{
    float secs = (float)ms / 1000.0f;
    QWORD pos = BASS_ChannelSeconds2Bytes(stream, secs);
    BASS_ChannelSetPosition(stream, pos);

    return true;
}
void MusicSelection::checkThatMusicIsPlayingWithinRange()
{
	double currentPosition = BASS_ChannelBytes2Seconds(bgm, (BASS_ChannelGetPosition(bgm, BASS_POS_BYTE)));
	if (currentPosition > beatMaps[currentSelectedMusicIndex].musicEndPosition || currentPosition < beatMaps[currentSelectedMusicIndex].musicStartPosition)
	{
		BASS_ChannelSetPosition(bgm, BASS_ChannelSeconds2Bytes(bgm, beatMaps[currentSelectedMusicIndex].musicStartPosition), BASS_POS_BYTE);
		BASS_ChannelPlay(bgm, false);
	}
}
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundModule
//  - prototype : bool SetPlayPos(int nOrder)
//
//  - Purpose   : Sets the playing position in orders of the module.
//
// -----------------------------------------------------------------------------
bool CSoundModule::SetPlayPos(int nOrder)
{
    if(!IsValid())
    {
        return false;
    }

    return BASS_ChannelSetPosition(m_handle, (QWORD)MAKELONG(nOrder, 0)) == TRUE;
}
HRESULT CBSoundBuffer::SetPosition(DWORD Pos)
{
	if (m_Stream)
	{
		QWORD pos = BASS_ChannelSeconds2Bytes(m_Stream, (float)Pos / 1000.0f);		
		BASS_ChannelSetPosition(m_Stream, pos, BASS_POS_BYTE);
	}
	return S_OK;
}
Exemple #13
0
/**
 * This fuction ????
 * @brief Stream::slot_Barra
 * @param pos
 * @return void
 */
void Stream::slot_Barra(int pos)
{
    if(IsPlay(streamUltimo)|| IsPause(streamUltimo))
    {
        double posx = BASS_ChannelSeconds2Bytes( streamUltimo,  pos);
        BASS_ChannelSetPosition(streamUltimo, posx, BASS_POS_BYTE);
        return;
    }
}
Exemple #14
0
void Player::Stop()
{
    if (stream != NULL)
    {
        stopped = true;
        paused = false;
        BASS_ChannelStop(stream);
        BASS_ChannelSetPosition(stream, 0, BASS_POS_BYTE);
    }
}
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundStream
//  - prototype : bool SetPlayPos(float fSeconds)
//
//  - Purpose   : Sets the stream play position (seconds).
//
// -----------------------------------------------------------------------------
bool CSoundStream::SetPlayPos(float fSeconds)
{
    if(!IsValid())
    {
        return false;
    }

    QWORD bytes = BASS_ChannelSeconds2Bytes(m_handle, fSeconds);
    return BASS_ChannelSetPosition(m_handle, bytes) == TRUE;
}
Exemple #16
0
// Non-streams only
void CBassAudio::SetPlayPosition ( double dPosition )
{
    // Only relevant for non-streams, which are always ready if valid
    if ( m_pSound )
    {
        // Make sure position is in range
        QWORD bytePosition = BASS_ChannelSeconds2Bytes( m_pSound, dPosition );
        QWORD byteLength = BASS_ChannelGetLength( m_pSound, BASS_POS_BYTE );
        BASS_ChannelSetPosition( m_pSound, Clamp < QWORD > ( 0, bytePosition, byteLength - 1 ), BASS_POS_BYTE );
    }
}
Exemple #17
0
void Music::SetPosition(float time)
{
	QWORD bytesPos = BASS_ChannelSeconds2Bytes(mp3Strewam, time);
	BOOL result = BASS_ChannelSetPosition(mp3Strewam, bytesPos, BASS_POS_BYTE);

	if (result != TRUE)
	{
		int errorCode = BASS_ErrorGetCode();
		assert(false);
	}
}
Exemple #18
0
void BassDecoder::rewind()
{
  #if defined(LIBTOOLS_WINDOWS) && !defined(BASS_H)
  if (!BASS_ChannelSetPosition)
  {
    std::cerr << "Missing BASS_ChannelSetPosition function" << std::endl;
    return;
  }
  #endif 

  if (_music)
  {
    if (_mod)
    {
      BASS_ChannelSetPosition((DWORD) _music,0,BASS_MUSIC_POSRESETEX|BASS_MUSIC_POSRESET);
    }
    else 
      BASS_ChannelSetPosition((DWORD) _music,0,BASS_POS_BYTE);
    _ended=false;
  }
}
Exemple #19
0
bool CAudio::SetAt (int time)
{
	if (m_bIsOnlineStream)
		return false;

	if (m_dwChannel)
	{
		long lTime =BASS_ChannelSeconds2Bytes (m_dwChannel, time);
		BASS_ChannelSetPosition(m_dwChannel, lTime, BASS_POS_BYTE);
		return true;
	}
	return false;
}	
void KNMusicBackendBassThread::setPosition(const qint64 &position)
{
    //If no media, ignore.
    if(m_filePath.isEmpty())
    {
        return;
    }
    //Change the position into second.
    BASS_ChannelSetPosition(m_channel,
                            BASS_ChannelSeconds2Bytes(m_channel,
                                                      (double)(m_startPosition+position)/1000.0),
                            BASS_POS_BYTE);
    //Do the position check.
    onActionPositionCheck();
}
Exemple #21
0
// scan the peaks
void __cdecl ScanPeaks(void *p)
{
	DWORD decoder=(DWORD)p;
	DWORD pos=0;
	float spp=BASS_ChannelBytes2Seconds(decoder,bpp); // seconds per pixel
	while (!killscan) {
		float peak[2];
		if (spp>1) { // more than 1 second per pixel, break it down...
			float todo=spp;
			peak[1]=peak[0]=0;
			do {
				float level[2],step=(todo<1?todo:1);
				BASS_ChannelGetLevelEx(decoder,level,step,BASS_LEVEL_STEREO); // scan peaks
				if (peak[0]<level[0]) peak[0]=level[0];
				if (peak[1]<level[1]) peak[1]=level[1];
				todo-=step;
			} while (todo>0);
		} else
			BASS_ChannelGetLevelEx(decoder,peak,spp,BASS_LEVEL_STEREO); // scan peaks
		{
			DWORD a;
			for (a=0;a<peak[0]*(HEIGHT/2);a++)
				wavebuf[(HEIGHT/2-1-a)*WIDTH+pos]=1+a; // draw left peak
			for (a=0;a<peak[1]*(HEIGHT/2);a++)
				wavebuf[(HEIGHT/2+1+a)*WIDTH+pos]=1+a; // draw right peak
		}
		pos++;
		if (pos>=WIDTH) break; // reached end of display
		if (!BASS_ChannelIsActive(decoder)) break; // reached end of channel
	}
	if (!killscan) {
		DWORD size;
		BASS_ChannelSetPosition(decoder,(QWORD)-1,BASS_POS_BYTE|BASS_POS_SCAN); // build seek table (scan to end)
		size=BASS_ChannelGetAttributeEx(decoder,BASS_ATTRIB_SCANINFO,0,0); // get seek table size
		if (size) { // got it
			void *info=malloc(size); // allocate a buffer
			BASS_ChannelGetAttributeEx(decoder,BASS_ATTRIB_SCANINFO,info,size); // get the seek table
			BASS_ChannelSetAttributeEx(chan,BASS_ATTRIB_SCANINFO,info,size); // apply it to the playback channel
			free(info);
		}
	}
	BASS_StreamFree(decoder); // free the decoder
	scanthread=0;
}
/*
	WM_HSCROLL
*/
VOID Application::Cls_OnHScroll(HWND hwnd, HWND hwndCtl, UINT code, INT pos)
{
	/*
		Громкость
	*/
	if (hwndCtl == hTBSoundVolume)											//Adjusting the volume control (Настройка регулятора громкости)
	{
		INT p = SendMessage(hTBSoundVolume, TBM_GETPOS, NULL, NULL);		//Получение позиции
		DOUBLE nPos = p * 0.01;		//новая позиция уровня громкости
		/*
			Собственный регулятор громкости
		*/
		SendMessage(hTBSoundVolume, TBM_SETPOS, TRUE, (LPARAM)p);
		BASS_ChannelSetAttribute(hStream, BASS_ATTRIB_VOL, nPos);
		numVolume = nPos;
		/*
			Привязка к windows регулятору громкости
		*/
		//BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, p * 100);
		//BASS_SetVolume(p / 100.f);
		
	}
	/*
		Время проигрывания
	*/	
	else if (hwndCtl == hTBPlayingSong)										
	{
		INT nPos = 0;														//new position
		nPos = SendMessage(hTBPlayingSong, TBM_GETPOS, 0, 0);				//Get new position
		secPlaying = nPos;													//Seconds playing = current position
		QWORD bytePos = BASS_ChannelSeconds2Bytes(hStream, nPos);			//Translated seconds in bytes 
		BASS_ChannelSetPosition(hStream, bytePos, BASS_POS_BYTE);			//Rewind in bytes
		SendMessage(hTBPlayingSong, TBM_SETPOS, TRUE, (LPARAM)nPos);		//Translated position	
	}
	/*
		Баланс
	*/
	else if (hwndCtl == hSlider_Balance)
	{
		INT p = SendMessage(hSlider_Balance, TBM_GETPOS, NULL, NULL);
		BASS_ChannelSetAttribute(Application::_this->hStream, BASS_ATTRIB_PAN, p / 5);
	}
}
Exemple #23
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;
}
Exemple #24
0
void stop_playback(HMUSIC music)
{
	BASS_ChannelStop(music);
	BASS_ChannelSetPosition(music, MAKELONG(0,0), BASS_POS_MUSIC_ORDER|
	                        BASS_MUSIC_POSRESET);
}
Exemple #25
0
void CALLBACK LoopSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
	if (!BASS_ChannelSetPosition(channel,loop[0],BASS_POS_BYTE)) // try seeking to loop start
		BASS_ChannelSetPosition(channel,0,BASS_POS_BYTE); // failed, go to start of file instead
}
Exemple #26
0
/*************************************************************************
* Main entrypoint for debug build
*************************************************************************/
int WINAPI WinMain(HINSTANCE instance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;

	g_hInstance = GetModuleHandle(0);
	OutputDebugString("Starting...\n");

    if (!WindowOpen()) {
		OutputDebugString("Failed to open window\n");
		WindowClose();
		return 0;
	}

	if (FAILED(InitDevice())) {
		CleanupDevice();
		return 0;
	}

	IntroInit();
	InitSound();
   
    while (!g_done) {
		g_currentFrame++;
		g_lastTime = g_currentTime;		
		g_currentPos = BASS_ChannelGetPosition(g_stream, BASS_POS_BYTE);
		g_currentTime = BASS_ChannelBytes2Seconds(g_stream, g_currentPos);
		
		if (g_pause) {
			Sleep(100);
		}

	    while (PeekMessage(&msg,0,0,0,PM_REMOVE)) {
            if (msg.message == WM_QUIT) {
				g_done = true;
			}

		    TranslateMessage(&msg);
            DispatchMessage(&msg);

			if (WM_KEYDOWN == msg.message && VK_SPACE == LOWORD(msg.wParam)) {
				if (!g_pause) {
					BASS_ChannelPause(g_stream);
					g_pause = true;
				} else {
					BASS_ChannelPlay(g_stream, false);
					g_pause = false;
				}
			}
			
			if (WM_KEYDOWN == msg.message && VK_LEFT == LOWORD(msg.wParam)) {
				if (g_pause) {
					BASS_ChannelSetPosition(g_stream, g_currentPos-44100, BASS_POS_BYTE);
				} else {
					BASS_ChannelSetPosition(g_stream, g_currentPos-44100*4, BASS_POS_BYTE);
				}
			}

			if (WM_KEYDOWN == msg.message && VK_RIGHT == LOWORD(msg.wParam)) {
				if (g_pause) {
					BASS_ChannelSetPosition(g_stream, g_currentPos+44100, BASS_POS_BYTE);
				} else {
					BASS_ChannelSetPosition(g_stream, g_currentPos+44100*4, BASS_POS_BYTE);
				}
			}

			if (WM_KEYDOWN == msg.message && VK_DOWN == LOWORD(msg.wParam)) {
				BASS_ChannelSetPosition(g_stream, g_currentPos-44100*20, BASS_POS_BYTE);
			}

			if (WM_KEYDOWN == msg.message && VK_UP == LOWORD(msg.wParam)) {
				BASS_ChannelSetPosition(g_stream, g_currentPos+44100*20, BASS_POS_BYTE);
			}

			if (WM_KEYDOWN == msg.message && VK_F1 == LOWORD(msg.wParam)) {
				g_repeatStart = g_currentPos;
				g_repeatEnd = LONG_MAX;
			}

			if (WM_KEYDOWN == msg.message && VK_F2 == LOWORD(msg.wParam)) {
				g_repeatEnd = g_currentPos;
			}

			if (WM_KEYDOWN == msg.message && VK_RETURN == LOWORD(msg.wParam)) {
				g_repeatStart = 0;
				g_repeatEnd = LONG_MAX;
			}
        }

		IntroLoop((long)(g_currentTime*44100.0));
		UpdateTitle();

		if (g_currentPos > g_repeatEnd) {
			BASS_ChannelSetPosition(g_stream, g_repeatStart, BASS_POS_BYTE);
		}
		BASS_Update(0);
    }

	BASS_StreamFree(g_stream);
	BASS_Free();
	
	WindowClose();

    return 0;
}
Exemple #27
0
int decodeFunc(void* inData)
{
    int a, b, r, g, i;
    //short waveData[8 * 1024];
    unsigned int* fftPtr;
    unsigned int* fftOutput;
    float fftData[1024];
    //double timeInSec = 0.0;
    const float maxIntensity = 500 * 2;
    const int COLOR_STEPS = 255;
    const int PALETTE_SIZE = 3 * COLOR_STEPS;
    const int spectrumLength = 1024;
    ThreadFuncData* threadData = (ThreadFuncData*)inData;
    unsigned int colors[255 * 3];
    int imageHeight = 128;
    HSTREAM chan = threadData->stream;
	MusicData* data = threadData->data;
    float percentDone = 1.0f;
    float step = 0.0f;

    mtx_lock(&s_mutex);

    const int SAMPLING_FREQUENCY = 100; //warning: in TimelineImage this samplingfrequency is assumed to be 100
    const double SAMPLING_RESOLUTION = 1.0 / SAMPLING_FREQUENCY;

    QWORD sampleLength = BASS_ChannelSeconds2Bytes(chan, SAMPLING_RESOLUTION);
    int numSamples = (int)((double)BASS_ChannelGetLength(chan, BASS_POS_BYTE) / (double)sampleLength);

    //printf("Num samples %d\n", (int)sampleLength);
    //printf("Num samples %d\n", numSamples);

    BASS_ChannelPlay(chan, 0);

    int j_table[128];
    int pj_table[128];
    int nj_table[128];

    // TODO: Size optimize?

    data->sampleCount = numSamples;

    fftPtr = fftOutput = (unsigned int*)malloc(128 * 4 * (numSamples + 1));

    //const int spectrumLength = 1024;
    //const int imageHeight = 256;

    //var spectrumImage = new Bitmap((int)numSamples, imageHeight);
    //var volumeImage = new Bitmap((int)numSamples, imageHeight);

    //s_editorData.waveViewSize = 128;
	//s_editorData.trackViewInfo.windowSizeX -= s_editorData.waveViewSize;

    //timeInSec =(DWORD)BASS_ChannelBytes2Seconds(chan, len);
    //printf(" %u:%02u\n", (int)timeInSec / 60, (int)timeInSec % 60);

    for (i = 0; i < PALETTE_SIZE; ++i)
    {
        a = 255;
        if (i < PALETTE_SIZE * 0.666f)
            a = (int)(i * 255 / (PALETTE_SIZE * 0.666f));

        b = 0;
        if (i < PALETTE_SIZE * 0.333f)
            b = i;
        else if (i < PALETTE_SIZE * 0.666f)
            b = -i + 510;

        r = 0;
        if (i > PALETTE_SIZE * 0.666f)
            r = 255;
        else if (i > PALETTE_SIZE * 0.333f)
            r = i - 255;

        g = 0;
        if (i > PALETTE_SIZE * 0.666f)
            g = i - 510;

        colors[i] = Emgui_color32((uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a);
    }

    float f = (float)(spectrumLength / log((float)(imageHeight + 1)));
    float f2 = (float)((PALETTE_SIZE - 1) / log(maxIntensity + 1));

    (void)f2;

    for (int rowIndex = 0; rowIndex < imageHeight; ++rowIndex)
    {
        int j_ = (int)(f * log(rowIndex + 1));
        int pj_ = (int)(rowIndex > 0 ? f * log(rowIndex - 1 + 1) : j_);
        int nj_ = (int)(rowIndex < imageHeight - 1 ? f * log(rowIndex + 1 + 1) : j_);

        j_table[rowIndex] = j_;
        pj_table[rowIndex] = pj_;
        nj_table[rowIndex] = nj_;
    }

    step = (float)(99.0f / numSamples);
    percentDone = 1.0f;

    for (int sampleIndex = 0; sampleIndex < numSamples; ++sampleIndex)
    {
        BASS_ChannelSetPosition(chan, sampleIndex * sampleLength, BASS_POS_BYTE);
        BASS_ChannelGetData(chan, fftData, BASS_DATA_FFT2048);

        data->percentDone = (int)(percentDone);

        //printf("%d/%d\n", sampleIndex, numSamples);

        for (int rowIndex = 0; rowIndex < imageHeight; ++rowIndex)
        {
            //int j_ = (int)(f * log(rowIndex + 1));
            //int pj_ = (int)(rowIndex > 0 ? f * log(rowIndex - 1 + 1) : j_);
            //int nj_ = (int)(rowIndex < imageHeight - 1 ? f * log(rowIndex + 1 + 1) : j_);

            int j_ = j_table[(imageHeight - rowIndex) - 1];
            int pj_ = pj_table[(imageHeight - rowIndex) - 1];
            int nj_ = nj_table[(imageHeight - rowIndex) - 1];

            //printf("index %d - %d %d %d\n", rowIndex, j_, pj_, nj_);

            float intensity = 125.0f * 4.0f * fftData[spectrumLength - pj_ - 1] +
                              750.0f * 4.0f * fftData[spectrumLength - j_ - 1] +
                              125.0f * 4.0f * fftData[spectrumLength - nj_ - 1];
            if (intensity > maxIntensity)
                intensity = maxIntensity;

            if (intensity < 0.0f)
                intensity = 0.0f;

            int palettePos = (int)(f2 * log(intensity + 1));

            *fftOutput++ = colors[palettePos];
        }

        percentDone += step;
    }

    BASS_StreamFree(chan);

    free(threadData);

    data->percentDone = 100;
    data->fftData = fftPtr;

    mtx_unlock(&s_mutex);

    //printf("thread done\n");

    return 1;
}
Exemple #28
0
INT_PTR CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case IDCANCEL:
					DestroyWindow(h);
					break;
				case 10:
					{
						char file[MAX_PATH]="";
						ofn.lpstrFile=file;
						ofn.nMaxFile=MAX_PATH;
						if (GetOpenFileName(&ofn)) {
							BASS_StreamFree(chan); // free the old stream
							if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP))) {
								// it ain't playable
								MESS(10,WM_SETTEXT,0,"click here to open a file...");
								MESS(11,WM_SETTEXT,0,"");
								Error("Can't play the file");
								break;
							}
							MESS(10,WM_SETTEXT,0,file);
							{ // display the file type and length
								QWORD bytes=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
								DWORD time=BASS_ChannelBytes2Seconds(chan,bytes);
								BASS_CHANNELINFO info;
								BASS_ChannelGetInfo(chan,&info);
								sprintf(file,"channel type = %x (%s)\nlength = %I64u (%u:%02u)",
									info.ctype,GetCTypeString(info.ctype,info.plugin),bytes,time/60,time%60);
								MESS(11,WM_SETTEXT,0,file);
								MESS(12,TBM_SETRANGE,1,MAKELONG(0,time)); // update scroller range
							}
							BASS_ChannelPlay(chan,FALSE);
						}
					}
					break;
			}
			break;

		case WM_HSCROLL:
			if (l && LOWORD(w)!=SB_THUMBPOSITION && LOWORD(w)!=SB_ENDSCROLL) { // set the position
				int pos=SendMessage((HWND)l,TBM_GETPOS,0,0);
				BASS_ChannelSetPosition(chan,BASS_ChannelSeconds2Bytes(chan,pos),BASS_POS_BYTE);
			}
			break;

		case WM_TIMER:
			MESS(12,TBM_SETPOS,1,(DWORD)BASS_ChannelBytes2Seconds(chan,BASS_ChannelGetPosition(chan,BASS_POS_BYTE))); // update position
			break;

		case WM_INITDIALOG:
			win=h;
			// initialize default output device
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				break;
			}
			// initialize file selector
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;
			ofn.lpstrFilter=filter;
			memcpy(filter,"BASS built-in (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif)\0*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0",88);
			{ // look for plugins (in the executable's directory)
				WIN32_FIND_DATA fd;
				HANDLE fh;
				char path[MAX_PATH],*fp=filter+88;
				GetModuleFileName(0,path,sizeof(path));
				strcpy(strrchr(path,'\\')+1,"bass*.dll");
				fh=FindFirstFile(path,&fd);
				if (fh!=INVALID_HANDLE_VALUE) {
					do {
						HPLUGIN plug;
						if (plug=BASS_PluginLoad(fd.cFileName,0)) { // plugin loaded...
							const BASS_PLUGININFO *pinfo=BASS_PluginGetInfo(plug); // get plugin info to add to the file selector filter...
							int a;
							for (a=0;a<pinfo->formatc;a++) {
								fp+=sprintf(fp,"%s (%s) - %s",pinfo->formats[a].name,pinfo->formats[a].exts,fd.cFileName)+1; // format description
								fp+=sprintf(fp,"%s",pinfo->formats[a].exts)+1; // extension filter
							}
							// add plugin to the list
							MESS(20,LB_ADDSTRING,0,fd.cFileName);
						}
					} while (FindNextFile(fh,&fd));
					FindClose(fh);
				}
				if (!MESS(20,LB_GETCOUNT,0,0)) // no plugins...
					MESS(20,LB_ADDSTRING,0,"no plugins - visit the BASS webpage to get some");
				memcpy(fp,"All files\0*.*\0\0",15);
			}
			SetTimer(h,0,500,0); // timer to update the position
			return 1;

		case WM_DESTROY:
			// "free" the output device and all plugins
			BASS_Free();
			BASS_PluginFree(0);
			break;
	}
	return 0;
}
	void  setRow(float row) { BASS_ChannelSetPosition(stream, BASS_ChannelSeconds2Bytes(stream, float(row / rowRate)), BASS_POS_BYTE); }
Exemple #30
0
void PlaybackWidget::seek(float ratio)
{
    BASS_ChannelSetPosition(curchan,ratio*cursongblength,BASS_POS_BYTE);
}