Exemplo n.º 1
11
    void input(ALshort ** input_audio,ALshort ** output_audio) {
        ALint samples, val, state;
        // Если источник вдруг перестал играть, то пнем его
        alGetSourcei (al_source, AL_SOURCE_STATE,  &state);
        if (state != AL_PLAYING) alSourcePlay(al_source);

        alcGetIntegerv(in_device, ALC_CAPTURE_SAMPLES, sizeof(samples), &samples);
        if( (error=  alcGetError(in_device)) != AL_NO_ERROR)
            std::cout<<error<<" alcGetIntegerv "<<__LINE__<<"\n";
        alGetSourcei (al_source, AL_BUFFERS_PROCESSED , &val);
	
        while ( ( (val--) > 0) && (samples < play_buf_size)   ) {
            ALuint buffer;
	    //Write sound
            alcCaptureSamples(in_device, play_buf, samples);
	    //-Write sound

	    //Connect with main thread
	    for(int copy=0; copy<play_buf_size; copy++) input_audio[copy] = play_buf[copy];
	    for(int copy=0; copy<play_buf_size; copy++) play_buf[copy] = output_audio[copy];

	    //Play sound 
	    alSourceUnqueueBuffers(al_source, 1, &buffer);
            alBufferData(buffer, AL_FORMAT_STEREO16, play_buf, play_buf_size * sizeof(ALshort), play_buf_size);
            alSourceQueueBuffers(al_source, 1, &buffer);
	    //-Play sound

	    //Write sound
            alcGetIntegerv(in_device, ALC_CAPTURE_SAMPLES, sizeof(samples), &samples);
	    //-Write sound
        }
	
    }
Exemplo n.º 2
0
float* AudioAnalyzer::Capture() {
	if (!initialized)
		return NULL;

	ALCint sampled;

	alcGetIntegerv(inputDevice, ALC_CAPTURE_SAMPLES, 1, &sampled);

	if (sampled > captureSize) {
		// Grab the sound
		alcCaptureSamples(inputDevice, capturedBuffer, captureSize);

		const float theta = 2.0f * (3.1415926535898f) / captureSize;
		for (int i = 0; i < captureSize; i ++) {
			ar[i] = capturedBuffer[i] / 32768.0f;
			//		  ar[i] = 0.54 - 0.46 * cos(2.0 * (3.1415926535898f) * (float)capturedBuffer[i] / 32768.0);
			ai[i] = 0.0f;

		}
		fft(captureSize, theta , ar, ai);

		for (int i = 0; i < captureSize; i ++) { 
			ffted[i] = 4.0f * sqrtf(ar[i]*ar[i] + ai[i]*ai[i]) / captureSize;
		}
		return ffted;
	}

	return NULL;
}
Exemplo n.º 3
0
void OpenAL2::captureSamples(ALCdevice* device, int16_t* buffer, ALCsizei samples)
{
    alcCaptureSamples(device, buffer, samples);
    if (echoCancelSupported && filterer) {
        filter_audio(filterer, buffer, samples);
    }
}
void OpenALController::recordToStreamBuffer(qint16 *samples, int frame_size,
		int nb_channels) {
	//qDebug() << "Starting capture NOW!";

	Q_UNUSED(nb_channels);
	int samplesCaptured = 0, samplesAvailable = 0;
	qint16 * captureBufPtr;
	captureBufPtr = samples;

	//this->setRecording(true);
	alcCaptureStart(m_captureDev);
	alcGetIntegerv(m_captureDev, ALC_CAPTURE_SAMPLES,
			(ALCsizei) sizeof(qint16), &samplesAvailable);
	int samplesToCopy = frame_size - samplesCaptured;
	while (samplesCaptured < frame_size) {
		if (samplesAvailable > 0 && samplesToCopy > samplesAvailable) {
			samplesToCopy = samplesAvailable;
		}
		alcCaptureSamples(m_captureDev, captureBufPtr, samplesToCopy);
		checkError("alcCaptureSamples");
		samplesCaptured += samplesToCopy;
		///* Advance the buffer (two bytes per sample * number of samples) */
		captureBufPtr += samplesToCopy;// * 2;
		alcGetIntegerv(m_captureDev, ALC_CAPTURE_SAMPLES,
				(ALCsizei) sizeof(ALubyte), &samplesAvailable);
	}
	//qDebug() << "oal:" << frame_size;;
	//qDebug() << "\nDone capturing. samples captured:" << accum;
	/*alcCaptureStop(m_captureDev); */
	//this->setRecording(false);
}
Exemplo n.º 5
0
/**
 * @brief handles recording of audio frames
 */
