// // 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; }
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; }