Exemple #1
0
void AudioSndio::run( void )
{
	surroundSampleFrame * temp =
	    new surroundSampleFrame[mixer()->framesPerPeriod()];
	int_sample_t * outbuf =
	    new int_sample_t[mixer()->framesPerPeriod() * channels()];

	while( TRUE )
	{
		const fpp_t frames = getNextBuffer( temp );
		if( !frames )
		{
			break;
		}

		uint bytes = convertToS16( temp, frames,
		    mixer()->masterGain(), outbuf, FALSE );
		if( sio_write( m_hdl, outbuf, bytes ) != bytes )
		{
			break;
		}
	}

	delete[] temp;
	delete[] outbuf;
}
Exemple #2
0
void AudioOss::run()
{
	surroundSampleFrame * temp =
		new surroundSampleFrame[mixer()->framesPerPeriod()];
	int_sample_t * outbuf =
			new int_sample_t[mixer()->framesPerPeriod() *
								channels()];

	while( true )
	{
		const fpp_t frames = getNextBuffer( temp );
		if( !frames )
		{
			break;
		}

		int bytes = convertToS16( temp, frames,
				mixer()->masterGain(), outbuf,
							m_convertEndian );
		if( write( m_audioFD, outbuf, bytes ) != bytes )
		{
			break;
		}
	}

	delete[] temp;
	delete[] outbuf;
}
bool ObjectDataIStream::getNextBuffer( uint32_t* compressor, uint32_t* nChunks,
                                       const void** chunkData, uint64_t* size )
{
    const Command* command = getNextCommand();
    if( !command )
        return false;

    const ObjectDataPacket* packet = command->get< ObjectDataPacket >();
    LBASSERT( packet->command == CMD_OBJECT_INSTANCE ||
              packet->command == CMD_OBJECT_DELTA ||
              packet->command == CMD_OBJECT_SLAVE_DELTA );

    if( packet->dataSize == 0 ) // empty packet
        return getNextBuffer( compressor, nChunks, chunkData, size );

    *size = packet->dataSize;
    *compressor = packet->compressorName;
    *nChunks = packet->nChunks;
    *size = packet->dataSize;
    switch( packet->command )
    {
      case CMD_OBJECT_INSTANCE:
        *chunkData = command->get< ObjectInstancePacket >()->data;
        break;
      case CMD_OBJECT_DELTA:
        *chunkData = command->get< ObjectDeltaPacket >()->data;
        break;
      case CMD_OBJECT_SLAVE_DELTA:
        *chunkData = command->get< ObjectSlaveDeltaPacket >()->data;
        break;
    }
    return true;
}
Exemple #4
0
command result_t StdControl.start() {
  
  uint8_t *rxBuffer = getNextBuffer(&receiveBufferSet);
  
  call BulkTxRx.BulkReceive(rxBuffer, RXLINELEN);
  return SUCCESS;
}
Exemple #5
0
int AudioPortAudio::process_callback(
	const float *_inputBuffer,
	float * _outputBuffer,
	unsigned long _framesPerBuffer )
{
	if( supportsCapture() )
	{
		mixer()->pushInputFrames( (sampleFrame*)_inputBuffer,
												_framesPerBuffer );
	}

	if( m_stopped )
	{
		memset( _outputBuffer, 0, _framesPerBuffer *
			channels() * sizeof(float) );
		return paComplete;
	}

	while( _framesPerBuffer )
	{
		if( m_outBufPos == 0 )
		{
			// frames depend on the sample rate
			const fpp_t frames = getNextBuffer( m_outBuf );
			if( !frames )
			{
				m_stopped = true;
				m_stopSemaphore.release();
				memset( _outputBuffer, 0, _framesPerBuffer *
					channels() * sizeof(float) );
				return paComplete;
			}
			m_outBufSize = frames;
		}
		const int min_len = qMin( (int)_framesPerBuffer,
			m_outBufSize - m_outBufPos );

		float master_gain = mixer()->masterGain();

		for( fpp_t frame = 0; frame < min_len; ++frame )
		{
			for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl )
			{
				( _outputBuffer + frame * channels() )[chnl] =
						Mixer::clip( m_outBuf[frame][chnl] *
						master_gain );
			}
		}

		_outputBuffer += min_len * channels();
		_framesPerBuffer -= min_len;
		m_outBufPos += min_len;
		m_outBufPos %= m_outBufSize;
	}

	return paContinue;
}
        int16* waitForFreeBuffer (Thread& threadToCheck)
        {
            while (numBlocksOut.get() == numBuffers)
            {
                dataArrived.wait (1);

                if (threadToCheck.threadShouldExit())
                    return nullptr;
            }

            return getNextBuffer();
        }