void OpenAL2::doInput()
{
    ALint curSamples = 0;
    alcGetIntegerv(alInDev, ALC_CAPTURE_SAMPLES, sizeof(curSamples), &curSamples);
    if (curSamples < AUDIO_FRAME_SAMPLE_COUNT) {
        return;
    }

    int16_t buf[AUDIO_FRAME_SAMPLE_COUNT];
    alcCaptureSamples(alInDev, buf, AUDIO_FRAME_SAMPLE_COUNT);

    int retVal = 0;
    if (echoCancelSupported && filterer) {
        retVal = filter_audio(filterer, buf, AUDIO_FRAME_SAMPLE_COUNT);
    }

    // gain amplification with clipping to 16-bit boundaries
    for (quint32 i = 0; i < AUDIO_FRAME_SAMPLE_COUNT; ++i) {
        int ampPCM = qBound<int>(std::numeric_limits<int16_t>::min(),
                                 qRound(buf[i] * OpenAL::inputGainFactor()),
                                 std::numeric_limits<int16_t>::max());

        buf[i] = static_cast<int16_t>(ampPCM);
    }

    emit Audio::frameAvailable(buf, AUDIO_FRAME_SAMPLE_COUNT, 1, AUDIO_SAMPLE_RATE);
}
Exemplo n.º 6
0
	void cAudioCapture::updateCaptureBuffer(bool force)
	{
		cAudioMutexBasicLock lock(Mutex);
		if(Capturing && CaptureDevice && Ready)
		{
			int AvailableSamples = 0;
			alcGetIntegerv(CaptureDevice, ALC_CAPTURE_SAMPLES, 1, &AvailableSamples);
			const unsigned int availbuffersize = AvailableSamples * SampleSize;

			//If the samples in the OpenAL buffer are more than half of its max size, grab them
			if(availbuffersize > InternalBufferSize / 2 || force)
			{
				//Fixes a bug with the capture being forced, but no data being available
				if(availbuffersize > 0)
				{
					const unsigned int oldBufferSize = CaptureBuffer.size();
					CaptureBuffer.resize(oldBufferSize + availbuffersize, 0);
					alcCaptureSamples(CaptureDevice, &CaptureBuffer[oldBufferSize], AvailableSamples);
					checkError();
					getLogger()->logDebug("AudioCapture", "Captured %i bytes of audio data.", availbuffersize);
					signalEvent(ON_UPDATE);
				}
			}
		}
	}
