Cpp CHOP example - sample rate understanding

Hello. an example cppCHOP VS solution project is set to be performed 120 times (sampleRate), but after firing TD and setting TrailChop, you can see that it does not work like that, because it is performed twice in one frame and it does not always work well, sometimes it gets dirty with an additional sample unless you set the red button real-time, but then the whole thing slows down to the main TD thread. Also changing timeslice to info->timeslice = false; makes the same results. How do I set up a project to always get 120 or a different sample value correctly in an example like this?
What is the right procedure to work with a faster sample rate than 60, and how to get this data like this sine wave run smoothly?

If you are creating a timeliced CHOP, then you need to fill in X samples every cook, where X is the number of samples that elapsed since the last cook. For example if the file is running at 60FPS, and your CHOP is at 60Hz, but the project drops a frame, you’ll be asked to generate 2 samples.
If the file is running at 60FPS and your CHOP is 120Hz, then by default you’ll be asked to generate 2 samples every cook. If the project drops a frame you need to generate 4 samples, if it drops 2 frames you’ll need to generate 6. This is how you’d get a smooth ramp coming out of the Trail CHOP.

Thank you, Malcolm. So I should do it similar to how audiofileinCHOP works: 44100/FPS per frame? Could you give me some pseudocode example of how this part of the function should looks when I want to run at 120 for example? Just to be clear I get it right.

	for (int i = 0 ; i < output->numChannels; i++)
	{
		for (int j = 0; j < output->numSamples; j++)
		{
			output->channels[i][j] = float(cinput->getChannelData(i)[ind] * scale);
			ind++;

			// Make sure we don't read past the end of the CHOP input
			ind = ind % cinput->numSamples;
		}
	}

So the question with that code is, what sample rate is your input. If it’s 60hz then you’ll get half the number of samples on input as you need for your 120Hz output. That’s what the ind % cinput->numSamples is doing, it’s avoiding reading too many samples.
If your input is a different Hz, then you’ll need to decide what to do about that, such as interpolate between the samples. You may also need to keep track of what your last frame’s newest values where so you know where you are coming from.

I have a EEG device that’s operate in 250Hz. And it has a GetData function which takes a pointer to float buffer of length 17(this can be interpreted as channels). So every second I want to output from chop as fast as it can be all 250 samples from EEG device. so what I was think to do is set the sample rate of chop to 250Hz and execute this function as something like update() and then read from the buffer all 17 channels. while all the logic looks good and I get the data right in channels, but sample rate is corrupted, basically not in time and I get the error from the Unicorn EEG Capi that I overflow the buffer. So what would be the best strategy to get this case right in time to work with data in TD ? I can upload the main file I you would like to look at it.

I’m not sure about the error you are getting from their library. But essentially if you grab X samples from the EEG, but the CHOP isn’t ready for that many samples yet, then you should buffer them in your class, and output those old samples first on the next cook.
Also it’s usually good to have your CHOP hz divisible by your FPS, so likely you’ll want to output at 240Hz, and either just drop samples from the EEG, or if you want, interpolate them down to 240Hz.

Thank you, Malcolm, I will try.