Csound Csound-dev Csound-tekno Search About

[Csnd] Quantisation issues

Date2024-01-14 16:22
From"Jeanette C."
Subject[Csnd] Quantisation issues
Hey hey,
I have written a UDO to quantise incoming frequencies to predefined 12-tone 
equal temperament scales (like the church modes, pentatonics, ...).

The UDO works, in that it can quantise frequencies into scales. BUT in scales 
with more than a whole tone gap, it creates a trill. I can't work it out. 
Following the code and a short explanation:
https://www.dropbox.com/scl/fi/edaiqrdgn5cwvm8pxz88p/scale_quant.zip?rlkey=cwq0ssq2vexn9aj3ue60rgcxd
The scales table contains twelve entries per scale. Namely what to do with 
each degree/note/step of the octave. For example the Ionian/major scale:
0 = 0 (the tonic is the tonic, no shift)
1 = 1 (the minor second does not exist, shift up one to the major second)
2 = 0 (the major second doesn't need to be shifted)
...
In the code I marked the beginning of that whole block and the extra logic 
with a comment including JBS (all capital letters).

The extra logic:  in the major scale, assume we have a frequency 0.7 times the 
tonic. It will be rounded to 1, the first degree, which should be shifted to 
2, the major second. But if the scale table contains a shift != 0, the extra 
logic checks if the original value is on the opposite side of the rounded 
tone. In our example: 0.7 is less than 1, thus 0.7 is in effect closer to 0, 
so the "quantised" value will be rounded decreased by one to 0. If the 
suggested shift in the scale table goes down, the logic check if the received 
degree/semitone is above the rounded value. If so, the "rounded value" will be 
increased by one.

I have a feeling that something in this logic causes the trills in gaps of 
more than two semitones. The supplied .csd shows this with a pentatonic scale.

Does anyone have an idea? I'm sorry, I think I can't condense the logic by 
much and still provide it in a meaningful way. I hope the code markers help.

Best wishes and thanks for any hints,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-01-15 08:18
Fromjoachim heintz
SubjectRe: [Csnd] Quantisation issues
hi jeanette -
just want to mention that i had a look yesterday but found it too 
complicated to dig into it.  i guess you are right that it is about the 
way you do the quantization.  perhaps you can simplify it, or split it 
into several modules / functions?
best -
	joachim


On 14/01/2024 17:22, Jeanette C. wrote:
> Hey hey,
> I have written a UDO to quantise incoming frequencies to predefined 
> 12-tone equal temperament scales (like the church modes, pentatonics, ...).
> 
> The UDO works, in that it can quantise frequencies into scales. BUT in 
> scales with more than a whole tone gap, it creates a trill. I can't work 
> it out. Following the code and a short explanation:
> https://www.dropbox.com/scl/fi/edaiqrdgn5cwvm8pxz88p/scale_quant.zip?rlkey=cwq0ssq2vexn9aj3ue60rgcxd
> The scales table contains twelve entries per scale. Namely what to do 
> with each degree/note/step of the octave. For example the Ionian/major 
> scale:
> 0 = 0 (the tonic is the tonic, no shift)
> 1 = 1 (the minor second does not exist, shift up one to the major second)
> 2 = 0 (the major second doesn't need to be shifted)
> ...
> In the code I marked the beginning of that whole block and the extra 
> logic with a comment including JBS (all capital letters).
> 
> The extra logic:  in the major scale, assume we have a frequency 0.7 
> times the tonic. It will be rounded to 1, the first degree, which should 
> be shifted to 2, the major second. But if the scale table contains a 
> shift != 0, the extra logic checks if the original value is on the 
> opposite side of the rounded tone. In our example: 0.7 is less than 1, 
> thus 0.7 is in effect closer to 0, so the "quantised" value will be 
> rounded decreased by one to 0. If the suggested shift in the scale table 
> goes down, the logic check if the received degree/semitone is above the 
> rounded value. If so, the "rounded value" will be increased by one.
> 
> I have a feeling that something in this logic causes the trills in gaps 
> of more than two semitones. The supplied .csd shows this with a 
> pentatonic scale.
> 
> Does anyone have an idea? I'm sorry, I think I can't condense the logic 
> by much and still provide it in a meaningful way. I hope the code 
> markers help.
> 
> Best wishes and thanks for any hints,
> 
> Jeanette
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-01-15 09:47
From"Jeanette C."
SubjectRe: [Csnd] Quantisation issues
Hi Joachim,
hm, I might try to break the code down into several UDOs. I know that this 
relevant part alone consists of two nested if-statements with a bit of prior 
initialisation. Perhaps also checking my variable names once again to find 
even more meaningful ones. Perhaps I can put in some work later tonight.

Thanks for looking and getting back to me!

Best wishes,

Jeanette

Jan 15 2024, joachim heintz has written:

> hi jeanette -
> just want to mention that i had a look yesterday but found it too complicated 
> to dig into it.  i guess you are right that it is about the way you do the 
> quantization.  perhaps you can simplify it, or split it into several modules 
> / functions?
> best -
> 	 joachim
>
>
> On 14/01/2024 17:22, Jeanette C. wrote:
>>  Hey hey,
>>  I have written a UDO to quantise incoming frequencies to predefined
>>  12-tone equal temperament scales (like the church modes, pentatonics,
>>  ...).
>>
>>  The UDO works, in that it can quantise frequencies into scales. BUT in
>>  scales with more than a whole tone gap, it creates a trill. I can't work
>>  it out. Following the code and a short explanation:
>>  https://www.dropbox.com/scl/fi/edaiqrdgn5cwvm8pxz88p/scale_quant.zip?rlkey=cwq0ssq2vexn9aj3ue60rgcxd
>>  The scales table contains twelve entries per scale. Namely what to do with
>>  each degree/note/step of the octave. For example the Ionian/major scale:
>>  0 = 0 (the tonic is the tonic, no shift)
>>  1 = 1 (the minor second does not exist, shift up one to the major second)
>>  2 = 0 (the major second doesn't need to be shifted)
>>  ...
>>  In the code I marked the beginning of that whole block and the extra logic
>>  with a comment including JBS (all capital letters).
>>
>>  The extra logic:  in the major scale, assume we have a frequency 0.7 times
>>  the tonic. It will be rounded to 1, the first degree, which should be
>>  shifted to 2, the major second. But if the scale table contains a shift !=
>>  0, the extra logic checks if the original value is on the opposite side of
>>  the rounded tone. In our example: 0.7 is less than 1, thus 0.7 is in
>>  effect closer to 0, so the "quantised" value will be rounded decreased by
>>  one to 0. If the suggested shift in the scale table goes down, the logic
>>  check if the received degree/semitone is above the rounded value. If so,
>>  the "rounded value" will be increased by one.
>>
>>  I have a feeling that something in this logic causes the trills in gaps of
>>  more than two semitones. The supplied .csd shows this with a pentatonic
>>  scale.
>>
>>  Does anyone have an idea? I'm sorry, I think I can't condense the logic by
>>  much and still provide it in a meaningful way. I hope the code markers
>>  help.
>>
>>  Best wishes and thanks for any hints,
>>
>>  Jeanette
>> 
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>       https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

You know I'm one of a kind,
There'll never be another me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-01-15 09:49
FromST Music
SubjectRe: [Csnd] Quantisation issues
Hi Jeanette :)


I also took a quick peek.

I could be off base as, per usual, it takes time for me to wrap my head around your codes. So just a few quick observations that might point you in the right direction.

The issue seems to be with the if statement following elseif (if it's commented out there is no trill).

If:
  if (kInputTone > kSuggestedIndex)

is changed to:

  if (kInputTone > kSuggestedIndex + 0.1) 
then the trill becomes quicker. If 0.4 is added, the trill is even quicker. At a value >= .5 the trill does not happen. But, then the values are not tested.

If instead the elseif line is commented out, everytime a note is shifted 3 semi-tones the values are tested (the final if statement takes place) and no slur occurs.

This may have to do with having earlier using the round opcode (?).

I only tested the pent & harmonic minor scales.

I haven't had time to sort thru the whole logic so take this with a grain of salt.

Best as always,
Scott



On Sun, Jan 14, 2024, 11:22 a.m. Jeanette C. <julien@mail.upb.de> wrote:
Hey hey,
I have written a UDO to quantise incoming frequencies to predefined 12-tone
equal temperament scales (like the church modes, pentatonics, ...).

The UDO works, in that it can quantise frequencies into scales. BUT in scales
with more than a whole tone gap, it creates a trill. I can't work it out.
Following the code and a short explanation:
https://www.dropbox.com/scl/fi/edaiqrdgn5cwvm8pxz88p/scale_quant.zip?rlkey=cwq0ssq2vexn9aj3ue60rgcxd
The scales table contains twelve entries per scale. Namely what to do with
each degree/note/step of the octave. For example the Ionian/major scale:
0 = 0 (the tonic is the tonic, no shift)
1 = 1 (the minor second does not exist, shift up one to the major second)
2 = 0 (the major second doesn't need to be shifted)
...
In the code I marked the beginning of that whole block and the extra logic
with a comment including JBS (all capital letters).

The extra logic:  in the major scale, assume we have a frequency 0.7 times the
tonic. It will be rounded to 1, the first degree, which should be shifted to
2, the major second. But if the scale table contains a shift != 0, the extra
logic checks if the original value is on the opposite side of the rounded
tone. In our example: 0.7 is less than 1, thus 0.7 is in effect closer to 0,
so the "quantised" value will be rounded decreased by one to 0. If the
suggested shift in the scale table goes down, the logic check if the received
degree/semitone is above the rounded value. If so, the "rounded value" will be
increased by one.

I have a feeling that something in this logic causes the trills in gaps of
more than two semitones. The supplied .csd shows this with a pentatonic scale.

Does anyone have an idea? I'm sorry, I think I can't condense the logic by
much and still provide it in a meaningful way. I hope the code markers help.

Best wishes and thanks for any hints,

Jeanette

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2024-01-15 09:54
FromST Music
SubjectRe: [Csnd] Quantisation issues
Meant to write: 
This may have to do with having earlier used the round opcode and then adding the frac (?).

On Mon, Jan 15, 2024, 4:49 a.m. ST Music <stunes6556@gmail.com> wrote:
Hi Jeanette :)


I also took a quick peek.

I could be off base as, per usual, it takes time for me to wrap my head around your codes. So just a few quick observations that might point you in the right direction.

The issue seems to be with the if statement following elseif (if it's commented out there is no trill).

If:
  if (kInputTone > kSuggestedIndex)

is changed to:

  if (kInputTone > kSuggestedIndex + 0.1) 
then the trill becomes quicker. If 0.4 is added, the trill is even quicker. At a value >= .5 the trill does not happen. But, then the values are not tested.

If instead the elseif line is commented out, everytime a note is shifted 3 semi-tones the values are tested (the final if statement takes place) and no slur occurs.

This may have to do with having earlier using the round opcode (?).

I only tested the pent & harmonic minor scales.

I haven't had time to sort thru the whole logic so take this with a grain of salt.

Best as always,
Scott



On Sun, Jan 14, 2024, 11:22 a.m. Jeanette C. <julien@mail.upb.de> wrote:
Hey hey,
I have written a UDO to quantise incoming frequencies to predefined 12-tone
equal temperament scales (like the church modes, pentatonics, ...).

The UDO works, in that it can quantise frequencies into scales. BUT in scales
with more than a whole tone gap, it creates a trill. I can't work it out.
Following the code and a short explanation:
https://www.dropbox.com/scl/fi/edaiqrdgn5cwvm8pxz88p/scale_quant.zip?rlkey=cwq0ssq2vexn9aj3ue60rgcxd
The scales table contains twelve entries per scale. Namely what to do with
each degree/note/step of the octave. For example the Ionian/major scale:
0 = 0 (the tonic is the tonic, no shift)
1 = 1 (the minor second does not exist, shift up one to the major second)
2 = 0 (the major second doesn't need to be shifted)
...
In the code I marked the beginning of that whole block and the extra logic
with a comment including JBS (all capital letters).

The extra logic:  in the major scale, assume we have a frequency 0.7 times the
tonic. It will be rounded to 1, the first degree, which should be shifted to
2, the major second. But if the scale table contains a shift != 0, the extra
logic checks if the original value is on the opposite side of the rounded
tone. In our example: 0.7 is less than 1, thus 0.7 is in effect closer to 0,
so the "quantised" value will be rounded decreased by one to 0. If the
suggested shift in the scale table goes down, the logic check if the received
degree/semitone is above the rounded value. If so, the "rounded value" will be
increased by one.

I have a feeling that something in this logic causes the trills in gaps of
more than two semitones. The supplied .csd shows this with a pentatonic scale.

Does anyone have an idea? I'm sorry, I think I can't condense the logic by
much and still provide it in a meaningful way. I hope the code markers help.

Best wishes and thanks for any hints,

Jeanette

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here