// Executed inside the worker-thread.
// It is not safe to access V8, or V8 data structures
// here, so everything we need for input and output
// should go on `this`.
void ALCaptureWorker::Execute(const ExecutionProgress& progress)
{
	ALCint			samplesIn = 0;

	alcCaptureStart(device);

	while(*this->capturing)
	{
		alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, 1, &samplesIn);

		if (samplesIn > CAPTURE_SIZE) {

			int sampleSize = CAPTURE_SIZE * sizeof(short);

			char* captured = (char*)malloc(sampleSize);

			alcCaptureSamples(device, captured, CAPTURE_SIZE);

			if (*this->capturing)
			{
				progress.Send(captured, sampleSize);
			}

			delete captured;
		}

		sleep_ms(1);
	}
}
Exemplo n.º 8
0
void* recAndSend(void * param){
  ALshort alrecBuffer[SAMPLESIZE];
  ALint alSample;
  ALCdevice* device = alcOpenDevice(NULL);
  ALCcontext* context = alcCreateContext(device,  NULL);
  alcMakeContextCurrent(context);
  ALCdevice* alDevice = alcCaptureOpenDevice(NULL, SRATE, AL_FORMAT_MONO16, SAMPLESIZE);
  alcGetError(alDevice);
  alcCaptureStart(alDevice);
  alcGetError(alDevice);
  while (1){
    alcGetIntegerv(alDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &alSample);
    alcGetError(alDevice);
    if(alSample > SAMPLESIZE/2) {
      alcCaptureSamples(alDevice, (ALCvoid *)alrecBuffer, alSample);
      int n;
      socklen_t addrlen = sizeof(senderinfo);
      int i;
      for(i=0; i<alSample; i++){
        if(abs((int)alrecBuffer[i]) > (0.8*INT16_MAX) ) break;
      }
      if(i==alSample) continue;
      if((n = sendto(sock, alrecBuffer, alSample*2, 0, (struct sockaddr *)&senderinfo, addrlen)) != alSample*2){
        perror("sendto");
        exit(1);
      }
    }
    if(callFlag==OFF) break;
  }
  alcCaptureCloseDevice(alDevice);
  alcCaptureStop(alDevice);
  alcCloseDevice(device);
//  fprintf(stderr, "close recAndSend\n");
}
Exemplo n.º 9
0
void MFSound_UpdateInternal()
{
	const int NumSamples = 4096;
	float buffer[NumSamples];

	size_t numCaptureDevices = MFDevice_GetNumDevices(MFDT_AudioCapture);
	for(size_t i=0; i<numCaptureDevices; ++i)
	{
		MFDevice *pDevice = MFDevice_GetDeviceByIndex(MFDT_AudioCapture, i);
		AudioDevice &device = *(AudioDevice*)pDevice->pInternal;

		if(device.pDevice && device.bActive)
		{
			// get samples, and feed to callback
			ALint numSamples;
			alcGetIntegerv(device.pDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &numSamples);

			MFDebug_Assert(false, "TODO: check if numSamples is in samples or bytes...");

			while(numSamples > 0)
			{
				ALint samples = MFMin(1024, numSamples);
				alcCaptureSamples(device.pDevice, (ALCvoid *)buffer, samples);
				numSamples -= samples;

				// feed samples to the callback
				device.pSampleCallback((float*)buffer, samples, 1, device.pUserData);
			}
		}
	}
}
Exemplo n.º 10
0
void *encode_audio_thread(void *arg)
{
    INFO("Started encode audio thread!");
    av_session_t *_phone = arg;
    _phone->running_encaud = 1;

    int ret = 0;
    int16_t frame[4096];
    int frame_size = AUDIO_FRAME_SIZE;
    ALint sample = 0;
    alcCaptureStart((ALCdevice *)_phone->audio_capture_device);
    while (_phone->running_encaud) {
        
        alcGetIntegerv((ALCdevice *)_phone->audio_capture_device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &sample);
        
        if (sample >= frame_size) {
            alcCaptureSamples((ALCdevice *)_phone->audio_capture_device, frame, frame_size);

            ret = toxav_send_audio(_phone->av, frame, frame_size);

            if (ret < 0) printf("Could not encode or send audio packet\n");

        } else {
            usleep(1000);
        }
    }

    /* clean up codecs *
    pthread_mutex_lock(&cs->ctrl_mutex);* /
    alcCaptureStop((ALCdevice*)_phone->audio_capture_device);
    alcCaptureCloseDevice((ALCdevice*)_phone->audio_capture_device);
    / *pthread_mutex_unlock(&cs->ctrl_mutex);*/
    _phone->running_encaud = -1;
    pthread_exit ( NULL );
}
Exemplo n.º 11
0
/**
 * @brief Called on the captureTimer events to capture audio
 */