Exemple #7
0
void AudioSoundIo::writeCallback(int frameCountMin, int frameCountMax)
{
	const struct SoundIoChannelLayout *layout = &m_outstream->layout;
	SoundIoChannelArea *areas;
	int bytesPerSample = m_outstream->bytes_per_sample;
	int err;

	const float gain = mixer()->masterGain();

	int framesLeft = frameCountMax;

	while (framesLeft > 0)
	{
		int frameCount = framesLeft;
		if ((err = soundio_outstream_begin_write(m_outstream, &areas, &frameCount)))
		{
			errorCallback(err);
			return;
		}

		if (!frameCount)
			break;

		for (int frame = 0; frame < frameCount; frame += 1)
		{
			if (m_outBufFrameIndex >= m_outBufFramesTotal)
			{
				m_outBufFramesTotal = getNextBuffer(m_outBuf);
				m_outBufFrameIndex = 0;
			}

			for (int channel = 0; channel < layout->channel_count; channel += 1)
			{
				float sample = gain * m_outBuf[m_outBufFrameIndex][channel];
				memcpy(areas[channel].ptr, &sample, bytesPerSample);
				areas[channel].ptr += areas[channel].step;
			}
			m_outBufFrameIndex += 1;
		}

		if ((err = soundio_outstream_end_write(m_outstream)))
		{
			errorCallback(err);
			return;
		}

		framesLeft -= frameCount;
	}
}
Exemple #8
0
bool DataIStream::_checkBuffer()
{
    while( _impl->position >= _impl->inputSize )
    {
        uint32_t compressor = EQ_COMPRESSOR_NONE;
        uint32_t nChunks = 0;
        const void* data = 0;

        if( !getNextBuffer( compressor, nChunks, &data, _impl->inputSize ))
            return false;

        _impl->input = _decompress( data, compressor, nChunks,
                                    _impl->inputSize );
        _impl->position = 0;
    }
    return true;
}
Exemple #9
0
void*
kma_malloc(kma_size_t size)
{
	if (debug) printf("\nREQUEST %i\n", size);
	if (entryPoint == 0) {
		entryPoint = getEntryPoint();
	}
	
	int adjustedSize = size + sizeof(buffer);
	int bufferSize = getBufferSize(adjustedSize);
	freeListInfo* freeList = getFreeList(bufferSize);
	
	if (freeList == NULL) {
		return NULL;
	}
	
	getSpaceIfNeeded(freeList, bufferSize);
	return getNextBuffer(freeList);
}
Exemple #10
0
bool DataIStream::_checkBuffer()
{
    while (_impl->position >= _impl->inputSize)
    {
        CompressorInfo info;
        uint32_t nChunks = 0;
        const void* data = 0;

        _impl->position = 0;
        _impl->input = 0;
        _impl->inputSize = 0;

        if (!getNextBuffer(info, nChunks, data, _impl->inputSize))
            return false;

        _impl->input = _decompress(data, info, nChunks, _impl->inputSize);
    }
    return true;
}
bool ObjectDataIStream::getNextBuffer( uint32_t& compressor, uint32_t& nChunks,
                                       const void** chunkData, uint64_t& size )
{
    if( _commands.empty( ))
    {
        _usedCommand.clear();
        return false;
    }

    _usedCommand = _commands.front();
    _commands.pop_front();
    if( !_usedCommand.isValid( ))
        return false;

    LBASSERT( _usedCommand.getCommand() == CMD_OBJECT_INSTANCE ||
              _usedCommand.getCommand() == CMD_OBJECT_DELTA ||
              _usedCommand.getCommand() == CMD_OBJECT_SLAVE_DELTA );

    ObjectDataICommand command( _usedCommand );
    const uint64_t dataSize = command.getDataSize();

    if( dataSize == 0 ) // empty command
        return getNextBuffer( compressor, nChunks, chunkData, size );

    size = dataSize;
    compressor = command.getCompressor();
    nChunks = command.getChunks();
    switch( command.getCommand( ))
    {
      case CMD_OBJECT_INSTANCE:
        command.get< NodeID >();    // nodeID
        command.get< uint32_t >();  // instanceID
        break;
      case CMD_OBJECT_SLAVE_DELTA:
        command.get< UUID >();      // commit UUID
        break;
    }
    *chunkData = command.getRemainingBuffer( command.getRemainingBufferSize( ));

    setSwapping( command.isSwapping( ));
    return true;
}
Exemple #12
0
void AudioSdl::sdlAudioCallback( Uint8 * _buf, int _len )
{
	if( m_stopped )
	{
		memset( _buf, 0, _len );
		return;
	}

	while( _len )
	{
		if( m_convertedBufPos == 0 )
		{
			// frames depend on the sample rate
			const fpp_t frames = getNextBuffer( m_outBuf );
			if( !frames )
			{
				m_stopped = true;
				m_stopSemaphore.release();
				memset( _buf, 0, _len );
				return;
			}
			m_convertedBufSize = frames * channels()
						* sizeof( int_sample_t );

			convertToS16( m_outBuf, frames,
						mixer()->masterGain(),
						(int_sample_t *)m_convertedBuf,
						m_convertEndian );
		}
		const int min_len = qMin( _len, m_convertedBufSize
							- m_convertedBufPos );
		memcpy( _buf, m_convertedBuf + m_convertedBufPos, min_len );
		_buf += min_len;
		_len -= min_len;
		m_convertedBufPos += min_len;
		m_convertedBufPos %= m_convertedBufSize;
	}
}
Exemple #13
0
void AudioAlsa::run()
{
	surroundSampleFrame * temp =
		new surroundSampleFrame[mixer()->framesPerPeriod()];
	int_sample_t * outbuf =
			new int_sample_t[mixer()->framesPerPeriod() *
								channels()];
	int_sample_t * pcmbuf = new int_sample_t[m_periodSize * channels()];

	int outbuf_size = mixer()->framesPerPeriod() * channels();
	int outbuf_pos = 0;
	int pcmbuf_size = m_periodSize * channels();

	bool quit = false;
	while( quit == false )
	{
		int_sample_t * ptr = pcmbuf;
		int len = pcmbuf_size;
		while( len )
		{
			if( outbuf_pos == 0 )
			{
				// frames depend on the sample rate
				const fpp_t frames = getNextBuffer( temp );
				if( !frames )
				{
					quit = true;
					memset( ptr, 0, len
						* sizeof( int_sample_t ) );
					break;
				}
				outbuf_size = frames * channels();

				convertToS16( temp, frames,
						mixer()->masterGain(),
						outbuf,
						m_convertEndian );
			}
			int min_len = qMin( len, outbuf_size - outbuf_pos );
			memcpy( ptr, outbuf + outbuf_pos,
					min_len * sizeof( int_sample_t ) );
			ptr += min_len;
			len -= min_len;
			outbuf_pos += min_len;
			outbuf_pos %= outbuf_size;
		}

		f_cnt_t frames = m_periodSize;
		ptr = pcmbuf;

		while( frames )
		{
			int err = snd_pcm_writei( m_handle, ptr, frames );

			if( err == -EAGAIN )
			{
				continue;
			}

			if( err < 0 )
			{
				if( handleError( err ) < 0 )
				{
					printf( "Write error: %s\n",
							snd_strerror( err ) );
				}
				break;	// skip this buffer
			}
			ptr += err * channels();
			frames -= err;
		}
	}

	delete[] temp;
	delete[] outbuf;
	delete[] pcmbuf;
}
Exemple #14
0
int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata )
{
	for( int c = 0; c < channels(); ++c )
	{
		m_tempOutBufs[c] =
			(jack_default_audio_sample_t *) jack_port_get_buffer(
												m_outputPorts[c], _nframes );
	}

#ifdef AUDIO_PORT_SUPPORT
	const int frames = qMin<int>( _nframes, mixer()->framesPerPeriod() );
	for( jackPortMap::iterator it = m_portMap.begin();
						it != m_portMap.end(); ++it )
	{
		for( ch_cnt_t ch = 0; ch < channels(); ++ch )
		{
			if( it.data().ports[ch] == NULL )
			{
				continue;
			}
			jack_default_audio_sample_t * buf =
			(jack_default_audio_sample_t *) jack_port_get_buffer(
							it.data().ports[ch],
								_nframes );
			for( int frame = 0; frame < frames; ++frame )
			{
				buf[frame] = it.key()->firstBuffer()[frame][ch];
			}
		}
	}
#endif

	jack_nframes_t done = 0;
	while( done < _nframes && m_stopped == false )
	{
		jack_nframes_t todo = qMin<jack_nframes_t>(
						_nframes,
						m_framesToDoInCurBuf -
							m_framesDoneInCurBuf );
		const float gain = mixer()->masterGain();
		for( int c = 0; c < channels(); ++c )
		{
			jack_default_audio_sample_t * o = m_tempOutBufs[c];
			for( jack_nframes_t frame = 0; frame < todo; ++frame )
			{
				o[done+frame] = m_outBuf[m_framesDoneInCurBuf+frame][c] * gain;
			}
		}
		done += todo;
		m_framesDoneInCurBuf += todo;
		if( m_framesDoneInCurBuf == m_framesToDoInCurBuf )
		{
			m_framesToDoInCurBuf = getNextBuffer( m_outBuf );
			if( !m_framesToDoInCurBuf )
			{
				m_stopped = true;
				m_stopSemaphore.release();
			}
			m_framesDoneInCurBuf = 0;
		}
	}

	if( m_stopped == true )
	{
		for( int c = 0; c < channels(); ++c )
		{
			jack_default_audio_sample_t * b = m_tempOutBufs[c] + done;
			memset( b, 0, sizeof( *b ) * ( _nframes - done ) );
		}
	}

	return 0;
}