Hello everybody,
i can’t find it, but maybe you can help me:
i’m searching a way to get the current project sr into my opcode.
is there a data member in the OPDS struct or somewhere?
- Philipp
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here
in csoundCore.h:
MYFLT GetLocalSr(OPDS *p)
In order to have one source build for both csound 6 and csound 7 I use the following:
static inline MYFLT _GetLocalSr(CSOUND *csound, OPDS *ctx) {
#if CS_API_VERSION_MAJOR == 7
IGN(csound);
return GetLocalSr(ctx);
#else
IGN(ctx);
return csound->GetSr(csound);
#endif
}
which can be called as MYFLT sr = _GetLocalSr(csound, &(p->h)), where p is the pointer to your opcode’s struct
This depends on CS_API_VERSION_MAJOR being set to the correct value, for example within cmake
Thanks all! This helped a lot!
I’m still working through some examples i try to understand this incrementing mechanism:
inc = (int32)(*cpsp++ * CS_SICVT);
CS_SICVT is leading to a struct where sicvtis commented with ‚local sr‘. is this right?
if so, i don’t understand this incrementing mechanism:
static int32\_t randomh\(CSOUND \*csound, RANDOMH \*p\)
\{
int32 phs = p\->phs, inc;
uint32\_t offset = p\->h\.insdshead\->ksmps\_offset;
uint32\_t early = p\->h\.insdshead\->ksmps\_no\_end;
uint32\_t n, nsmps = CS\_KSMPS;
MYFLT \*ar, \*cpsp;
MYFLT amp, min;
cpsp = p\->xcps;
min = \*p\->min;
amp = \(\*p\->max \- min\);
ar = p\->ar;
inc = \(int32\)\(\*cpsp\+\+ \* CS\_SICVT\);
if \(UNLIKELY\(offset\)\) memset\(ar, '\\0', offset\*sizeof\(MYFLT\)\);
if \(UNLIKELY\(early\)\) \{
nsmps \-= early;
memset\(&ar\[nsmps\], '\\0', early\*sizeof\(MYFLT\)\);
\}
for \(n=offset; n<nsmps; n\+\+\) \{
ar\[n\] = p\->num1 \* amp \+ min;
phs \+= inc;
if \(p\->cpscod\)
inc = \(int32\)\(\*cpsp\+\+ \* CS\_SICVT\);
if \(phs >= MAXLEN\) \{
phs &= PHMASK;
p\->num1 = randGab\(csound\);
\}
\}
p\->phs = phs;
return OK;
\}
\`\`\`
This is used to read function tables using fixed-point phase, converting frequency to a suitable
sampling increment to update the phase. Unless you understand fixed-point maths, best is to
use floating-point phase and ignore this. Also for csound 7, if fixed-point maths is used, an
alternative floating-point version needs to be implemented too, as we have scrapped the
limitation to power-of-two table sizes.
best