Beispiel #1
0
void GenericProcessor::processBlock (AudioSampleBuffer &buffer, MidiBuffer &eventBuffer)
{
	
	int nSamples = getNumSamples(eventBuffer); // removes first value from midimessages

	process(buffer, eventBuffer, nSamples);

	setNumSamples(eventBuffer, nSamples); // adds it back,
										  // even if it's unchanged

}
void FileReader::process (AudioSampleBuffer& buffer, MidiBuffer& events)
{
    setTimestamp (events, timestamp);

    const int samplesNeeded = int (float (buffer.getNumSamples()) * (getDefaultSampleRate() / 44100.0f));
    // FIXME: needs to account for the fact that the ratio might not be an exact
    //        integer value

    int samplesRead = 0;

    while (samplesRead < samplesNeeded)
    {
        int samplesToRead = samplesNeeded - samplesRead;
        if ( (currentSample + samplesToRead) > stopSample)
        {
            samplesToRead = stopSample - currentSample;
            if (samplesToRead > 0)
                input->readData (readBuffer + samplesRead, samplesToRead);

            input->seekTo (startSample);
            currentSample = startSample;
        }
        else
        {
            input->readData (readBuffer + samplesRead, samplesToRead);

            currentSample += samplesToRead;
        }

        samplesRead += samplesToRead;
    }

    for (int i = 0; i < currentNumChannels; ++i)
    {
        input->processChannelData (readBuffer, buffer.getWritePointer (i, 0), i, samplesNeeded);
    }

    timestamp += samplesNeeded;
    setNumSamples (events, samplesNeeded);

    // code for testing events:
    // // ===========================================================================

    // if (counter == 100)
    // {
    //     //std::cout << "Adding on event for node id: " << nodeId << std::endl;
    //     addEvent (events,    // MidiBuffer
    //               TTL,       // eventType
    //               0,         // sampleNum
    //               1,         // eventID
    //               0);        // eventChannel
    //     ++counter;
    // } 
    // else if (counter > 120)
    // {
    //     //std::cout << "Adding off event!" << std::endl;
    //     addEvent (events,    // MidiBuffer
    //               TTL,       // eventType
    //               0,         // sampleNum
    //               0,         // eventID
    //               0);        // eventChannel
    //     counter = 0;
    // }
    // else 
    // {
    //     ++counter;
    // }
    // // ===========================================================================
}
/*!
 * Description: General funtion for menus which set values
 *              (Such as Set Max Range). This calls the
 *              appropriate function, and transmits user messages.
 */
