[C#] Absolute song position in samples

Post Reply
wde
Posts: 332
Joined: Sun Jan 08, 2012 9:28 am

[C#] Absolute song position in samples

Post 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
User avatar
mantratronic
Posts: 296
Joined: Mon Nov 21, 2011 7:23 pm

Re: [C#] Absolute song position in samples

Post 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);
wde
Posts: 332
Joined: Sun Jan 08, 2012 9:28 am

Re: [C#] Absolute song position in samples

Post 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)
Post Reply