void NLS::Sound::Play(bool loop) { if (!stream) { if (loop) { stream = BASS_StreamCreateFile(true, data->data, 0, data->len, BASS_SAMPLE_FLOAT|BASS_SAMPLE_LOOP); } else { stream = BASS_StreamCreateFile(true, data->data, 0, data->len, BASS_SAMPLE_FLOAT); } } BASS_ChannelPlay(stream, !loop); }
// 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); } }
/* Поток для загрузки музыки в плейлист */ DWORD WINAPI Thread(LPVOID lp) { HDROP hDrop = (HDROP)lp; CHAR szFileName[MAX_PATH]; TCHAR buff[MAX_PATH]; DWORD dwCount = DragQueryFileA(hDrop, 0xFFFFFFFF, szFileName, MAX_PATH); //Определение количества загружаемых песен for (INT i = 0; i < dwCount; i++) { DragQueryFileA(hDrop, i, szFileName, MAX_PATH); //Определение пути к файлу INT len = strlen(szFileName); CHAR buffFormat[4]; //Формат песни INT j = 0; //для прохода по буферу формата песни for (INT i = len - 4; i < len; i++) { buffFormat[j] = szFileName[i]; j++; } if (me_strcmp(".mp3", buffFormat)) { HSTREAM stream = BASS_StreamCreateFile(0, szFileName, 0, 0, 0); //Создание потока mbstowcs(buff, szFileName, MAX_PATH); //преобразование CHAR to TCHAR DlgPlayList::_this->addSongToPlayList(stream, buff); //Добавление песни в плейлист } } DragFinish(hDrop); return FALSE; }
bool CBackgroundAudio::InitializeBASS() { bool bBassInitializedSuccessfully = false; //BASS default device constant const int kBASSDefaultDevice = -1; //Output rate of 44.1 kHz... const int kOutputRateHz = 44100; //Initialize the BASS library.. if(::BASS_Init(kBASSDefaultDevice, kOutputRateHz, 0, 0, NULL) && this->mpFileBuffer && (this->mFileBufferSize > 0)) { //Create a BASS audio stream, using the file in the memory //buffer (the stream will be looped, as indicated by the appropriate //flag)... HSTREAM hBassAudioStream = BASS_StreamCreateFile(true, this->mpFileBuffer, 0, this->mFileBufferSize, BASS_SAMPLE_LOOP); if(hBassAudioStream) { this->mhBassAudioStream = hBassAudioStream; } } return(bBassInitializedSuccessfully); }
/** * @brief No incoming parameters. Get data from RCHAN. Creating the stream file. If BASS_StreamCreateFile is failure colled BASS_Free(). * @param No params */ void Widget::stopRecording() { if (BASS_ChannelGetData(rchan, this->fft, BASS_DATA_FFT1024 | BASS_DATA_FFT_COMPLEX) == -1) { QDEBUG("Cannot get recbuf from rchan"); QDEBUG(BASS_ErrorGetCode()); } BASS_ChannelStop(rchan); rchan=0; ui->pushButton->setText(tr("Record")); // complete the WAVE header *(DWORD*)(recbuf+4)=reclen-8; *(DWORD*)(recbuf+40)=reclen-44; // enable "save" button ui->pushButton_3->setEnabled(true); // setup output device (using default device) if (!BASS_Init(-1,44100,0,NULL,NULL)) { QDEBUG(BASS_ErrorGetCode()); QDEBUG("Can't initialize output device"); return; } // create a stream from the recording if (chan=BASS_StreamCreateFile(TRUE,recbuf,0,reclen,BASS_SAMPLE_FLOAT)) { //ui->pushButton_2->setEnabled(true); // enable "play" button } else BASS_Free(); ui->pushButton->setEnabled(true); }
// 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; }
int Music_decode(text_t* path, MusicData* data) { QWORD len; thrd_t id; if (thrd_busy == mtx_trylock(&s_mutex)) { Dialog_showError(TEXT("Decoding of stream already in-progress. Re-open after it's been completed.")); return 1; } // now this will break if we already have a thread running. free(data->fftData); data->fftData = 0; int flags = BASS_STREAM_DECODE | BASS_SAMPLE_MONO | BASS_POS_SCAN; #ifdef _WIN32 flags |= BASS_UNICODE; #endif HSTREAM chan = BASS_StreamCreateFile(0, path, 0, 0, flags); if (!chan) { Dialog_showError(TEXT("Unable to open stream for decode. No music data will be available.")); mtx_unlock(&s_mutex); return 0; } len = BASS_ChannelGetLength(chan, BASS_POS_BYTE); if (len == -1) { Dialog_showError(TEXT("Stream has no length. No music data will be available.")); BASS_StreamFree(chan); mtx_unlock(&s_mutex); return 0; } ThreadFuncData* threadData = malloc(sizeof(ThreadFuncData)); threadData->stream = chan; threadData->data = data; data->percentDone = 1; data->fftData = 0; // So there is a race-condition here as the mutex is unclocked while the thread is crated but in practice // this won't be a problem mtx_unlock(&s_mutex); if (thrd_create(&id, decodeFunc, threadData) != thrd_success) { printf("Unable to create decode thread. Stalling main thread and running...\n"); decodeFunc(threadData); } return 1; }
render::render(char* song, bool play) { this->play = play; running = setupSDL(); if (play) { BASS_Init(-1, 44100, 0, NULL, NULL); HSTREAM stream; stream = BASS_StreamCreateFile(false, song, 0, 0, BASS_SAMPLE_FLOAT | BASS_STREAM_PRESCAN); sound_chan = stream; BASS_ChannelPlay(sound_chan, false); } srand(time(NULL)); for (int i = 0; i < BALL_SIZE; i++) { balls[i].setX(rand()%BOX_SIZE*2); balls[i].setY(rand()%BOX_SIZE*2); balls[i].setZ(rand()%BOX_SIZE*2); } rotx = 0; roty = 0; rotz = 0; box_x = 0; box_y = 0; box_z = 0; posx = 0; posy = 0; posz = 100; max = BALL_SIZE; }
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; }
void StopRecording() { BASS_ChannelStop(rchan); rchan=0; { // complete the WAVE header DWORD len=ftell(rfp),v; fseek(rfp,4,SEEK_SET); v=len-8; fwrite(&v,1,4,rfp); fseek(rfp,40,SEEK_SET); v=len-44; fwrite(&v,1,4,rfp); fclose(rfp); } MESS(10,WM_SETTEXT,0,L"Record"); // setup output device (using default device) if (!BASS_Init(-1,44100,0,NULL,NULL)) { Error(L"Can't initialize output device"); return; } // create a stream from the recording if (chan=BASS_StreamCreateFile(FALSE,L"bass.wav",0,0,BASS_UNICODE)) EnableWindow(DLGITEM(11),TRUE); // enable "play" button else BASS_Free(); }
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; }
// 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; }
void play(char *file) { if (status != 0) stop(); stream = BASS_StreamCreateFile(FALSE, file, 0, 0, 0); BASS_ChannelPlay(stream, 0); status = 1; printf("Now Playing :\n%s\n", file); // getInfo(1); //bug: causes to crash when songs with huge titles comein :| }
void Music::LoadMusic(const char *filename) { BOOL results; results = BASS_Init(-1, 44100, 0, NULL, NULL); if (results) { mp3Strewam = BASS_StreamCreateFile(false, filename, 0, 0, 0); } }
// --[ 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; }
void PlaybackWidget::changeSong(QString songPath) { stopSong(); curchan = BASS_StreamCreateFile(false,songPath.utf16(),0,0, BASS_SAMPLE_FLOAT | BASS_STREAM_AUTOFREE | BASS_UNICODE); BASS_ChannelPlay(curchan,false); cursongblength = BASS_ChannelGetLength(curchan, BASS_POS_BYTE); cursonglength = BASS_ChannelBytes2Seconds(curchan,cursongblength); changeState(PLAYING); }
HSTREAM CBassMusicEngine::LoadFile( LPCTSTR lpszFileName ) { tagMusicInfo _Info; ZeroMemory(&_Info,sizeof _Info); if (!(_Info.hStream = BASS_StreamCreateFile(FALSE, lpszFileName,0,0,BASS_SAMPLE_MONO))) { ShowError(TEXT("不能打开该文件")); return -1; } _Info.dwTime = BASS_ChannelBytes2Seconds(_Info.hStream,BASS_ChannelGetLength(_Info.hStream,BASS_POS_BYTE) ); TAG_ID3 *pTag = (TAG_ID3 *)BASS_ChannelGetTags(_Info.hStream,BASS_TAG_ID3); if ( pTag != NULL ) { #ifdef UNICODE MultiByteToWideChar(CP_ACP, 0, pTag->artist, -1, _Info.szArtist, 30); MultiByteToWideChar(CP_ACP, 0, pTag->title, -1, _Info.szTitle, 30); if ( lstrlen(_Info.szArtist) == 0 ) { lstrcpyn(_Info.szArtist,TEXT("未知"),CountArray(_Info.szArtist)); } if ( lstrlen(_Info.szTitle) == 0 ) { CString StrTitle(lpszFileName); StrTitle = StrTitle.Right(StrTitle.GetLength()-StrTitle.ReverseFind('\\')-1); StrTitle = StrTitle.Left(StrTitle.Find('.')); lstrcpyn(_Info.szTitle,StrTitle,CountArray(_Info.szTitle)); } #else lstrcpyn(_Info.szArtist,CString(pTag->artist),CountArray(_Info.szArtist)); lstrcpyn(_Info.szTitle,CString(pTag->title),CountArray(_Info.szTitle)); #endif } else { CString StrTitle(lpszFileName); StrTitle = StrTitle.Right(StrTitle.GetLength()-StrTitle.ReverseFind('\\')-1); StrTitle = StrTitle.Left(StrTitle.Find('.')); lstrcpyn(_Info.szArtist,TEXT("未知"),CountArray(_Info.szArtist)); lstrcpyn(_Info.szTitle,StrTitle,CountArray(_Info.szTitle)); } m_MusicEngineMap.insert(pair<HSTREAM,tagMusicInfo>(_Info.hStream,_Info)); //Play(_Info.hStream); return _Info.hStream; }
pascal OSStatus OpenEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { NavDialogRef fileDialog; NavDialogCreationOptions fo; NavGetDefaultDialogCreationOptions(&fo); fo.optionFlags=0; fo.parentWindow=win; NavCreateChooseFileDialog(&fo,NULL,NULL,NULL,NULL,NULL,&fileDialog); // if someone wants to somehow get the file selector to filter like in the Windows example, that'd be nice ;) 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 stream before opening new if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_SAMPLE_FLOAT))) { SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file...")); { ControlRef cref=GetControl(11); SetControlData(cref,kControlNoPart,kControlStaticTextTextTag,0,""); DrawOneControl(cref); } SetControl32BitMaximum(GetControl(12),0); Error("Can't play the file"); } else { CFStringRef cs=CFStringCreateWithCString(0,file,kCFStringEncodingUTF8); SetControlTitleWithCFString(inUserData,cs); CFRelease(cs); { // 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 = %llu (%u:%02u)", info.ctype,GetCTypeString(info.ctype,info.plugin),bytes,time/60,time%60); { ControlRef cref=GetControl(11); SetControlData(cref,kControlNoPart,kControlStaticTextTextTag,strlen(file),file); DrawOneControl(cref); } SetControl32BitMaximum(GetControl(12),time); // update scroller range } BASS_ChannelPlay(chan,FALSE); } } NavDisposeReply(&r); } } NavDialogDispose(fileDialog); return noErr; }
//----------------------------------------------------------------------------- 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 }
AudioClip::AudioClip(std::string filename) { pan = 0.0f; volume = 1.0f; pitch = 0.0f; loop = false; play_once = false; oshot = false; std::wstring fname(filename.begin(), filename.end()); hm = BASS_StreamCreateFile(FALSE, fname.c_str(), 0, 0, BASS_STREAM_DECODE); hm = BASS_FX_TempoCreate(hm, BASS_FX_FREESOURCE); }
bool Player::Load(const char filename[]) { BASS_ChannelStop(stream); BASS_StreamFree(stream); stream = BASS_StreamCreateFile(false, filename, 0, 0, 0); if (stream == NULL) return false; stopped = true; paused = false; BASS_ChannelGetAttribute(stream, BASS_ATTRIB_FREQ, &defaulSampleRate); pitchedSampleRate = defaulSampleRate; return true; }
TError StreamSample::Init() { if ( GetFilename() ) { const char *file = GetFilename()->ToCString(); m_stream = BASS_StreamCreateFile(FALSE, file, 0, 0 , 0); } else { return TError::ERROR; } return OK; }
static int OnPlaySnd(WPARAM wParam, LPARAM lParam) { TCHAR* ptszFile = (TCHAR*)lParam; SYSTEMTIME systime; BOOL doPlay = TRUE; GetLocalTime(&systime); WORD currtime = MAKEWORD(systime.wMinute, systime.wHour); WORD currstat = 1; switch (CallService(MS_CLIST_GETSTATUSMODE, 0, 0)) { case ID_STATUS_OUTTOLUNCH: currstat <<= 1; case ID_STATUS_ONTHEPHONE: currstat <<= 1; case ID_STATUS_INVISIBLE: currstat <<= 1; case ID_STATUS_FREECHAT: currstat <<= 1; case ID_STATUS_DND: currstat <<= 1; case ID_STATUS_OCCUPIED: currstat <<= 1; case ID_STATUS_NA: currstat <<= 1; case ID_STATUS_AWAY: currstat <<= 1; case ID_STATUS_ONLINE: currstat <<= 1; } if (!db_get_b(NULL, "Skin", "UseSound", 0)) doPlay = FALSE; if (QuietTime) if ( ((TimeWrd1 < TimeWrd2) && (TimeWrd1 <= currtime && currtime < TimeWrd2)) || ((TimeWrd2 < TimeWrd1) && (TimeWrd1 <= currtime || currtime < TimeWrd2)) ) doPlay = FALSE; if (!(currstat & StatMask)) doPlay = FALSE; if (Preview || (int)wParam == 1) doPlay = TRUE; if (!ptszFile) doPlay = FALSE; if (doPlay) { BASS_StreamFree(sndSSnd[sndNSnd]); sndSSnd[sndNSnd] = BASS_StreamCreateFile(FALSE, ptszFile, 0, 0, BASS_STREAM_AUTOFREE); BASS_ChannelPlay(sndSSnd[sndNSnd], FALSE); sndNSnd = (sndNSnd + 1) % sndLimSnd; } Preview = FALSE; return 1; }
/* Загрузка песни с компьютера */ BOOL Application::openFile_LoadMusic(HWND hWnd) { TCHAR path[MAX_PATH]; OPENFILENAME ofn = { 0 }; path[0] = '\0'; ofn.hInstance = GetModuleHandle(0); ofn.hwndOwner = hWnd; ofn.Flags = OFN_FILEMUSTEXIST;// | OFN_ALLOWMULTISELECT | OFN_EXPLORER; ofn.lpstrDefExt = TEXT("mp3"); ofn.lpstrFile = path; ofn.lpstrFilter = TEXT("(.mp3)\0*.mp3\0");// (.aif)\0 * .aif\0(.wav)\0 * .wav\0(.mp2)\0 * .mp2\0(.mp1)\0 * .mp1\0(.ogg)\0 * .ogg\0"); ofn.lpstrInitialDir = TEXT("d:\\"); ofn.lpstrTitle = TEXT("Open file"); ofn.lStructSize = sizeof(OPENFILENAME); ofn.nFilterIndex = 1; ofn.nMaxFile = MAX_PATH; if (GetOpenFileName(&ofn)) { if (hStream == NULL) { hStream = BASS_StreamCreateFile(FALSE, path, 0, 0, 0); setRangeTrackBarPlaySong(hStream); playlist.addSongToPlayList(hStream, path); } else { HSTREAM stream; stream = BASS_StreamCreateFile(FALSE, path, 0, 0, 0); setRangeTrackBarPlaySong(stream); playlist.addSongToPlayList(stream, path); } return TRUE; } return FALSE; }
void AudioPlayer::play_music(const char * const filepath, bool loop, float volume) { if (!m_initialized) return; HSTREAM channel = BASS_StreamCreateFile(FALSE, filepath, 0, 0, 0); BASS_ChannelSetAttribute(channel, BASS_ATTRIB_VOL, volume); if (loop) BASS_ChannelFlags(channel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); if (!BASS_ChannelPlay(channel, FALSE)) log::error("Failed to play music: %", filepath); else m_music_stream = channel; }
/************************************************************************* * Initialize bass *************************************************************************/ void InitSound() { if (!BASS_Init(-1, 44100, 0, g_hWnd, 0)) { OutputDebugString("Failed to initialize bass"); ExitProcess(0); } g_stream = BASS_StreamCreateFile(false, "../data/4kintro.mp3", 0, 0, 0); if (!g_stream) { OutputDebugString("Failed to load mp3"); ExitProcess(0); } BASS_Start(); BASS_ChannelPlay(g_stream, false); }
ClientGame::ClientGame(int xSize, int ySize, bool playMusic) : m_host(1), m_state(&m_typeRegistry), m_notificationLog(&m_map, &m_mapParticles, &m_font, xSize, ySize) { m_server = NULL; m_time = 0; m_clientId = -1; m_gameState = GameState_MainMenu; m_mapScale = 1; m_xSize = xSize; m_ySize = ySize; m_mapState = State_Idle; m_blipX = 0; m_blipY = 0; m_serverId = -1; m_hoverStop = -1; m_hoverButton = ButtonId_None; m_xMapSize = 0; m_yMapSize = 0; m_gridSpacing = 0; m_selectedAgent = -1; m_maxPlayersInGame = 0; m_gameOverTime = 0; m_isWinner = false; m_totalNumIntels = 0; m_timeAdjustment = 0; m_pathLength = 0; m_nextStop = -1; for (int i = 0; i < ButtonId_NumButtons; ++i) { m_button[i].toggled = false; } UpdateActiveButtons(); m_music = BASS_StreamCreateFile(FALSE, "assets/get_a_groove.mp3", 0, 0, BASS_SAMPLE_LOOP); if (playMusic) { BASS_ChannelPlay(m_music, TRUE); } m_lanListener.Initialize(Protocol::listenPort); m_random.Seed(SDL_GetTicks()); }
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); }
HEFFECT CALL HGE_Impl::Effect_Load(const char *filename, DWORD size) { DWORD _size, length, samples; HSAMPLE hs; HSTREAM hstrm; BASS_CHANNELINFO info; void *buffer, *data; if(hBass) { if(bSilent) return 1; if(size) { data=(void *)filename; _size=size; } else { data=Resource_Load(filename, &_size); if(!data) return NULL; } hs=BASS_SampleLoad(TRUE, data, 0, _size, 4, BASS_SAMPLE_OVER_VOL); if(!hs) { hstrm=BASS_StreamCreateFile(TRUE, data, 0, _size, BASS_STREAM_DECODE); if(hstrm) { length=(DWORD)BASS_ChannelGetLength(hstrm); BASS_ChannelGetInfo(hstrm, &info); samples=length; if(info.chans < 2) samples>>=1; if((info.flags & BASS_SAMPLE_8BITS) == 0) samples>>=1; buffer=BASS_SampleCreate(samples, info.freq, 2, 4, info.flags | BASS_SAMPLE_OVER_VOL); if(!buffer) { BASS_StreamFree(hstrm); _PostError("Can't create sound effect: Not enough memory"); } else { BASS_ChannelGetData(hstrm, buffer, length); hs=BASS_SampleCreateDone(); BASS_StreamFree(hstrm); if(!hs) _PostError("Can't create sound effect"); } } } if(!size) Resource_Free(data); return hs; }