Page 1 of 1

[C#] Absolute song position in samples

Posted: Sat May 12, 2012 9:03 am
by wde
How do I get absolute song position in samples using C# api inside public Sample Work(Sample s) method? Absolute meaning from the beginning of the song.

I tried

Code: Select all

int thePosition = Global.Buzz.Song.PlayPosition * host.MasterInfo.SamplesPerTick + host.MasterInfo.PosInTick;
but it did not work. In C++ this works

Code: Select all

pMasterInfo->SamplesPerTick * pCB->GetSongPosition() + pMasterInfo->PosInTick

Re: [C#] Absolute song position in samples

Posted: Sat May 12, 2012 1:22 pm
by mantratronic
just recording this info from the irc channel for other devs:
[12:56] oskari if you have Engine -> Accurate BPM enabled that calculation is not correct
[12:56] oskari because SamplesPerTicks changes
[12:57] wde ok. is there way to go around this?
[12:59] oskari double avgSamplesPerTick = (60.0 * host.MasterInfo.SamplesPerSec) / (host.MasterInfo.BeatsPerMin * host.MasterInfo.TicksPerBeat);
[12:59] oskari int thePosition = (int)(host.Machine.Graph.Buzz.Song.PlayPosition * avgSamplesPerTick + host.MasterInfo.PosInTick);

Re: [C#] Absolute song position in samples

Posted: Sun May 13, 2012 7:00 am
by wde
The solution was to use "block" version of Work method:

Code: Select all

public bool Work(Sample[] output, Sample[] input, int numsamples, WorkModes mode)