void AudioClip::play()
{
	if (loop)
		BASS_ChannelFlags(hm, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);
	else
        BASS_ChannelFlags(hm, 0, BASS_SAMPLE_LOOP);

	if (play_once)
	{
		if (oshot)
		{
			BASS_ChannelSetAttribute(hm, BASS_ATTRIB_PAN, pan);
			BASS_ChannelSetAttribute(hm, BASS_ATTRIB_VOL, volume);
			BASS_ChannelSetAttribute(hm, BASS_ATTRIB_TEMPO_PITCH, pitch);
			BASS_ChannelPlay(hm, TRUE);
			playing = true;
			oshot = false;
		}
	}
	else
	{
		BASS_ChannelSetAttribute(hm, BASS_ATTRIB_PAN, pan);
		BASS_ChannelSetAttribute(hm, BASS_ATTRIB_VOL, volume);
		BASS_ChannelSetAttribute(hm, BASS_ATTRIB_TEMPO_PITCH, pitch);
		BASS_ChannelPlay(hm, TRUE);
		playing = true;
	}
}
Example #2
0
void SwapClicked(GtkButton *obj, gpointer data)
{
	const gchar *objname=gtk_widget_get_name(GTK_WIDGET(obj));
	int speaker=atoi(objname+4)-1; // get speaker pair number from button name ("swapX")
	{ // swap handles
		HSTREAM temp=chan[speaker];
		chan[speaker]=chan[speaker+1];
		chan[speaker+1]=temp;
	}
	{ // swap text
		GtkButton *open1,*open2;
		char bname[10],*temp;
		sprintf(bname,"open%d",1+speaker);
		open1=GTK_BUTTON(GetWidget(bname));
		sprintf(bname,"open%d",1+speaker+1);
		open2=GTK_BUTTON(GetWidget(bname));
		temp=strdup(gtk_button_get_label(open1));
		gtk_button_set_label(open1,gtk_button_get_label(open2));
		gtk_button_set_label(open2,temp);
		free(temp);
	}
	// update the channel devices
	BASS_ChannelFlags(chan[speaker],flags[speaker],BASS_SPEAKER_FRONT);
	BASS_ChannelFlags(chan[speaker+1],flags[speaker+1],BASS_SPEAKER_FRONT);
}
Example #3
0
		// play
		void BassSound3D::Play()
		{
			m_channel = BASS_SampleGetChannel(m_handle, FALSE);

			if (m_looping)
			{
				BASS_ChannelFlags(m_channel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);
			}
			else
			{
				BASS_ChannelFlags(m_channel, 0, BASS_SAMPLE_LOOP);
			}

			BASS_ChannelSetAttribute(m_channel, BASS_ATTRIB_VOL, m_volume);

			BASS_ChannelSet3DAttributes(m_channel, -1, m_minDistance, m_maxDistance, -1, -1, -1);

			BASS_3DVECTOR pos(m_Position.x, m_Position.y, m_Position.z);
			BASS_3DVECTOR vel(m_velocity.x, m_velocity.y, m_velocity.z);
			BASS_ChannelSet3DPosition(m_channel, &pos, NULL, &vel);

			BASS_Apply3D();

			BASS_ChannelPlay(m_channel, FALSE);
		}
Example #4
0
		// SetLoopingState
		void BassSound3D::SetLoopingState(bool loop)
		{
			m_looping = loop;

			if (m_looping)
			{
				BASS_ChannelFlags(m_channel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);
			}
			else
			{
				BASS_ChannelFlags(m_channel, 0, BASS_SAMPLE_LOOP);
			}
		}
Example #5
0
bool playMOD (int f, int a, int fromTrack) {
	if (soundOK) {

		stopMOD (a);

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

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

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

		if (! mod[a]) {

		}
		else
		{
			setMusicVolume (a, defVol);

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

			BASS_ChannelSetPosition (mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER);
			BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP);
		}
		setResourceForFatal (-1);
	}
    return true;
}
Example #6
0
HCHANNEL BassSoundEngine::PlayMusic(string filename, CHANNEL Ichannel, bool loop, float volume)
{
	if(Ichannel<0||Ichannel>=maxChannel)
	{
		Ichannel = GetNewChannel();
		if(Ichannel<0)
			return NULL;
	}else
		FreeChannel(Ichannel);

	HSTREAM sound = ReadMusic(filename);

	DWORD hr;

	// start play
	hr = BASS_ChannelPlay(sound, TRUE);

	// set volume
	volumeDes[Ichannel] = volume*defaultVolume;
	hr = BASS_ChannelSetAttribute(sound, BASS_ATTRIB_VOL, volumeDes[Ichannel]);

	// set loop
	if(loop)
		hr = BASS_ChannelFlags(sound, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);

	channel[Ichannel] = sound;

	return sound;
}
void CBSoundBuffer::SetLooping(bool looping)
{
	m_Looping = looping;

	if (m_Stream)
	{
		BASS_ChannelFlags(m_Stream, looping ? BASS_SAMPLE_LOOP : 0, BASS_SAMPLE_LOOP);
	}
}
Example #8
0
    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;
    }
Example #9
0
HCHANNEL BassSoundEngine::PlayMusic(int sound_id, CHANNEL Ichannel, bool loop, float volume)
{
	if(Ichannel<0||Ichannel>=maxChannel){
		Ichannel = GetNewChannel();
		if(Ichannel<0)
			return NULL;
	}else
		FreeChannel(Ichannel);
	HSTREAM sound = playMusic[sound_id];
	channel[Ichannel] = sound;

	DWORD hr;
	bool useDSP = false;

	// set position
	float freq;
	if(Ichannel==0)
	{
		hr = BASS_ChannelGetAttribute(sound, BASS_ATTRIB_FREQ, &freq);
		hr = SetPosition(0, sound_id, 0);
		hr = BASS_FX_TempoGetRateRatio(sound);
		if(hr>0)
			useDSP = true;
		music_sampleRate = freq;
	}

	// set volume
	volumeDes[Ichannel] = volume*defaultVolume;
	hr = BASS_ChannelSetAttribute(sound, BASS_ATTRIB_VOL, volumeDes[Ichannel]);

	// start play
	hr = BASS_ChannelPlay(sound, useDSP?FALSE:TRUE);

	// set loop
	if(loop)
		hr = BASS_ChannelFlags(sound, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);

	if(Ichannel==0)
		Update(0);

	return sound;
}
Example #10
0
bool startSound (int f, bool loopy) {
	if (soundOK) {
		int a = cacheSound (f);
		if (a == -1) return false;

		soundCache[a].looping = loopy;
		soundCache[a].vol = defSoundVol;

		soundCache[a].mostRecentChannel = BASS_SampleGetChannel (soundCache[a].sample, false);
		if (soundCache[a].mostRecentChannel)
		{
			BASS_ChannelPlay(soundCache[a].mostRecentChannel, true);
			BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel, BASS_ATTRIB_VOL, defSoundVol);
			if (loopy)
			{
				BASS_ChannelFlags(soundCache[a].mostRecentChannel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag
			}
		}

	}
	return true;
}
Example #11
0
//
// 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;
}