void OpenAL::doCapture()
{
    QMutexLocker lock(&audioLock);

    if (!alInDev || !inSubscriptions)
        return;

    ALint curSamples = 0;
    alcGetIntegerv(alInDev, ALC_CAPTURE_SAMPLES, sizeof(curSamples), &curSamples);
    if (curSamples < AUDIO_FRAME_SAMPLE_COUNT)
        return;

    int16_t buf[AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS];
    alcCaptureSamples(alInDev, buf, AUDIO_FRAME_SAMPLE_COUNT);

    for (quint32 i = 0; i < AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS; ++i) {
        // gain amplification with clipping to 16-bit boundaries
        int ampPCM =
            qBound<int>(std::numeric_limits<int16_t>::min(), qRound(buf[i] * inputGainFactor()),
                        std::numeric_limits<int16_t>::max());

        buf[i] = static_cast<int16_t>(ampPCM);
    }

    emit Audio::frameAvailable(buf, AUDIO_FRAME_SAMPLE_COUNT, AUDIO_CHANNELS, AUDIO_SAMPLE_RATE);
}
void OpenALController::record() {
	ALubyte *captureBufPtr;
	qDebug() << "Starting capture NOW!";
	m_samplesCaptured = 0;
	captureBufPtr = m_captureBuffer;

	this->setRecording(true);
	alcCaptureStart(m_captureDev);
	alcGetIntegerv(m_captureDev, ALC_CAPTURE_SAMPLES,
			(ALCsizei) sizeof(ALubyte), &m_samplesAvailable);
	while (m_samplesCaptured < FREQ * 5) {
		if (0 < m_samplesAvailable && m_samplesAvailable <= FREQ) {
			alcCaptureSamples(m_captureDev, captureBufPtr, m_samplesAvailable);
			checkError("alcCaptureSamples");
			m_samplesCaptured += m_samplesAvailable;
			//qDebug()
			//		<<qPrintable(QString("Captured %1 samples (adding %2)\n").arg(m_samplesCaptured).arg(m_samplesAvailable));

			// Advance the buffer (two bytes per sample * number of samples)
			captureBufPtr += m_samplesAvailable * 2;
		} else {
			qDebug() << "No captured samples:" << m_samplesAvailable;
		}
		// Wait for a bit
		//alutSleep(0.02);
		printf(".");
		fflush(stdout);
		alcGetIntegerv(m_captureDev, ALC_CAPTURE_SAMPLES,
				(ALCsizei) sizeof(ALubyte), &m_samplesAvailable);
	}
	qDebug() << "\nDone capturing.\n";
	alcCaptureStop(m_captureDev);
	this->setRecording(false);
}
Exemplo n.º 13
0
int main()
{
    unsigned int sample_rate = 48000;
    unsigned int samples_perframe = sample_rate/50;
    _Bool filter = 1;

    const char *in_device_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);

    const char *temp_d = in_device_list;
    while (*temp_d) {
        printf("%s\n", temp_d);
        temp_d += strlen(temp_d) + 1;
    }

    ALCdevice *device_in = alcCaptureOpenDevice(in_device_list, sample_rate, AL_FORMAT_MONO16, samples_perframe);
    if (!device_in) {
        printf("open in dev failed\n");
        return 0;
    }

    const char *out_device_list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
    ALCdevice *device_out = alcOpenDevice(out_device_list);

    ALCcontext *context = alcCreateContext(device_out, NULL);
    if(!alcMakeContextCurrent(context)) {
        printf("alcMakeContextCurrent() failed\n");
        alcCloseDevice(device_out);
        return 0;
    }

    Filter_Audio *f_a = new_filter_audio(sample_rate);

    ALuint source;
    alGenSources(1, &source);
    alcCaptureStart(device_in);

    printf("Starting\n");

    while (1) {
        ALint samples;
        alcGetIntegerv(device_in, ALC_CAPTURE_SAMPLES, sizeof(samples), &samples);
        //printf("%u\n", samples);
        if(samples >= samples_perframe) {
            int16_t buf[samples_perframe];
            alcCaptureSamples(device_in, buf, samples_perframe);
            if (filter && filter_audio(f_a, buf, samples_perframe) == -1) {
                printf("filter_audio fail\n");
                return 0;
            }

            sourceplaybuffer(source, buf, samples_perframe, 1, sample_rate);
        }

        usleep(1000);
    }

    return 0;
}
Exemplo n.º 14
0
DShort* InternalSoundRecorder::getSamplePointer(DInt numSamples)
{
    DInt samplesAvailable = numSamples;

    // Get the recorded samples
    m_samples.resize(samplesAvailable);
    alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable);

    return &m_samples[0];
}
Exemplo n.º 15
0
void* thread_poll (void* arg) // TODO: maybe use thread for every input source
{
    /*
     * NOTE: We only need to poll input devices for data.
     */
    (void)arg;
    uint32_t i;
    int32_t sample = 0;


    while (true)
    {
        lock;
        if (!thread_running) {
            unlock;
            break;
        }
        unlock;

        if (thread_paused) usleep(10000); /* Wait for unpause. */
        else
        {
            for (i = 0; i < size[input]; ++i)
            {
                lock;
                if (running[input][i] != NULL)
                {
                    alcGetIntegerv(running[input][i]->dhndl, ALC_CAPTURE_SAMPLES, sizeof(int32_t), &sample);

                    int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000);

                    if (sample < f_size) {
                        unlock;
                        continue;
                    }
                    Device* device = running[input][i];

                    int16_t frame[16000];
                    alcCaptureSamples(device->dhndl, frame, f_size);

                    if (device->muted) {
                        unlock;
                        continue;
                    }

                    if ( device->cb ) device->cb(frame, f_size, device->cb_data);
                }
                unlock;
            }
            usleep(5000);
        }
    }

    pthread_exit(NULL);
}
Exemplo n.º 16
0
int CaptureStreamT::Read(unsigned char* Buffer, unsigned int Size)
{
    const unsigned int MAX_WRITE_SAMPLES=Size/BytesPerSample(m_FORMAT);

    // If this is the first read after initialization or a rewind, start capturing now.
    // When capturing has been stopped before and is restarted here, GetNumCaptureSamples() should return 0,
    // just as if it had been started for the first time. See Rewind() for more information.
    if (!m_IsCapturing)
    {
        alcCaptureStart(m_CaptureDevice);
        m_IsCapturing=true;
    }

    // std::cout << "\n" << __FUNCTION__ << "():\n" << "        "; PrintDebug();


    // If there are not enough "live" capture samples available, fill-in zeros until
    // the buffer is half full. This gives the device the chance to capture more data.
    if (GetNumCaptureSamples() < m_MAX_CAPTURE_BUFFER_SAMPLES/8)
    {
        m_ZeroSamples=m_MAX_CAPTURE_BUFFER_SAMPLES/2-GetNumCaptureSamples();

        // std::cout << "  + ... "; PrintDebug();
    }

    // If the capture buffer is too full, we have probably lost data already.
    // In order to prevent this from happening over and over again, reduce it to half its size.
    if (m_ZeroSamples+GetNumCaptureSamples() >= m_MAX_CAPTURE_BUFFER_SAMPLES)
    {
        m_ZeroSamples=0;
        ReduceSamplesTo(m_MAX_CAPTURE_BUFFER_SAMPLES/2 + MAX_WRITE_SAMPLES);

        // std::cout << "  - ... "; PrintDebug();
    }


    // Write the leading zero samples.
    unsigned int SamplesWritten=std::min(m_ZeroSamples, MAX_WRITE_SAMPLES);

    memset(Buffer, 0, SamplesWritten*BytesPerSample(m_FORMAT));
    m_ZeroSamples-=SamplesWritten;

    // Write the samples with real, live, captured data.
    if (GetNumCaptureSamples()>0 && SamplesWritten<MAX_WRITE_SAMPLES)
    {
        const unsigned int NumLive=std::min(GetNumCaptureSamples(), MAX_WRITE_SAMPLES-SamplesWritten);

        alcCaptureSamples(m_CaptureDevice, &Buffer[SamplesWritten*BytesPerSample(m_FORMAT)], NumLive);
        SamplesWritten+=NumLive;
    }

    // std::cout << "        " << SamplesWritten << " samples written,\n" << "     =  "; PrintDebug();

    return SamplesWritten*BytesPerSample(m_FORMAT);
}
Exemplo n.º 17
0
void OpenALCapture::grabSamples()
{
    alcGetIntegerv(this->capDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &numAvailSamples);
    this->error(alcGetError(this->capDevice));
    if (numAvailSamples >= this->BUFFER_SIZE)
    {
        alcCaptureSamples(this->capDevice, &(this->tempBuffer), this->BUFFER_SIZE);
        this->error(alcGetError(this->capDevice));
        this->softWave();
    }
}
Exemplo n.º 18
0
	void CaptureThread::run()
	{
		_captureMutex.lock();
		
		int volume, n; // variables for calculating the mean of the volume
#if defined( __WIN32__ ) || defined( _WIN32 )
		int sampleSize = BUFFERSIZE / _sWaveHeader.wfex.nBlockAlign;
#else
		int sampleSize = BUFFERSIZE / _nBlockAlign;
#endif
		while( _capturing ) 
		{
			// Release some CPU time ...
#if defined( __WIN32__ ) || defined( _WIN32 )
			Sleep( 1 );
#else
			usleep( 10 );
#endif
			// Find out how many samples have been captured
			alcGetIntegerv( _pCaptureDevice, ALC_CAPTURE_SAMPLES, 1, &_iSamplesAvailable );

			// When we have enough data to fill our BUFFERSIZE byte buffer, grab the samples
			if( _iSamplesAvailable > ( sampleSize ) ) 
			{
				//
				// Consume Samples
				//
				alcCaptureSamples( _pCaptureDevice, _buffer, sampleSize );
				//
				// Write the audio data to a file
				//
				writeAudioBufferToFile( BUFFERSIZE );
				//
				// Record total amount of data recorded
				//
				_iDataSize += BUFFERSIZE;
			}

			// Calculates the mean of the volume, from the samples on the buffer
			volume = 0;
			n = ( ( BUFFERSIZE < _iSamplesAvailable ) ? _iSamplesAvailable : BUFFERSIZE );
			if( n > 0 ) 
			{
				for( int i = 0; i < n; i++ ) 
				{
					volume += _buffer[i];
				}
				volume /= n;
			}
				
			emit captureVolume( volume );
		}
		_captureMutex.unlock();
	}
