Example #1
0
int CPaInput::Read( sqbind::CSqBinary *data, int frames )
{_STT();

	// Sanity checks
	if ( !m_stream || !data )
		return 0;

	// Use number of bytes available if blocking
	if ( m_bBlocking && 0 >= frames )
		frames = Pa_GetStreamReadAvailable( m_stream );

	// Anything new to read?
	if ( !frames )
		return data->getUsed();

	// How many bytes to read?
	unsigned long bytes = frames * getFrameBytes();
	if ( !m_bBlocking && 0 >= bytes )
		bytes = m_buf.GetMaxRead();

	// Ensure space
	unsigned long total = bytes + data->getUsed();
	unsigned long reserve = oex::cmn::NextPower2( total );
	if ( data->Size() < reserve )
		if ( !data->Resize( reserve ) )
			return data->getUsed();

	if ( m_bBlocking )
	{
		// Must specify an amount for blocking read
		if ( 0 >= bytes )
			return data->getUsed();

		// Read from stream
		m_errLast = Pa_ReadStream( m_stream, (void*)data->Ptr( data->getUsed() ), frames );
		if ( paNoError == m_errLast )
			data->setUsed( total );

	} // end if

	else
	{
		oex::CCircBuf::t_size uRead = 0;

		// Read the string from the buffer
		m_buf.Read( (oex::oexPVOID)data->Ptr( data->getUsed() ), bytes, &uRead );

		// Bounds check bytes read
		if ( uRead < 0 ) 
			uRead = 0;
		else if ( uRead > bytes ) 
			uRead = bytes;

		// Set new buffer size
		data->setUsed( data->getUsed() + uRead );

	} // end else

	return data->getUsed();
}
Example #2
0
int SoundStream::ReadAvailable(){
	int n=Pa_GetStreamReadAvailable(stream);
	if(n<0){
		err=n;
		CHECK_ERR;
		return -1;
	}else
		return n;
}
void PortAudioRecordBackend::vuMeterTimerSlot() {
    int err;
    signed long availableFrames;
    float volume;

    volume = 0;
    availableFrames = Pa_GetStreamReadAvailable(vuMeterStream);

    if(availableFrames > 0) {
        float *buffer = new float[availableFrames];
        err = Pa_ReadStream(vuMeterStream, buffer, availableFrames);

        if(err != paNoError) {
            qDebug("Error reading from vuMeter stream:\n %s", Pa_GetErrorText(err));
            updateVuMeter(&volume);
            return;
        }

        for(int i = 0; i < availableFrames; i++) {
            volume = fmax(volume, fabs(buffer[i]));
        }

        if(volume < 0) {
            volume = 0;
        }

        if(volume > 1) {
            volume = 1;
        }

        updateVuMeter(&volume);

    } else {
        updateVuMeter(&volume);

#ifndef WIN32
        /*
         * FIXME:
         * Quite a hack to resolve an issue where the stream unexpectedly aborted.
         * Here we simply restart the whole shebang to resolve this situation.
         * This problem does not seem to occur in Windows.
         */
        closeVuMeterStream();
        createVuMeterStream();
#endif
    }
}
Example #4
0
void PortAudioRead::run()
{
    //this->index = Pa_GetDefaultInputDevice();
    const PaDeviceInfo* info = Pa_GetDeviceInfo(this->index);
    PaStream* stream = NULL;
    PaStreamParameters parameter;
    parameter.channelCount = 2;
    parameter.device = this->index;
    parameter.hostApiSpecificStreamInfo = NULL;
    parameter.sampleFormat = paInt24;
    parameter.suggestedLatency = info->defaultHighInputLatency;

    PaError err = Pa_OpenStream(&stream, &parameter, NULL, 44100, 1024, paNoFlag, NULL, NULL);
    //PaError err = Pa_OpenDefaultStream(&stream, 2, 0, paFloat32, 44100, paFramesPerBufferUnspecified, NULL, NULL);

    if (err == paNoError)
    {
        err = Pa_StartStream(stream);
    }

    char buffer[12288];

    while (!this->toEnd && err == paNoError)
    {
        long count = Pa_GetStreamReadAvailable(stream);
        if (count > 4096)
            count = 4096;
        if (count > 0)
        {
            err = Pa_ReadStream(stream, &buffer[0], count);
            if (err == paNoError)
            {
                this->rb->Put((samplePtr)&buffer, int24Sample, count * 2);
            }
        }
        else
        {
            msleep(100);
        }
    }

    Pa_StopStream(stream);

    Pa_CloseStream(stream);
}
Example #5
0
int quisk_read_portaudio(struct sound_dev * dev, complex * cSamples)
{	// Read sound samples from the soundcard.
	// Samples are converted to 32 bits with a range of +/- CLIP32 and placed into cSamples.
	int i;
	long avail;
	int nSamples;
	complex c;
	PaError error;
	float fi, fq;

	if (!dev->handle)
		return -1;

	avail = dev->read_frames;		// size of read request
	if (avail == 0) {				// non-blocking: read available frames
		avail = Pa_GetStreamReadAvailable((PaStream * )dev->handle);
		if (avail > SAMP_BUFFER_SIZE / dev->num_channels)		// limit read request to buffer size
			avail = SAMP_BUFFER_SIZE / dev->num_channels;
	}
	error = Pa_ReadStream ((PaStream * )dev->handle, fbuffer, avail);
	if (error != paNoError)
		quisk_sound_state.read_error++;
	nSamples = 0;
	for (i = 0; avail; i += dev->num_channels, nSamples++, avail--) {
		fi = fbuffer[i + dev->channel_I];
		fq = fbuffer[i + dev->channel_Q];
		if (fi >=  1.0 || fi <= -1.0)
			dev->overrange++;	// assume overrange returns max int
		if (fq >=  1.0 || fq <= -1.0)
			dev->overrange++;
		cSamples[nSamples] = (fi + I * fq) * CLIP32;
	}
	for (i = 0; i < nSamples; i++) {	// DC removal; R.G. Lyons page 553
		c = cSamples[i] + dev->dc_remove * 0.95;
		cSamples[i] = c - dev->dc_remove;
		dev->dc_remove = c;
	}
	return nSamples;
}
Example #6
0
static int pa_stream_readavailable(lua_State *L)
{
  pa_Stream *stream = NULL;
  int narg = lua_gettop(L);
  PaError err = 0;

  if(narg == 1 && luaT_isudata(L, 1, "pa.Stream"))
    stream = luaT_toudata(L, 1, "pa.Stream");
  else
    luaL_error(L, "expected arguments: Stream");

  if(!stream->id)
    luaL_error(L, "attempt to operate on a closed stream");

  err = Pa_GetStreamReadAvailable(stream->id);
  if(err >= 0)
    lua_pushnumber(L, err);
  else
    pa_checkerror(L, err);

  return 1;
}
JNIEXPORT jlong JNICALL
Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetStreamReadAvailable
    (JNIEnv *env, jclass clazz, jlong stream)
{
    return Pa_GetStreamReadAvailable(((PortAudioStream *) stream)->stream);
}
Example #8
0
_CGUL_EXPORT CGUL::SInt64 CGUL::PortAudio::Stream::ReadAvailable()
{
    return (SInt64)Pa_GetStreamReadAvailable(stream);
}
Example #9
0
_JATTA_EXPORT Jatta::SInt64 Jatta::PortAudio::Stream::ReadAvailable()
{
    return (SInt64)Pa_GetStreamReadAvailable(stream);
}
Example #10
0
int pa_stream_get_avail_data(phastream_t *as)
{
  return (int) Pa_GetStreamReadAvailable(PAIDEV(as));
}