static void setValue(int input)
{
    char string[20] = " set to \0";
    char stringLcd[20] = {0};
    Direction dir;

    // Sends a new line
    sendNewLine(1);

    // Handle inpropper input values
    if (input < m_currentMenu.minVal || input > m_currentMenu.maxVal)
    {
        errOutOfRange(m_currentMenu.minVal, m_currentMenu.maxVal);
        sendNewLine(1);
        return;
    }

    // Handle Different cases
    // @TODO handle current values
    // @TODO Integrate
    switch (m_currentMenu.menuID)
    {
        case AZ_GOTO:
            dir.azimuth = input;
            dir.elevation = getDir().elevation;
            move(dir);
            sendROM(angleStr);
            break;
        case EL_GOTO:
            dir.azimuth = getDir().azimuth;
            dir.elevation = input;
            move(dir);
            sendROM(angleStr);
            break;
        case AZ_MIN:
            setMinAzimuthAngle((char) input);
            AzGoto.minVal = input;
            sendROM(angleStr);
            break;
        case AZ_MAX:
            setMaxAzimuthAngle((char) input);
            AzGoto.maxVal = input;
            sendROM(angleStr);
            break;
        case EL_MIN:
            setMinElevationAngle((char) input);
            ElGoto.minVal = input;
            sendROM(angleStr);
            break;
        case EL_MAX:
            setMaxElevationAngle((char) input);
            ElGoto.maxVal = input;
            sendROM(angleStr);
            break;
        case RANGE_MIN:
            setMinRange(input);
            sendROM(mmStr);
            break;
        case RANGE_MAX:
            setMaxRange(input);
            sendROM(mmStr);
            break;
        case US_SAMPLE_RATE:
            setUsSampleRate(input);
            sendROM(sampleRate);
            break;
        case US_SAMPLE_AVG:
            setNumSamples(input);
            sendROM(numPerSample);
            break;
    }

    // Transmit the final part of the sentence
    transmit(string);
    transmit(intToAscii(input));
    sendNewLine(1);

    //lcdWriteString(strcpypgm2ram(stringLcd, "OK!"), 2);
}
Beispiel #4
0
void MainWindow::on_action_Open_triggered()
{
	QString s;
	QString fileName = QFileDialog::getOpenFileName(this,
		tr("Open sample file"), ".",
		tr("Raw sample files (*.raw *.bin);;"
		   "Gnuplot data files (*.dat);;"
		   "VCD files (*.vcd);;"
		   "All files (*)"));

	if (fileName == NULL)
		return;

	QFile file(fileName);
	file.open(QIODevice::ReadOnly);
	QDataStream in(&file);

	/* TODO: Implement support for loading different input formats. */

	sample_buffer = (uint8_t *)malloc(file.size());
	if (sample_buffer == NULL) {
		/* TODO: Error handling. */
	}

	in.readRawData((char *)sample_buffer, file.size());

	setNumSamples(file.size());
	setNumChannels(8); /* FIXME */

	file.close();

	setupDockWidgets();

	ui->comboBoxLA->clear();
	ui->comboBoxLA->addItem(tr("File"));

	/* FIXME: Store number of channels in the file or allow user config. */
	s.sprintf("%d", getNumChannels());
	s.prepend(tr("Channels: "));
	ui->labelChannels->setText(s);
	ui->labelChannels->setEnabled(false);

	ui->comboBoxSampleRate->clear();
	ui->comboBoxSampleRate->setEnabled(false); /* FIXME */

	ui->comboBoxNumSamples->clear();
	ui->comboBoxNumSamples->addItem(s.sprintf("%llu", getNumSamples()),
					getNumSamples());
	ui->comboBoxNumSamples->setEnabled(true);

	ui->labelSampleStart->setText(tr("Start sample: "));
	ui->labelSampleStart->setEnabled(true);

	ui->labelSampleEnd->setText(tr("End sample: "));
	ui->labelSampleEnd->setEnabled(true);

	ui->labelZoomFactor->setText(tr("Zoom factor: "));
	ui->labelZoomFactor->setEnabled(true);

	ui->action_Save_as->setEnabled(true);
	ui->action_Get_samples->setEnabled(false);

	for (int i = 0; i < getNumChannels(); ++i) {
		channelRenderAreas[i]->setChannelNumber(i);
		channelRenderAreas[i]->setNumSamples(file.size());
		channelRenderAreas[i]->setSampleStart(0);
		channelRenderAreas[i]->setSampleEnd(getNumSamples());
		channelRenderAreas[i]->update();
	}

	/* FIXME */
}
Beispiel #5
0
void MainWindow::on_action_Get_samples_triggered()
{
	uint64_t samplerate;
	QString s;
	GSList *devs = NULL;
	int opt_dev;
	struct sr_dev *dev;
	QComboBox *n = ui->comboBoxNumSamples;

	opt_dev = 0; /* FIXME */

	/*
	 * The number of samples to get is a drop-down list, but you can also
	 * manually enter a value. If the latter, we have to get the value from
	 * the lineEdit object, otherwise via itemData() and the list index.
	 */
	if (n->lineEdit() != NULL) {
		limit_samples = n->lineEdit()->text().toLongLong();
	} else {
		limit_samples = n->itemData(n->currentIndex()).toLongLong();
	}

	samplerate = ui->comboBoxSampleRate->itemData(
		ui->comboBoxSampleRate->currentIndex()).toLongLong();

	/* TODO: Sanity checks. */

	/* TODO: Assumes unitsize == 1. */
	if (!(sample_buffer = (uint8_t *)malloc(limit_samples))) {
		/* TODO: Error handling. */
		return;
	}

	sr_session_new();
	sr_session_datafeed_callback_add(datafeed_in);

	devs = sr_dev_list();

	dev = (struct sr_dev *)g_slist_nth_data(devs, opt_dev);

	/* Set the number of samples we want to get from the device. */
	if (dev->driver->dev_config_set(dev->driver_index,
	    SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) {
		qDebug("Failed to set sample limit.");
		sr_session_destroy();
		return;
	}

	if (sr_session_dev_add(dev) != SR_OK) {
		qDebug("Failed to use device.");
		sr_session_destroy();
		return;
	}

	/* Set the samplerate. */
	if (dev->driver->dev_config_set(dev->driver_index,
	    SR_HWCAP_SAMPLERATE, &samplerate) != SR_OK) {
		qDebug("Failed to set samplerate.");
		sr_session_destroy();
		return;
	};

	if (dev->driver->dev_config_set(dev->driver_index,
	    SR_HWCAP_PROBECONFIG, (char *)dev->probes) != SR_OK) {
		qDebug("Failed to configure probes.");
		sr_session_destroy();
		return;
	}

	if (sr_session_start() != SR_OK) {
		qDebug("Failed to start session.");
		sr_session_destroy();
		return;
	}

	progress = new QProgressDialog("Getting samples from logic analyzer...",
				       "Abort", 0, limit_samples, this);
	progress->setWindowModality(Qt::WindowModal);
	progress->setMinimumDuration(100);

	sr_session_run();

	sr_session_stop();
	sr_session_destroy();

	for (int i = 0; i < getNumChannels(); ++i) {
		channelForms[i]->setNumSamples(limit_samples);
		// channelForms[i]->setSampleStart(0);
		// channelForms[i]->setSampleEnd(limit_samples);

		/* If any of the scale factors change, update all of them.. */
		connect(channelForms[i], SIGNAL(scaleFactorChanged(float)),
		        w, SLOT(updateScaleFactors(float)));

		channelForms[i]->generatePainterPath();
		// channelForms[i]->update();
	}

	setNumSamples(limit_samples);
	
	/* Enable the relevant labels/buttons. */
	ui->labelSampleStart->setEnabled(true);
	ui->labelSampleEnd->setEnabled(true);
	ui->labelScaleFactor->setEnabled(true);
	ui->action_Save_as->setEnabled(true);

	// sr_hw_get_samples_shutdown(&ctx, 1000);
}