Exemplo n.º 19
0
void CaptureStreamT::ReduceSamplesTo(unsigned int NumLeft)
{
    const unsigned int NumNow=GetNumCaptureSamples();

    if (NumNow>NumLeft)
    {
        ArrayT<unsigned char> Discard;

        Discard.PushBackEmpty((NumNow-NumLeft)*BytesPerSample(m_FORMAT));
        alcCaptureSamples(m_CaptureDevice, &Discard[0], NumNow-NumLeft);
    }
}
Exemplo n.º 20
0
	love::sound::SoundData * Audio::getRecordedData()
	{
		if (!canRecord()) return NULL;
		int samplerate = 8000;
		ALCint samples;
		alcGetIntegerv(capture, ALC_CAPTURE_SAMPLES, 4, &samples);
		void * data = malloc(samples * (2/sizeof(char)));
		alcCaptureSamples(capture, data, samples);
		love::sound::SoundData * sd = new love::sound::SoundData(data, samples, samplerate, 16, 1);
		free(data);
		return sd;
	}
Exemplo n.º 21
0
 int psm_record::record(void* data, size_t bufsize){
     ALint sample;
     if(context_->device){
         alcGetIntegerv(context_->device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &sample);
         if(sample >= bufsize){
             alcCaptureSamples(context_->device, (ALCvoid *)data, bufsize);
             return 0;
         }else{
             return 1; // wait
         }
     }
     return -1; // error
 }
