// select a file to play, and start scanning it BOOL PlayFile() { char file[MAX_PATH]=""; OPENFILENAME ofn={0}; ofn.lStructSize=sizeof(ofn); ofn.hwndOwner=win; ofn.nMaxFile=MAX_PATH; ofn.lpstrFile=file; ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER; ofn.lpstrTitle="Select a file to play"; ofn.lpstrFilter="Playable files\0*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif;*.mo3;*.it;*.xm;*.s3m;*.mtm;*.mod;*.umx\0All files\0*.*\0\0"; if (!GetOpenFileName(&ofn)) return FALSE; if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,0)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMPS|BASS_MUSIC_POSRESET|BASS_MUSIC_PRESCAN,0))) { Error("Can't play file"); return FALSE; // Can't load the file } { BYTE data[2000]={0}; BITMAPINFOHEADER *bh=(BITMAPINFOHEADER*)data; RGBQUAD *pal=(RGBQUAD*)(data+sizeof(*bh)); int a; bh->biSize=sizeof(*bh); bh->biWidth=WIDTH; bh->biHeight=-HEIGHT; bh->biPlanes=1; bh->biBitCount=8; bh->biClrUsed=bh->biClrImportant=HEIGHT/2+1; // setup palette for (a=1;a<=HEIGHT/2;a++) { pal[a].rgbRed=(255*a)/(HEIGHT/2); pal[a].rgbGreen=255-pal[a].rgbRed; } // create the bitmap wavebmp=CreateDIBSection(0,(BITMAPINFO*)bh,DIB_RGB_COLORS,(void**)&wavebuf,NULL,0); wavedc=CreateCompatibleDC(0); SelectObject(wavedc,wavebmp); } bpp=BASS_ChannelGetLength(chan,BASS_POS_BYTE)/WIDTH; // bytes per pixel if (bpp<BASS_ChannelSeconds2Bytes(chan,0.02)) // minimum 20ms per pixel (BASS_ChannelGetLevel scans 20ms) bpp=BASS_ChannelSeconds2Bytes(chan,0.02); BASS_ChannelSetSync(chan,BASS_SYNC_END|BASS_SYNC_MIXTIME,0,LoopSyncProc,0); // set sync to loop at end BASS_ChannelPlay(chan,FALSE); // start playing { // start scanning peaks in a new thread DWORD chan2=BASS_StreamCreateFile(FALSE,file,0,0,BASS_STREAM_DECODE); if (!chan2) chan2=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_DECODE,0); scanthread=_beginthread(ScanPeaks,0,chan2); } return TRUE; }
void CClientSound::SetPlayPosition ( unsigned int uiPosition ) { if ( m_pSound ) { BASS_ChannelSetPosition( m_pSound, BASS_ChannelSeconds2Bytes( m_pSound, uiPosition/1000 ), 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(); }
/** * 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; }
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; }
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); }
bool Seek(HSTREAM stream, int ms) { float secs = (float)ms / 1000.0f; QWORD pos = BASS_ChannelSeconds2Bytes(stream, secs); BASS_ChannelSetPosition(stream, pos); return true; }
/** * 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; } }
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); } }
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; }
void StreamRender::SlideMove(int pos){ //Timer->stop(); isSlider=true; //double posx = BASS_ChannelSeconds2Bytes( stream, pos); segungosTrascurridos= BASS_ChannelSeconds2Bytes( stream, pos); //BASS_ChannelSetPosition(stream, posx, BASS_POS_BYTE); return; }
// --[ 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; }
// 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 ); } }
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); } }
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; }
static BOOL Initialize() { BASS_INFO bi; // initialize output, get latency if (!BASS_Init(-1,44100,BASS_DEVICE_LATENCY,win,NULL)) { Error("Can't initialize output"); return FALSE; } BASS_GetInfo(&bi); if (bi.dsver<8) { // no DX8, so disable effect buttons EnableWindow(GetDlgItem(win,20),FALSE); EnableWindow(GetDlgItem(win,21),FALSE); EnableWindow(GetDlgItem(win,22),FALSE); EnableWindow(GetDlgItem(win,23),FALSE); } // create a stream to play the recording chan=BASS_StreamCreate(44100,2,0,STREAMPROC_PUSH,0); // start recording with 10ms period if (!BASS_RecordInit(-1) || !(rchan=BASS_RecordStart(44100,2,MAKELONG(0,10),RecordingCallback,0))) { BASS_RecordFree(); BASS_Free(); Error("Can't initialize recording"); return FALSE; } { // get list of inputs int c; const char *i; for (c=0;i=BASS_RecordGetInputName(c);c++) { float level; MESS(10,CB_ADDSTRING,0,i); if (!(BASS_RecordGetInput(c,&level)&BASS_INPUT_OFF)) { // this 1 is currently "on" input=c; MESS(10,CB_SETCURSEL,input,0); MESS(11,TBM_SETPOS,TRUE,level*100); // set level slider } } } { // prebuffer at least "minbuf" amount of data before starting playback DWORD prebuf=BASS_ChannelSeconds2Bytes(chan,bi.minbuf/1000.f); while (BASS_ChannelGetData(chan,NULL,BASS_DATA_AVAILABLE)<prebuf) Sleep(1); } BASS_ChannelPlay(chan,FALSE); return TRUE; }
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(); }
/* 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); } }
pascal void PosEventHandler(ControlHandle control, SInt16 part) { DWORD p=GetControl32BitValue(control); BASS_ChannelSetPosition(chan,BASS_ChannelSeconds2Bytes(chan,p),BASS_POS_BYTE); }
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; }
void setRow(float row) { BASS_ChannelSetPosition(stream, BASS_ChannelSeconds2Bytes(stream, float(row / rowRate)), BASS_POS_BYTE); }
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; }
BOOL BassSoundEngine::SetPosition(int chan_id, int sound_id, double timeInSeconds) { double tm_offset = timeInSeconds+playOffset[sound_id]*0.001; QWORD byte_posi = BASS_ChannelSeconds2Bytes(channel[chan_id], tm_offset); return BASS_ChannelSetPosition(channel[chan_id], byte_posi, BASS_POS_BYTE); }
static void bass_set_row(void *d, int row) { HSTREAM h = *((HSTREAM *)d); QWORD pos = BASS_ChannelSeconds2Bytes(h, row / row_rate); BASS_ChannelSetPosition(h, pos, BASS_POS_BYTE); }
void CSoundManager::SetMusicPosition(unsigned int position) { long seconds = BASS_ChannelSeconds2Bytes(m_stream, position / 1000.0); BASS_ChannelSetPosition(m_stream, seconds, BASS_POS_BYTE); }
bool BassPlayer::newPosProcessing(const qint64 & new_pos) { return BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, (new_pos + startPosition()) / BASS_POSITION_MULTIPLIER), BASS_POS_BYTE); }
void ControlEvent::SetMusicPosition(double seconds,HSTREAM m_stream) { QWORD p = BASS_ChannelSeconds2Bytes(m_stream,seconds); BASS_ChannelSetPosition(m_stream,p,BASS_POS_BYTE); }
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; }
void bmx_bass_channelseconds2bytes(DWORD handle, QWORD * bytes, double pos) { *bytes = BASS_ChannelSeconds2Bytes(handle, pos); }