void clAudioSource_OpenAL::Play()
{
#if L_AUDIO_USE_OPENAL

//   if ( IsPlaying() ) alSourceStop( FSourceID );
	if ( IsPlaying() ) { return; }

	Lint State;

	alGetSourcei( FSourceID, AL_SOURCE_STATE, &State );

	if ( !FWaveDataProvider )
	{
		return;
	}

	//FATAL( , "No data provider is attached to the audio source" );

	if ( State != AL_PAUSED && FWaveDataProvider->IsStreaming() )
	{
		UnqueueAll();

		StreamBuffer( FBufferID[0], BUFFER_SIZE );
		StreamBuffer( FBufferID[1], BUFFER_SIZE );

		alSourceQueueBuffers( FSourceID, 2, &FBufferID[0] );

		dynamic_cast<clAudioSubSystem_OpenAL*>( Env->Audio )->RegisterSource( this );
	}

	alSourcePlay( FSourceID );
#endif
}
void clAudioSource_OpenAL::PrepareBuffers()
{
	if ( !m_DataProvider ) return;

	int State;
	alGetSourcei( m_SourceID, AL_SOURCE_STATE, &State );

	if ( State != AL_PAUSED && m_DataProvider->IsStreaming() )
	{
		UnqueueAllBuffers();

		int BuffersToQueue = 2;

		StreamBuffer( m_BufferID[0], BUFFER_SIZE );
		if ( StreamBuffer( m_BufferID[1], BUFFER_SIZE ) == 0 )
		{
			if ( IsLooping() )
			{
				m_DataProvider->Seek(0);
				StreamBuffer(m_BufferID[1], BUFFER_SIZE);
			}
			else
			{
				BuffersToQueue = 1;
			}
		}

		alSourceQueueBuffers( m_SourceID, BuffersToQueue, &m_BufferID[0] );

		m_AudioSubsystem->RegisterSource( shared_from_this() );
	}
}
void clAudioSource::Update( float DeltaSeconds )
{
	if ( !FWaveDataProvider ) { return; }

	if ( !IsPlaying() ) { return; }

	if ( FWaveDataProvider->IsStreaming() )
	{
		int Processed;
		alGetSourcei( FSourceID, AL_BUFFERS_PROCESSED, &Processed );

		while ( Processed-- )
		{
			unsigned int BufID;
			alSourceUnqueueBuffers( FSourceID, 1, &BufID );

			StreamBuffer( BufID, BUFFER_SIZE );

			if ( FWaveDataProvider->IsEOF() )
			{
				if ( FLooping )
				{
					FWaveDataProvider->Seek( 0 );
				}

				StreamBuffer( BufID, BUFFER_SIZE );
			}

			alSourceQueueBuffers( FSourceID, 1, &BufID );
		}
	}
}
const bool cSoundSourceStream::Play(){
	// adds this to step list for handle streaming
	mpSoundSystem->mlSourceStream.push_back(this);

	// init buffers
	if(RemainingBytes() > 0)StreamBuffer(mlBuffer[0]);
	if(RemainingBytes() > 0)StreamBuffer(mlBuffer[1]);
	// and stream them
	alSourceQueueBuffers(miId, 2, (ALuint *)mlBuffer);
	CheckOpenAl();	
	
	// and play them
	return cSoundSourceOpenAl::Play();
}
void clAudioSource_OpenAL::EnqueueOneBuffer()
{
	ALuint BufID;
	alSourceUnqueueBuffers( m_SourceID, 1, &BufID );

	size_t Size = this->StreamBuffer( BufID, BUFFER_SIZE );

	if ( m_DataProvider->IsEndOfStream() )
	{
		if ( this->IsLooping() )
		{
			m_DataProvider->Seek( 0 );
			if ( !Size ) Size = StreamBuffer( BufID, BUFFER_SIZE );
		}
	}

	if ( Size )
	{
		alSourceQueueBuffers(m_SourceID, 1, &BufID);
	}
	else
	{
		// there is nothing more to play, but don't stop now if something is still playing
		if ( !this->IsPlaying() ) this->Stop();
	}
}
void clAudioSource_OpenAL::Update( float DeltaSeconds )
{
#if L_AUDIO_USE_OPENAL

	if ( !FWaveDataProvider ) { return; }

	if ( !IsPlaying() ) { return; }

	if ( FWaveDataProvider->IsStreaming() )
	{
		Lint Processed;

		alGetSourcei( FSourceID, AL_BUFFERS_PROCESSED, &Processed );

		while ( Processed-- )
		{
			Luint BufID;

			alSourceUnqueueBuffers( FSourceID, 1, &BufID );

			StreamBuffer( BufID, BUFFER_SIZE );

			if ( FWaveDataProvider->IsEOF() )
			{
				// FIXME: crash
				/*
				            if ( !FLooping )
				            {
				               UnqueueAll();
				               break;
				            }
				*/
				if ( FLooping ) { FWaveDataProvider->Seek( 0 ); }

				StreamBuffer( BufID, BUFFER_SIZE );
			}

			alSourceQueueBuffers( FSourceID, 1, &BufID );
		}
	}

#endif

	iAudioSource::Update( DeltaSeconds );
}
void clAudioSource::Play()
{
	if ( IsPlaying() ) { return; }

	if ( !FWaveDataProvider ) { return; }

	int State;
	alGetSourcei( FSourceID, AL_SOURCE_STATE, &State );

	if ( State != AL_PAUSED && FWaveDataProvider->IsStreaming() )
	{
		UnqueueAll();

		StreamBuffer( FBufferID[0], BUFFER_SIZE );
		StreamBuffer( FBufferID[1], BUFFER_SIZE );

		alSourceQueueBuffers( FSourceID, 2, &FBufferID[0] );
	}

	alSourcePlay( FSourceID );
}
Beispiel #8
0
void StreamBuffer::separate(const StreamBuffer& buffer, std::vector<StreamBuffer>& separated) {
    unsigned int offset = 0;
    unsigned char bufCount = buffer.buffer[offset++];
    while(separated.size() < bufCount)
        separated.push_back(StreamBuffer());
    for(unsigned int i = 0; i < bufCount; i++) {
        StreamBuffer& piece = separated[i];
        unsigned int *pieceSize = (unsigned int*)(buffer.buffer + offset);
        offset += sizeof(unsigned int);
        piece.write(buffer.buffer + offset, *pieceSize);
        offset += piece.size;
    }
}
void cSoundSourceStream::Step(){
	int processed = 0;

	if(RemainingBytes() == 0 && IsPlaying() && !IsPaused()){
		// sound is finished
		Stop();
	} else if(IsPlaying() && RemainingBytes() > 0){
		// read the number of played buffers
		alGetSourcei(miId, AL_BUFFERS_PROCESSED, &processed);
		CheckOpenAl();
		
		// and refill them
		while(processed--){
			ALuint buffer;
			alSourceUnqueueBuffers(miId, 1, &buffer);
			CheckOpenAl();
			StreamBuffer(buffer);		
			alSourceQueueBuffers(miId, 1, &buffer);
			CheckOpenAl();
			//printf("#### source step remaining=%i playing=%d paused=%d\n",mpStream->RemainingBytes(),IsPlaying(),IsPaused());
		}
	}
}
Beispiel #10
0
StreamBuffer &StreamBuffer::operator=(const StreamBuffer &rhs){
	StreamBuffer(rhs).swap(*this);
	return *this;
}
Beispiel #11
0
StreamBuffer &StreamBuffer::operator=(const StreamBuffer &rhs){
	if(&rhs != this){
		StreamBuffer(rhs).Swap(*this);
	}
	return *this;
}
Beispiel #12
0
bool Panel::MakeListFile(string& ListFileName, bool ShortNames, string_view const Modifers)
{
	uintptr_t CodePage = CP_OEMCP;

	if (!Modifers.empty())
	{
		if (contains(Modifers, L'A')) // ANSI
		{
			CodePage = CP_ACP;
		}
		else if (contains(Modifers, L'U')) // UTF8
		{
			CodePage = CP_UTF8;
		}
		else if (contains(Modifers, L'W')) // UTF16LE
		{
			CodePage = CP_UNICODE;
		}
	}

	const auto& transform = [&](string& strFileName)
	{
		if (!Modifers.empty())
		{
			if (contains(Modifers, L'F') && PointToName(strFileName).size() == strFileName.size()) // 'F' - использовать полный путь; //BUGBUG ?
			{
				strFileName = path::join(ShortNames ? ConvertNameToShort(m_CurDir) : m_CurDir, strFileName); //BUGBUG ?
			}

			if (contains(Modifers, L'Q')) // 'Q' - заключать имена с пробелами в кавычки;
				QuoteSpaceOnly(strFileName);

			if (contains(Modifers, L'S')) // 'S' - использовать '/' вместо '\' в путях файлов;
			{
				ReplaceBackslashToSlash(strFileName);
			}
		}
	};

	try
	{
		ListFileName = MakeTemp();
		if (const auto ListFile = os::fs::file(ListFileName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS))
		{
			os::fs::filebuf StreamBuffer(ListFile, std::ios::out);
			std::ostream Stream(&StreamBuffer);
			Stream.exceptions(Stream.badbit | Stream.failbit);
			encoding::writer Writer(Stream, CodePage);

			for (const auto& i: enum_selected())
			{
				auto Name = ShortNames? i.AlternateFileName() : i.FileName;

				transform(Name);

				Writer.write(Name);
				Writer.write(L"\r\n"sv);
			}

			Stream.flush();
		}
		else
		{
			throw MAKE_FAR_EXCEPTION(msg(lng::MCannotCreateListTemp));
		}

		return true;
	}
	catch (const far_exception& e)
	{
		os::fs::delete_file(ListFileName);
		Message(MSG_WARNING, e.get_error_state(),
			msg(lng::MError),
			{
				msg(lng::MCannotCreateListFile),
				e.get_message()
			},
			{ lng::MOk });
		return false;
	}
}