Exemplo n.º 22
0
void AudioRecorder::updateRecord()
{
    ALint samples;
    alcGetIntegerv(m_recordDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &samples);
    alcCaptureSamples(m_recordDevice, (ALCvoid *)m_recordBuffer, samples);

    m_sampleArray.append((char*)&m_recordBuffer[0], samples * 2);

    if (m_sampleArray.size() >= frame_size * 2)
    {
        writeFrame((uint8_t*)m_sampleArray.data(), frame_size * 2);
        m_sampleArray.remove(0, frame_size * 2);
    }
}
Exemplo n.º 23
0
void* thread_poll (void* arg) // TODO: maybe use thread for every input source
{
    /*
     * NOTE: We only need to poll input devices for data.
     */
    (void)arg;
    uint32_t i;
    int32_t sample = 0;
    
    
    while (thread_running)
    {
        if (thread_paused) usleep(10000); /* Wait for unpause. */
        else
        {
            for (i = 0; i < size[input]; i ++) 
            {
                lock;
                if (running[input][i] != NULL) 
                {
                    alcGetIntegerv(running[input][i]->dhndl, ALC_CAPTURE_SAMPLES, sizeof(int32_t), &sample);
                    
                    int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000);
                    
                    if (sample < f_size) { 
                        unlock;
                        continue;
                    }
                    Device* device = running[input][i];
                    
                    int16_t frame[16000];
                    alcCaptureSamples(device->dhndl, frame, f_size);
                    
                    if ( device->muted 
                    #ifdef _AUDIO
                        || (device->enable_VAD && !toxav_has_activity(av, device->call_idx, frame, f_size, device->VAD_treshold))
                    #endif /* _AUDIO */
                        )
                        { unlock; continue; } /* Skip if no voice activity */
                    
                    if ( device->cb ) device->cb(frame, f_size, device->cb_data);
                } 
                unlock;
            }
            usleep(5000);
        }
    }
    
    pthread_exit(NULL);
}
Exemplo n.º 24
0
int color_organ_tick(color_organ_t *c, spectrum_t *s) {
    ALint samples_available;
    do {
        alcGetIntegerv(c->mic, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &samples_available);
    } while (!samples_available);
    
    if (samples_available) {
        alcCaptureSamples(c->mic, (ALCvoid *) c->capture_buf, samples_available);
        
        spectrum_feed(s, samples_available, c->capture_buf);
    }
    
    return samples_available;
}
Exemplo n.º 25
0
void OpenALReader::read(int & length, bool& eos, sample_t* buffer)
{
	int len = getLength();
	length = std::min(length, len);

	if(length > 0)
	{
		alcCaptureSamples(m_device, buffer, length);
		convert_s16_float((data_t*)buffer, (data_t*)buffer, length * m_specs.channels);
	}

	eos = false;

	m_position += length;
}
Exemplo n.º 26
0
love::sound::SoundData *RecordingDevice::getData()
{
	if (!isRecording())
		return nullptr;

	int samples = getSampleCount();
	if (samples == 0)
		return nullptr;

	love::sound::SoundData *soundData = soundInstance()->newSoundData(samples, sampleRate, bitDepth, channels);

	alcCaptureSamples(device, soundData->getData(), samples);

	return soundData;
}
// static
void SdSoundCaptureAL::Update()
{
	ALint iSamplesAvailable;
    
	// Find out how many samples have been captured
	alcGetIntegerv(pCaptureDevice, ALC_CAPTURE_SAMPLES, 1, &iSamplesAvailable);
    
	// When we have enough data to fill our BUFFERSIZE byte buffer, grab the samples
	if (iSamplesAvailable > (FFTBufferSize / sWaveHeader.wfex.nBlockAlign))
	{
		BtU32 numSamples = FFTBufferSize / sWaveHeader.wfex.nBlockAlign;
        
		// Consume Samples
		alcCaptureSamples(pCaptureDevice, inWAV, numSamples );
        
		ALCshort *buffer = (ALCshort*)inWAV;
        
		// Get the average volume
		BtU32 averageVolume = 0;
		for( BtU32 i=0; i<numSamples; i++ )
		{
			BtS32 val = buffer[i];
			averageVolume += MtAbs( val );
		}
		volume = ((BtFloat)averageVolume) / numSamples;
        
		SamplesRead = numSamples;
        
		// Calculate the pitch
		m_pitch = find_pitch( (BtU8*)buffer, MIN_FREQ, MAX_FREQ );
        
		// Write this to a file
		if( audioFile )
		{
			// Write the audio data to a file
			fwrite(inWAV, FFTBufferSize, 1, audioFile );
		}
        
		// Record total amount of data recorded
		iDataSize += FFTBufferSize;
	}
}
Exemplo n.º 28
0
////////////////////////////////////////////////////////////
/// Get available captured samples and process them
////////////////////////////////////////////////////////////
void SoundRecorder::ProcessCapturedSamples()
{
    // Get the number of samples available
    ALCint SamplesAvailable;
    alcGetIntegerv(CaptureDevice, ALC_CAPTURE_SAMPLES, 1, &SamplesAvailable);

    if (SamplesAvailable > 0)
    {
        // Get the recorded samples
        mySamples.resize(SamplesAvailable);
        alcCaptureSamples(CaptureDevice, &mySamples[0], SamplesAvailable);

        // Forward them to the derived class
        if (!ProcessSamples(&mySamples[0], mySamples.size()))
        {
            // The user wants to stop the capture
            myIsCapturing = false;
        }
    }
}
Exemplo n.º 29
0
void SoundRecorder::processCapturedSamples()
{
    // Get the number of samples available
    ALCint samplesAvailable;
    alcGetIntegerv(captureDevice, ALC_CAPTURE_SAMPLES, 1, &samplesAvailable);

    if (samplesAvailable > 0)
    {
        // Get the recorded samples
        m_samples.resize(samplesAvailable * getChannelCount());
        alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable);

        // Forward them to the derived class
        if (!onProcessSamples(&m_samples[0], m_samples.size()))
        {
            // The user wants to stop the capture
            m_isCapturing = false;
        }
    }
}
Exemplo n.º 30
0
static guint
gst_openal_src_read (GstAudioSrc * asrc, gpointer data, guint length)
{
  GstOpenalSrc *osrc = GST_OPENAL_SRC (asrc);
  gint samples;

  alcGetIntegerv (osrc->deviceHandle, ALC_CAPTURE_SAMPLES, sizeof (samples),
      &samples);

  if (samples * osrc->bytes_per_sample > length) {
    samples = length / osrc->bytes_per_sample;
  }

  if (samples) {
    GST_DEBUG_OBJECT (osrc, "Read samples : %d", samples);
    alcCaptureSamples (osrc->deviceHandle, data, samples);
  }

  return samples * osrc->bytes_per_sample;
}