// 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,1))) { 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 { DWORD bpp1=BASS_ChannelSeconds2Bytes(chan,0.001); // minimum 1ms per pixel if (bpp<bpp1) bpp=bpp1; } BASS_ChannelSetSync(chan,BASS_SYNC_END|BASS_SYNC_MIXTIME,0,LoopSyncProc,0); // set sync to loop at end BASS_ChannelPlay(chan,FALSE); // start playing { // create another channel to scan DWORD chan2=BASS_StreamCreateFile(FALSE,file,0,0,BASS_STREAM_DECODE); if (!chan2) chan2=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_DECODE,1); scanthread=_beginthread(ScanPeaks,0,(void*)chan2); // start scanning in a new thread } return TRUE; }
void OpenClicked(GtkButton *obj, gpointer data) { int resp=gtk_dialog_run(GTK_DIALOG(filesel)); gtk_widget_hide(filesel); if (resp==GTK_RESPONSE_ACCEPT) { char *file=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filesel)); // free both MOD and stream, it must be one of them! :) BASS_MusicFree(chan); BASS_StreamFree(chan); if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_SAMPLE_FLOAT)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMPS|BASS_SAMPLE_LOOP|BASS_SAMPLE_FLOAT,1))) { // whatever it is, it ain't playable gtk_button_set_label(obj,"click here to open a file..."); Error("Can't play the file"); } else { BASS_CHANNELINFO info; BASS_ChannelGetInfo(chan,&info); if (info.chans!=2) { // the DSP expects stereo gtk_button_set_label(obj,"click here to open a file..."); BASS_MusicFree(chan); BASS_StreamFree(chan); Error("only stereo sources are supported"); } else { gtk_button_set_label(obj,file); // setup DSPs on new channel and play it RotateToggled(GTK_TOGGLE_BUTTON(GetWidget("rotate")),0); EchoToggled(GTK_TOGGLE_BUTTON(GetWidget("echo")),0); FlangerToggled(GTK_TOGGLE_BUTTON(GetWidget("flanger")),0); BASS_ChannelPlay(chan,FALSE); } } g_free(file); } }
//used to load the music list PUBLIC void GUTLoadMusicList(const char *filename) { FILE *fp = fopen(filename, "rt"); char path[DMAXCHARBUFF], buff[MAXCHARBUFF]; if(fp) { GUTClearMusicList(); fscanf(fp, "numMusic=%d\n", &g_gameMusic.numMusic); if(g_gameMusic.numMusic) { if(MemAlloc((void**)&g_gameMusic.music, sizeof(HMUSIC)*g_gameMusic.numMusic, M_ZERO) != RETCODE_SUCCESS) { ASSERT_MSG(0, "Unable to allocate music list", "GUTLoadMusicList"); return; } for(int i = 0; i < g_gameMusic.numMusic; i++) { fscanf(fp, "%[^\n]\n", buff); strcpy(path, MUSICDIR); strcat(path, buff); g_gameMusic.music[i] = BASS_MusicLoad(FALSE, path, 0, 0, 0);//BASS_MUSIC_CALCLEN); } } fclose(fp); } }
// select a file to play, and play it BOOL PlayFile() { BOOL ret=FALSE; regex_t fregex; GtkWidget *filesel; // file selector GtkFileFilter *filter; filesel=gtk_file_chooser_dialog_new("Open File",GTK_WINDOW(win),GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL); filter=gtk_file_filter_new(); gtk_file_filter_set_name(filter,"Playable files"); regcomp(&fregex,"\\.(mo3|xm|mod|s3m|it|umx|mp[1-3]|ogg|wav|aif)$",REG_ICASE|REG_NOSUB|REG_EXTENDED); gtk_file_filter_add_custom(filter,GTK_FILE_FILTER_FILENAME,FileExtensionFilter,&fregex,NULL); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter); filter=gtk_file_filter_new(); gtk_file_filter_set_name(filter,"All files"); gtk_file_filter_add_pattern(filter,"*"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter); if (gtk_dialog_run(GTK_DIALOG(filesel))==GTK_RESPONSE_ACCEPT) { char *file=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filesel)); gtk_widget_hide(filesel); if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP,1))) { Error("Can't play file"); } else { BASS_ChannelPlay(chan,FALSE); ret=TRUE; } g_free(file); } gtk_widget_destroy(filesel); return ret; }
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; }
float CBassAudio::GetSoundBPM ( void ) { if ( m_fBPM == 0.0f && !m_bStream ) { float fData = 0.0f; // open the same file as played but for bpm decoding detection DWORD bpmChan = BASS_StreamCreateFile ( false, m_strPath, 0, 0, BASS_STREAM_DECODE ); if ( !bpmChan ) { bpmChan = BASS_MusicLoad ( false, m_strPath, 0, 0, BASS_MUSIC_DECODE|BASS_MUSIC_PRESCAN, 0 ); } // detect bpm in background and return progress in GetBPM_ProgressCallback function if ( bpmChan ) { fData = BASS_FX_BPM_DecodeGet ( bpmChan, 0, GetLength ( ), 0, BASS_FX_FREESOURCE, NULL, NULL ); } if ( BASS_ErrorGetCode ( ) != BASS_OK ) { g_pCore->GetConsole ( )->Printf ( "BASS ERROR %d in BASS_FX_BPM_DecodeGet path:%s 3d:%d loop:%d", BASS_ErrorGetCode ( ), *m_strPath, m_b3D, m_bLoop ); } else { m_fBPM = floor ( fData ); } BASS_FX_BPM_BeatFree ( bpmChan ); } return m_fBPM; }
// select a file to play, and play it BOOL PlayFile() { BOOL ret=FALSE; NavDialogRef fileDialog; NavDialogCreationOptions fo; NavGetDefaultDialogCreationOptions(&fo); fo.optionFlags=0; fo.parentWindow=win; NavCreateChooseFileDialog(&fo,NULL,NULL,NULL,NULL,NULL,&fileDialog); if (!NavDialogRun(fileDialog)) { NavReplyRecord r; if (!NavDialogGetReply(fileDialog,&r)) { AEKeyword k; FSRef fr; if (!AEGetNthPtr(&r.selection,1,typeFSRef,&k,NULL,&fr,sizeof(fr),NULL)) { char file[256]; FSRefMakePath(&fr,(BYTE*)file,sizeof(file)); if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP,1))) { Error("Can't play file"); } else { BASS_ChannelPlay(chan,FALSE); ret=TRUE; } } NavDisposeReply(&r); } } NavDialogDispose(fileDialog); return ret; }
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; }
void InitSoundSystem(HWND hwnd) { if (!BASS_Init(-1,44100,0,hwnd,NULL)) ExitProcess(0); chan=BASS_MusicLoad(FALSE,"mario airlines (keygen edit).xm",0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN|BASS_MUSIC_SURROUND2,0); BASS_ChannelPlay(chan,FALSE); }
void AddClicked(GtkButton *obj, gpointer data) { // add a channel int resp=gtk_dialog_run(GTK_DIALOG(filesel)); gtk_widget_hide(filesel); if (resp==GTK_RESPONSE_ACCEPT) { char *file=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filesel)); DWORD newchan; // Load a music or sample from "file" if ((newchan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP|BASS_SAMPLE_3D,1)) || (newchan=BASS_SampleLoad(FALSE,file,0,0,1,BASS_SAMPLE_LOOP|BASS_SAMPLE_3D|BASS_SAMPLE_MONO))) { Channel *c; chanc++; chans=(Channel*)realloc((void*)chans,chanc*sizeof(Channel)); c=chans+chanc-1; memset(c,0,sizeof(Channel)); c->channel=newchan; BASS_SampleGetChannel(newchan,FALSE); // initialize sample channel { // add it to the list GtkTreeView *tree=GTK_TREE_VIEW(GetWidget("channels")); GtkListStore *tm=GTK_LIST_STORE(gtk_tree_view_get_model(tree)); GtkTreeIter it; gtk_list_store_append(tm,&it); gtk_list_store_set(tm,&it,0,strrchr(file,'/')+1,-1); } } else Error("Can't load file (note samples must be mono)"); g_free(file); } }
// --[ Method ]--------------------------------------------------------------- // // - Class : CSoundSystem // - prototype : CSound* LoadSound(CInput* pInput, const std::string& strExt) // // - Purpose : Loads a sound, setting it ready to play. // If succesfull, it returns a valid handle to operate // with, otherwise it returns NULL. // // ----------------------------------------------------------------------------- CSound* CSoundSystem::LoadSound(CInput* pInput, const std::string& strExt) { if(m_bActive == false) { return NULL; } // Put it into a buffer: pInput->SetPosition(0, CInput::SEEKFROM_START); char* pBuffer = new char[pInput->GetLength()]; assert(pBuffer); if(pInput->ReadRawData(pInput->GetLength(), 1, pBuffer) == 0) { CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\npInput->ReadRawData() failed"); SAFE_DELETE_A(pBuffer); return NULL; } CSound* pSound = NULL; if(IsModule(strExt)) { HMUSIC module = BASS_MusicLoad(TRUE, pBuffer, 0, pInput->GetLength(), 0); if(!module) { CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\nBASS_MusicLoad() failed"); return NULL; } CSound* pSound = new CSoundModule(module, pBuffer); m_vecSounds.push_back(pSound); return pSound; } else if(IsStream(strExt)) { HSTREAM stream = BASS_StreamCreateFile(TRUE, pBuffer, 0, pInput->GetLength(), BASS_MP3_SETPOS); if(!stream) { CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\nBASS_StreamCreateFile() failed"); return NULL; } CSound* pSound = new CSoundStream(stream, pBuffer); m_vecSounds.push_back(pSound); return pSound; } SAFE_DELETE_A(pBuffer); CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\nUnknown format (%s)", strExt.data()); return NULL; }
//----------------------------------------------------------------------------- bool LLFFTSound::loadSound(const char* filename, const char* speech, bool looping) { // set speech contents strcpy(m_Speech, speech); #ifdef _WINDOWS // initialize BASS if (!bBassInit) { if (!BASS_Init(-1,44100,0,0,NULL)) { //Error("Can't initialize device"); return false; } bBassInit = true; } if (looping) { if (!(m_dChannel=BASS_StreamCreateFile(FALSE,filename,0,0,BASS_SAMPLE_LOOP)) && !(m_dChannel=BASS_MusicLoad(FALSE,filename,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP,0))) { return false; // Can't load the file } } else { if (!(m_dChannel=BASS_StreamCreateFile(FALSE,filename,0,0,0)) && !(m_dChannel=BASS_MusicLoad(FALSE,filename,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP,0))) { return false; // Can't load the file } } m_bInitialized = true; return true; #else return false; #endif }
HMUSIC start_playback(const char* filename) { HMUSIC music = BASS_MusicLoad( FALSE, filename, 0, 0, BASS_MUSIC_PRESCAN, 0 ); BASS_ChannelPlay(music, FALSE); return music; }
bool BassDecoder::_load(const uint8_t* buffer, unsigned int size) { _mod=false; #if defined(LIBTOOLS_WINDOWS) && !defined(BASS_H) if (BASS_MusicLoad && BASS_StreamCreateFile && BASS_ChannelGetInfo) { #endif if (_music=BASS_MusicLoad(TRUE, (void*) buffer, 0,size, BASS_MUSIC_PRESCAN | BASS_MUSIC_DECODE | BASS_SAMPLE_FLOAT, Signal::frequency)) { _mod=true; } else if (_music=BASS_StreamCreateFile(TRUE, (void*) buffer, 0, size, BASS_STREAM_PRESCAN | BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT)); if (_music) { BASS_ChannelGetInfo((DWORD)_music,&_infos); _bytesFrame= sizeof(float)*Signal::size*_infos.chans; _samplesForSignals = (float*) realloc(_samplesForSignals,_bytesFrame); _sampleRate=_infos.freq; if (_sampleRate != Signal::frequency) std::cout << "warning : file rate (" << _sampleRate << "Hz) is different of " << Signal::frequency << "Hz" << std::endl; _ended=false; if (prepareDecode()) { decodeID3v1(); decodeOGGTag(); } } #if defined(LIBTOOLS_WINDOWS) && !defined(BASS_H) } else { std::cerr << "Error missing bass fonctions in DLL " << std::endl; } #endif return (_music); }
void DecodingBPM(BOOL newStream, double startSec, double endSec, const char *fp) { char c[30]; if (newStream){ // Open file for bpm decoding detection hBPM = BASS_StreamCreateFile(FALSE, fp, 0, 0, BASS_STREAM_DECODE); if (!hBPM) hBPM = BASS_MusicLoad(FALSE, fp, 0, 0, BASS_MUSIC_DECODE|BASS_MUSIC_PRESCAN, 0); } orgBPM = BASS_FX_BPM_DecodeGet(hBPM, startSec, endSec, 0, BASS_FX_BPM_BKGRND|BASS_FX_BPM_MULT2|BASS_FX_FREESOURCE, (BPMPROCESSPROC*)GetBPM_Process); // don't bother to update the BPM view if it's zero if (orgBPM) { // update the bpm view sprintf(c,"BPM: %0.2f", GetNewBPM(hBPM)); MESS(IDC_SBPM,WM_SETTEXT,0,c); } }
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; }
// select a file to play, and play 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*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.umx;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0"; if (!GetOpenFileName(&ofn)) return FALSE; if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP,0))) { Error("Can't play file"); return FALSE; // Can't load the file } BASS_ChannelPlay(chan,FALSE); return TRUE; }
void main(int argc, char **argv) { BUFSTUFF b,b2; BASS_3DVECTOR p={0,0,0}; printf("BASS 2 stereo channels on 4 speakers example : MOD/MPx/OGG/WAV\n" "--------------------------------------------------------------\n" " Set your soundcard's output to 4 or 5.1 speakers\n"); /* check that BASS 1.6 was loaded */ if (BASS_GetVersion()!=MAKELONG(1,6)) { printf("BASS version 1.6 was not loaded\n"); return; } if (argc!=3) { printf("\tusage: 4speaker <file1> <file2>\n"); return; } /* setup output - default device, 44100hz, stereo, 16 bits */ if (!BASS_Init(-1,44100,BASS_DEVICE_3D,0)) Error("Can't initialize device"); /* try initializing the 1st (front) file */ if (!(b.dstr=BASS_StreamCreateFile(FALSE,argv[1],0,0,BASS_STREAM_DECODE))) if (!(b.dstr=BASS_MusicLoad(FALSE,argv[1],0,0,BASS_MUSIC_DECODE|BASS_MUSIC_RAMPS))) Error("Can't play the 1st file"); if (BASS_ChannelGetFlags(b.dstr)&BASS_SAMPLE_MONO) Error("The 1st stream is mono!"); /* try initializing the 2nd (rear) file */ if (!(b2.dstr=BASS_StreamCreateFile(FALSE,argv[2],0,0,BASS_STREAM_DECODE))) if (!(b2.dstr=BASS_MusicLoad(FALSE,argv[2],0,0,BASS_MUSIC_DECODE|BASS_MUSIC_RAMPS))) Error("Can't play the 2nd file"); if (BASS_ChannelGetFlags(b2.dstr)&BASS_SAMPLE_MONO) Error("The 2nd stream is mono!"); printf("front : %s\n",argv[1]); printf("rear : %s\n",argv[2]); /* Get sample rates and allocate buffers */ BASS_ChannelGetAttributes(b.dstr,&b.freq,0,0); b.buf=malloc(b.freq*4); // 1 sec buffer BASS_ChannelGetAttributes(b2.dstr,&b2.freq,0,0); b2.buf=malloc(b2.freq*4); // 1 sec buffer /* Create streams to play the 1st decoded data, and link them */ b.lstr=BASS_StreamCreate(b.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_left,(DWORD)&b); b.rstr=BASS_StreamCreate(b.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_right,(DWORD)&b); BASS_ChannelSetLink(b.lstr,b.rstr); /* Create streams to play the 2nd decoded data, and link them */ b2.lstr=BASS_StreamCreate(b2.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_left,(DWORD)&b2); b2.rstr=BASS_StreamCreate(b2.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_right,(DWORD)&b2); BASS_ChannelSetLink(b2.lstr,b2.rstr); /* position the streams */ p.z=3; // front p.x=-1.5; // left BASS_ChannelSet3DPosition(b.lstr,&p,0,0); p.x=1.5; // right BASS_ChannelSet3DPosition(b.rstr,&p,0,0); p.z=-3; // rear p.x=-1.5; // left BASS_ChannelSet3DPosition(b2.lstr,&p,0,0); p.x=1.5; // right BASS_ChannelSet3DPosition(b2.rstr,&p,0,0); BASS_Apply3D(); BASS_Start(); /* start it! */ b.writepos=b.readposl=b.readposr=0; BASS_StreamPlay(b.lstr,FALSE,0); // start front b2.writepos=b2.readposl=b2.readposr=0; BASS_StreamPlay(b2.lstr,FALSE,0); // start rear while (!_kbhit() && (BASS_ChannelIsActive(b.lstr) || BASS_ChannelIsActive(b2.lstr))) { /* display some stuff and wait a bit */ printf("pos %09I64d %09I64d - cpu %.1f%% \r", BASS_ChannelGetPosition(b.lstr)*2,BASS_ChannelGetPosition(b2.lstr)*2,BASS_GetCPU()); Sleep(50); } BASS_Free(); free(b.buf); }
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; }
bool BassDecoder::_open(const string_t& filename) { _mod=false; #if defined(LIBTOOLS_WINDOWS) && !defined(BASS_H) if (BASS_MusicLoad && BASS_StreamCreateFile && BASS_StreamCreateURL && BASS_ChannelGetInfo) { #endif //std::wcerr << "Try loading: " << filename.toWideString() << std::endl; bass_unicode_string_t bass_unicode_str=string_t_to_bass_unicode_string_t(filename); void* unicode_filename=(void*)bass_unicode_str.c_str(); if (_music=BASS_MusicLoad(FALSE, unicode_filename, 0,0, BASS_MUSIC_PRESCAN | BASS_MUSIC_DECODE | BASS_SAMPLE_FLOAT | BASS_UNICODE, Signal::frequency)) { _mod=true; } else if (_music=BASS_StreamCreateFile(FALSE, unicode_filename, 0,0, BASS_STREAM_PRESCAN | BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT | BASS_UNICODE)); else if (_music=BASS_StreamCreateURL((const char *)unicode_filename,0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT | BASS_UNICODE, (DOWNLOADPROC*) 0, (void*)0)); if (_music) { BASS_ChannelGetInfo((DWORD)_music,&_infos); _bytesFrame= sizeof(float)*Signal::size*_infos.chans; _samplesForSignals = (float*) realloc(_samplesForSignals,_bytesFrame); _sampleRate=_infos.freq; if (_sampleRate != Signal::frequency) { #ifndef NDEBUG std::cout << "warning : file rate (" << _sampleRate << "Hz) is different of " << Signal::frequency << "Hz" << std::endl; #endif } _ended=false; if (prepareDecode()) { decodeID3v1(); decodeOGGTag(); } } #if defined(LIBTOOLS_WINDOWS) && !defined(BASS_H) } else { #ifndef NDEBUG std::cerr << "Error missing bass fonctions in DLL " << std::endl; #endif } #endif return (_music); }
// // 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; }
void SoundModuleBASS::Load(void *inBuffer, int inSize) { mHandle = BASS_MusicLoad(TRUE, inBuffer, 0, inSize, 0); }
void SoundModuleBASS::Load(const char *inName) { mHandle = BASS_MusicLoad(FALSE, (void*)inName, 0, 0, 0); SetFileName(inName); }
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; }
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 ); }
pascal OSStatus OpenEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { DWORD p; NavDialogRef fileDialog; NavDialogCreationOptions fo; NavGetDefaultDialogCreationOptions(&fo); fo.optionFlags=0; fo.parentWindow=win; NavCreateChooseFileDialog(&fo,NULL,NULL,NULL,NULL,NULL,&fileDialog); if (!NavDialogRun(fileDialog)) { NavReplyRecord r; if (!NavDialogGetReply(fileDialog,&r)) { AEKeyword k; FSRef fr; if (!AEGetNthPtr(&r.selection,1,typeFSRef,&k,NULL,&fr,sizeof(fr),NULL)) { char file[256]; FSRefMakePath(&fr,(BYTE*)file,sizeof(file)); BASS_StreamFree(chan); // free old streams before opening new // create decode channel chan = BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE|BASS_STREAM_PRESCAN); // check for MOD if (!chan) chan = BASS_MusicLoad(FALSE, file, 0, 0, BASS_SAMPLE_FLOAT|BASS_MUSIC_RAMP|BASS_STREAM_DECODE|BASS_MUSIC_PRESCAN,0); if (!chan) { SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file && play it...")); Error("Selected file couldn't be loaded!"); } else { // create new stream - decoded & reversed // 2 seconds decoding block as a decoding channel if (!(chan=BASS_FX_ReverseCreate(chan, 2, BASS_STREAM_DECODE|BASS_FX_FREESOURCE))) { SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file && play it...")); Error("Couldn't create a reversed stream!"); BASS_StreamFree(chan); BASS_MusicFree(chan); } else { // create a new stream - decoded & resampled :) if (!(chan=BASS_FX_TempoCreate(chan, BASS_SAMPLE_LOOP|BASS_FX_FREESOURCE))){ SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file && play it...")); Error("Couldn't create a resampled stream!"); BASS_StreamFree(chan); BASS_MusicFree(chan); } else { // update the Button to show the loaded file c2pstrcpy((BYTE*)file,file); SetControlTitle(inUserData,(BYTE*)file); // update the position slider p = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE)); SetControl32BitMaximum(GetControl(15),p); SetControl32BitValue(GetControl(15),p); // set Volume p = GetControl32BitValue(GetControl(11)); BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, (float)p/100.0f); // update tempo slider SetControl32BitValue(GetControl(13),0); SetStaticText(12,"Tempo = 0%"); // play new created stream BASS_ChannelPlay(chan,FALSE); } } } } NavDisposeReply(&r); } } NavDialogDispose(fileDialog); return noErr; }
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.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.umx;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0"; ofn.lpstrFile=file; if (GetOpenFileName(&ofn)) { // free both MOD and stream, it must be one of them! :) BASS_MusicFree(chan); BASS_StreamFree(chan); #if 1 // with FX flag if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_SAMPLE_FX)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP|BASS_SAMPLE_FX,1))) { #else // without FX flag if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP,1))) { #endif // whatever it is, it ain't playable MESS(10,WM_SETTEXT,0,"click here to open a file..."); Error("Can't play the file"); break; } MESS(10,WM_SETTEXT,0,file); { // setup the effects BASS_DX8_PARAMEQ p; fx[0]=BASS_ChannelSetFX(chan,BASS_FX_DX8_PARAMEQ,0); fx[1]=BASS_ChannelSetFX(chan,BASS_FX_DX8_PARAMEQ,0); fx[2]=BASS_ChannelSetFX(chan,BASS_FX_DX8_PARAMEQ,0); fx[3]=BASS_ChannelSetFX(chan,BASS_FX_DX8_REVERB,0); p.fGain=0; p.fBandwidth=18; p.fCenter=125; BASS_FXSetParameters(fx[0],&p); p.fCenter=1000; BASS_FXSetParameters(fx[1],&p); p.fCenter=8000; BASS_FXSetParameters(fx[2],&p); UpdateFX(0); UpdateFX(1); UpdateFX(2); UpdateFX(3); } BASS_ChannelPlay(chan,FALSE); } } break; } break; case WM_VSCROLL: if (l) { UpdateFX(GetDlgCtrlID((HWND)l)-20); } break; case WM_INITDIALOG: win=h; memset(&ofn,0,sizeof(ofn)); ofn.lStructSize=sizeof(ofn); ofn.hwndOwner=h; ofn.nMaxFile=MAX_PATH; ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER; // setup output - default device if (!BASS_Init(-1,44100,0,win,NULL)) { Error("Can't initialize device"); DestroyWindow(win); break; } { // check that DX8 features are available BASS_INFO bi={sizeof(bi)}; BASS_GetInfo(&bi); if (bi.dsver<8) { BASS_Free(); Error("DirectX 8 is not installed"); DestroyWindow(win); } } // initialize eq/reverb sliders MESS(20,TBM_SETRANGE,FALSE,MAKELONG(0,20)); MESS(20,TBM_SETPOS,TRUE,10); MESS(21,TBM_SETRANGE,FALSE,MAKELONG(0,20)); MESS(21,TBM_SETPOS,TRUE,10); MESS(22,TBM_SETRANGE,FALSE,MAKELONG(0,20)); MESS(22,TBM_SETPOS,TRUE,10); MESS(23,TBM_SETRANGE,FALSE,MAKELONG(0,20)); MESS(23,TBM_SETPOS,TRUE,20); return 1; case WM_DESTROY: BASS_Free(); break; } return 0; } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) { // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { MessageBox(0,"An incorrect version of BASS.DLL was loaded",0,MB_ICONERROR); return 0; } { // enable trackbar support INITCOMMONCONTROLSEX cc={sizeof(cc),ICC_BAR_CLASSES}; InitCommonControlsEx(&cc); } DialogBox(hInstance,(char*)1000,0,&dialogproc); return 0; }
BOOL 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: { BASS_CHANNELINFO info; char file[MAX_PATH]=""; ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.umx;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0"; ofn.lpstrFile=file; if (GetOpenFileName(&ofn)) { // free both MOD and stream, it must be one of them! :) BASS_MusicFree(chan); BASS_StreamFree(chan); if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|floatable)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMPS|floatable,1))) { // whatever it is, it ain't playable MESS(10,WM_SETTEXT,0,"click here to open a file..."); Error("Can't play the file"); break; } BASS_ChannelGetInfo(chan,&info); if (info.chans!=2) { // only stereo is allowed MESS(10,WM_SETTEXT,0,"click here to open a file..."); BASS_MusicFree(chan); BASS_StreamFree(chan); Error("only stereo sources are supported"); break; } MESS(10,WM_SETTEXT,0,file); // setup DSPs on new channel and play it SendMessage(win,WM_COMMAND,11,0); SendMessage(win,WM_COMMAND,12,0); SendMessage(win,WM_COMMAND,13,0); BASS_ChannelPlay(chan,FALSE); } } break; case 11: // toggle "rotate" if (MESS(11,BM_GETCHECK,0,0)) { rotpos=0.7853981f; rotdsp=BASS_ChannelSetDSP(chan,&Rotate,0,2); } else BASS_ChannelRemoveDSP(chan,rotdsp); break; case 12: // toggle "echo" if (MESS(12,BM_GETCHECK,0,0)) { memset(echbuf,0,sizeof(echbuf)); echpos=0; echdsp=BASS_ChannelSetDSP(chan,&Echo,0,1); } else BASS_ChannelRemoveDSP(chan,echdsp); break; case 13: // toggle "flanger" if (MESS(13,BM_GETCHECK,0,0)) { memset(flabuf,0,sizeof(flabuf)); flapos=0; flas=FLABUFLEN/2; flasinc=0.002f; fladsp=BASS_ChannelSetDSP(chan,&Flange,0,0); } else BASS_ChannelRemoveDSP(chan,fladsp); break; } break; case WM_INITDIALOG: win=h; memset(&ofn,0,sizeof(ofn)); ofn.lStructSize=sizeof(ofn); ofn.hwndOwner=h; ofn.nMaxFile=MAX_PATH; ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER; // enable floating-point DSP BASS_SetConfig(BASS_CONFIG_FLOATDSP,TRUE); // initialize - default device if (!BASS_Init(-1,44100,0,win,NULL)) { Error("Can't initialize device"); DestroyWindow(win); break; } // check for floating-point capability floatable=BASS_StreamCreate(44100,2,BASS_SAMPLE_FLOAT,NULL,0); if (floatable) { // woohoo! BASS_StreamFree(floatable); floatable=BASS_SAMPLE_FLOAT; } return 1; case WM_DESTROY: BASS_Free(); break; } return 0; }
bool KNMusicBackendBassThread::loadFromFile(const QString &filePath) { //Stop the thread first. stop(); //Release all the sync handle. releaseSyncHandle(); //Load the file to thread. //Check is the file the current file. if(filePath==m_filePath) { resetState(); //Emit load succeed signal. emit loaded(); return true; } //Clear the file path. m_filePath.clear(); //Try to load the file. #ifdef Q_OS_WIN32 std::wstring uniPath=filePath.toStdWString(); if(!(m_channel=BASS_StreamCreateFile(FALSE, uniPath.data(), 0, 0, BASS_UNICODE | KNMusicBassGlobal::fdps())) && !(m_channel=BASS_MusicLoad(FALSE, uniPath.data(), 0, 0, BASS_UNICODE | BASS_MUSIC_RAMPS | KNMusicBassGlobal::fdps(),1))) #endif #ifdef Q_OS_UNIX std::string uniPath=filePath.toStdString(); if(!(m_channel=BASS_StreamCreateFile(FALSE, uniPath.data(), 0, 0, KNMusicBassGlobal::fdps())) && !(m_channel=BASS_MusicLoad(FALSE, uniPath.data(), 0, 0, BASS_MUSIC_RAMPS | KNMusicBassGlobal::fdps(),1))) #endif { //Loaded failed, emit cannot load signal. emit cannotLoadFile(); return false; } //Backup the file path. m_filePath=filePath; //Emit load succeed. emit loaded(); //Establish sync handle. establishSyncHandle(); //When loading the file complete, set the channel info to the thread. //Get the byte duration. m_totalDuration=BASS_ChannelBytes2Seconds(m_channel, BASS_ChannelGetLength(m_channel, BASS_POS_BYTE))*1000; //Change the duration. emit durationChanged(m_totalDuration); //Reset the thread. resetState(); return true; }
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l) { switch (m) { case WM_COMMAND: switch (LOWORD(w)) { case IDCANCEL: DestroyWindow(h); return 1; case 10: { char file[MAX_PATH]=""; ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.mp3;*.mp2;*.mp1;*.ogg;*.wav\0All files\0*.*\0\0"; ofn.lpstrFile=file; if (GetOpenFileName(&ofn)) { memcpy(path,file,ofn.nFileOffset); path[ofn.nFileOffset-1]=0; // free both MOD and stream, it must be one of them! :) BASS_MusicFree(chan); BASS_StreamFree(chan); if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,floatable?BASS_SAMPLE_FLOAT:0)) && !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_LOOP|BASS_MUSIC_RAMP|(floatable?BASS_MUSIC_FLOAT:0)))) { // whatever it is, it ain't playable MESS(10,WM_SETTEXT,0,"click here to open a file..."); Error("Can't play the file"); break; } if (BASS_ChannelGetFlags(chan)&BASS_SAMPLE_MONO) { // mono = not allowed MESS(10,WM_SETTEXT,0,"click here to open a file..."); BASS_MusicFree(chan); BASS_StreamFree(chan); Error("mono sources are not supported"); break; } MESS(10,WM_SETTEXT,0,file); // setup DSPs on new channel SendMessage(win,WM_COMMAND,11,0); SendMessage(win,WM_COMMAND,12,0); SendMessage(win,WM_COMMAND,13,0); // play both MOD and stream, it must be one of them! BASS_MusicPlay(chan); BASS_StreamPlay(chan,0,BASS_SAMPLE_LOOP); } } return 1; case 11: // toggle "rotate" if (MESS(11,BM_GETCHECK,0,0)) { rotpos=0.7853981f; rotdsp=BASS_ChannelSetDSP(chan,&Rotate,0); } else BASS_ChannelRemoveDSP(chan,rotdsp); break; case 12: // toggle "echo" if (MESS(12,BM_GETCHECK,0,0)) { memset(echbuf,0,sizeof(echbuf)); echpos=0; echdsp=BASS_ChannelSetDSP(chan,&Echo,0); } else BASS_ChannelRemoveDSP(chan,echdsp); break; case 13: // toggle "flanger" if (MESS(13,BM_GETCHECK,0,0)) { memset(flabuf,0,sizeof(flabuf)); flapos=0; flas=FLABUFLEN/2; flasinc=0.002f; fladsp=BASS_ChannelSetDSP(chan,&Flange,0); } else BASS_ChannelRemoveDSP(chan,fladsp); break; } 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.lpstrInitialDir=path; ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER; // initialize - default device, 44100hz, stereo, 16 bits, floating-point DSP if (!BASS_Init(-1,44100,BASS_DEVICE_FLOATDSP,win)) { Error("Can't initialize device"); DestroyWindow(win); return 1; } BASS_Start(); // check for floating-point capability floatable=BASS_StreamCreate(44100,BASS_SAMPLE_FLOAT,NULL,0); if (floatable) BASS_StreamFree(floatable); // woohoo! return 1; } return 0; }