Csound Csound-dev Csound-tekno Search About

[Csnd] downsampling a pulse

Date2012-10-25 13:06
FromOeyvind Brandtsegg
Subject[Csnd] downsampling a pulse
Hi,

I'm trying to do some conditionals depending on an a-rate pulse signal
(like counting the number of pulses within a given period and
similar).
In this context I want to downsample an a-rate pulse,
so that where I have a single sample with the value 1 followed by
zeroes (a rate pulse),
I want to have ksmps number of samples with the value 1 followed by
zeroes (k rate pulse).

When ksmps > 1 some of the a-rate pulses are lost in the downsampling,
while some of them come through fine.
I suspect that if the first sample of an a-rate vector is 1, then the
pulse is converted to k-rate,
but if it happens at any other time during the vector, it is lost.

I know I could write an UDO with ksmps=1, but I'm trying to solve it
without relying on sr=kr,
also because I would like to learn more about what happens when
converting between the different rates in Csound.

Here's a test csd where I generate a pulse, downsample it, then
upsample it again and output both the original pulse and the resampled
one (one to the left, the other to the right).



-otest.wav


	sr = 44100
	ksmps = 2
	nchnls = 2
	0dbfs = 1

	instr	1
apulse	mpulse	1, 0.25
kpulse	downsamp apulse
apulse2	upsamp kpulse
	outs	apulse, apulse2
	endin



i1 	0 	2
e





-- 

Oeyvind Brandtsegg
Professor of Music Technology
NTNU
7491 Trondheim
Norway
Cell: +47 92 203 205

http://flyndresang.no/
http://www.partikkelaudio.com/
http://soundcloud.com/brandtsegg
http://soundcloud.com/t-emp

Date2012-10-25 13:54
FromJustin Smith
SubjectRe: [Csnd] downsampling a pulse
Provide the optional iwlen argument to downsamp, and make it = ksmps I
think. Unless the averaging crosses over k cycle boundaries? Then
instead of testing for 1 you would test for 1/ksmps.

Otherwise you could write the asig to a table at least ksmps in size
using tablew with a(0) or [andx line 0 p3 0] as andx, and loop through
the table using loop_lt investigating up to ksmps indexes with tab
until you find a value of 1, then output all 1s if any of the values
were 1, and all 0 if none of them were.

On Thu, Oct 25, 2012 at 5:06 AM, Oeyvind Brandtsegg
 wrote:
> Hi,
>
> I'm trying to do some conditionals depending on an a-rate pulse signal
> (like counting the number of pulses within a given period and
> similar).
> In this context I want to downsample an a-rate pulse,
> so that where I have a single sample with the value 1 followed by
> zeroes (a rate pulse),
> I want to have ksmps number of samples with the value 1 followed by
> zeroes (k rate pulse).
>
> When ksmps > 1 some of the a-rate pulses are lost in the downsampling,
> while some of them come through fine.
> I suspect that if the first sample of an a-rate vector is 1, then the
> pulse is converted to k-rate,
> but if it happens at any other time during the vector, it is lost.
>
> I know I could write an UDO with ksmps=1, but I'm trying to solve it
> without relying on sr=kr,
> also because I would like to learn more about what happens when
> converting between the different rates in Csound.
>
> Here's a test csd where I generate a pulse, downsample it, then
> upsample it again and output both the original pulse and the resampled
> one (one to the left, the other to the right).
>
> 
> 
> -otest.wav
> 
> 
>         sr = 44100
>         ksmps = 2
>         nchnls = 2
>         0dbfs = 1
>
>         instr   1
> apulse  mpulse  1, 0.25
> kpulse  downsamp apulse
> apulse2 upsamp kpulse
>         outs    apulse, apulse2
>         endin
>
> 
> 
> i1      0       2
> e
> 
> 
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://flyndresang.no/
> http://www.partikkelaudio.com/
> http://soundcloud.com/brandtsegg
> http://soundcloud.com/t-emp
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-10-25 14:03
FromOeyvind Brandtsegg
SubjectRe: [Csnd] downsampling a pulse
Ah, perfect.
The iwlen argument makes it work.
Guess it's a case of RTFM for me, ...didn't cross my mind to actually
check the manual for downsamp :-)
thanks
Oeyvind

2012/10/25 Justin Smith :
> Provide the optional iwlen argument to downsamp, and make it = ksmps I
> think. Unless the averaging crosses over k cycle boundaries? Then
> instead of testing for 1 you would test for 1/ksmps.
>
> Otherwise you could write the asig to a table at least ksmps in size
> using tablew with a(0) or [andx line 0 p3 0] as andx, and loop through
> the table using loop_lt investigating up to ksmps indexes with tab
> until you find a value of 1, then output all 1s if any of the values
> were 1, and all 0 if none of them were.
>
> On Thu, Oct 25, 2012 at 5:06 AM, Oeyvind Brandtsegg
>  wrote:
>> Hi,
>>
>> I'm trying to do some conditionals depending on an a-rate pulse signal
>> (like counting the number of pulses within a given period and
>> similar).
>> In this context I want to downsample an a-rate pulse,
>> so that where I have a single sample with the value 1 followed by
>> zeroes (a rate pulse),
>> I want to have ksmps number of samples with the value 1 followed by
>> zeroes (k rate pulse).
>>
>> When ksmps > 1 some of the a-rate pulses are lost in the downsampling,
>> while some of them come through fine.
>> I suspect that if the first sample of an a-rate vector is 1, then the
>> pulse is converted to k-rate,
>> but if it happens at any other time during the vector, it is lost.
>>
>> I know I could write an UDO with ksmps=1, but I'm trying to solve it
>> without relying on sr=kr,
>> also because I would like to learn more about what happens when
>> converting between the different rates in Csound.
>>
>> Here's a test csd where I generate a pulse, downsample it, then
>> upsample it again and output both the original pulse and the resampled
>> one (one to the left, the other to the right).
>>
>> 
>> 
>> -otest.wav
>> 
>> 
>>         sr = 44100
>>         ksmps = 2
>>         nchnls = 2
>>         0dbfs = 1
>>
>>         instr   1
>> apulse  mpulse  1, 0.25
>> kpulse  downsamp apulse
>> apulse2 upsamp kpulse
>>         outs    apulse, apulse2
>>         endin
>>
>> 
>> 
>> i1      0       2
>> e
>> 
>> 
>>
>>
>>
>> --
>>
>> Oeyvind Brandtsegg
>> Professor of Music Technology
>> NTNU
>> 7491 Trondheim
>> Norway
>> Cell: +47 92 203 205
>>
>> http://flyndresang.no/
>> http://www.partikkelaudio.com/
>> http://soundcloud.com/brandtsegg
>> http://soundcloud.com/t-emp
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



-- 

Oeyvind Brandtsegg
Professor of Music Technology
NTNU
7491 Trondheim
Norway
Cell: +47 92 203 205

http://flyndresang.no/
http://www.partikkelaudio.com/
http://soundcloud.com/brandtsegg
http://soundcloud.com/t-emp

Date2012-10-25 14:08
FromJustin Smith
SubjectRe: [Csnd] downsampling a pulse
I am wondering, would a iwlen of ksmps cause two positives if the
pulse was right at the beginning or end of a k cycle? what about if
iwlen was ksmps/2+1 - would this always catch a pulse, and would it
prevent false positives?

On Thu, Oct 25, 2012 at 6:03 AM, Oeyvind Brandtsegg
 wrote:
> Ah, perfect.
> The iwlen argument makes it work.
> Guess it's a case of RTFM for me, ...didn't cross my mind to actually
> check the manual for downsamp :-)
> thanks
> Oeyvind
>
> 2012/10/25 Justin Smith :
>> Provide the optional iwlen argument to downsamp, and make it = ksmps I
>> think. Unless the averaging crosses over k cycle boundaries? Then
>> instead of testing for 1 you would test for 1/ksmps.
>>
>> Otherwise you could write the asig to a table at least ksmps in size
>> using tablew with a(0) or [andx line 0 p3 0] as andx, and loop through
>> the table using loop_lt investigating up to ksmps indexes with tab
>> until you find a value of 1, then output all 1s if any of the values
>> were 1, and all 0 if none of them were.
>>
>> On Thu, Oct 25, 2012 at 5:06 AM, Oeyvind Brandtsegg
>>  wrote:
>>> Hi,
>>>
>>> I'm trying to do some conditionals depending on an a-rate pulse signal
>>> (like counting the number of pulses within a given period and
>>> similar).
>>> In this context I want to downsample an a-rate pulse,
>>> so that where I have a single sample with the value 1 followed by
>>> zeroes (a rate pulse),
>>> I want to have ksmps number of samples with the value 1 followed by
>>> zeroes (k rate pulse).
>>>
>>> When ksmps > 1 some of the a-rate pulses are lost in the downsampling,
>>> while some of them come through fine.
>>> I suspect that if the first sample of an a-rate vector is 1, then the
>>> pulse is converted to k-rate,
>>> but if it happens at any other time during the vector, it is lost.
>>>
>>> I know I could write an UDO with ksmps=1, but I'm trying to solve it
>>> without relying on sr=kr,
>>> also because I would like to learn more about what happens when
>>> converting between the different rates in Csound.
>>>
>>> Here's a test csd where I generate a pulse, downsample it, then
>>> upsample it again and output both the original pulse and the resampled
>>> one (one to the left, the other to the right).
>>>
>>> 
>>> 
>>> -otest.wav
>>> 
>>> 
>>>         sr = 44100
>>>         ksmps = 2
>>>         nchnls = 2
>>>         0dbfs = 1
>>>
>>>         instr   1
>>> apulse  mpulse  1, 0.25
>>> kpulse  downsamp apulse
>>> apulse2 upsamp kpulse
>>>         outs    apulse, apulse2
>>>         endin
>>>
>>> 
>>> 
>>> i1      0       2
>>> e
>>> 
>>> 
>>>
>>>
>>>
>>> --
>>>
>>> Oeyvind Brandtsegg
>>> Professor of Music Technology
>>> NTNU
>>> 7491 Trondheim
>>> Norway
>>> Cell: +47 92 203 205
>>>
>>> http://flyndresang.no/
>>> http://www.partikkelaudio.com/
>>> http://soundcloud.com/brandtsegg
>>> http://soundcloud.com/t-emp
>>>
>>>
>>> Send bugs reports to the Sourceforge bug tracker
>>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>>> Discussions of bugs and features can be posted here
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>>
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://flyndresang.no/
> http://www.partikkelaudio.com/
> http://soundcloud.com/brandtsegg
> http://soundcloud.com/t-emp
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-10-25 14:40
FromOeyvind Brandtsegg
SubjectRe: [Csnd] downsampling a pulse
No, it seems there seems to be no overlap between vectors, if that is
why you think it might give false positives(?).
iwlen=ksmps catches all pulses and not false triggering as far as I
cen see. I did test a variety of different pulse rates, and it only
breaks down when the pulse rate is higher than kr/2, as you would
expect.
best
Oeyvind

2012/10/25 Justin Smith :
> I am wondering, would a iwlen of ksmps cause two positives if the
> pulse was right at the beginning or end of a k cycle? what about if
> iwlen was ksmps/2+1 - would this always catch a pulse, and would it
> prevent false positives?
>
> On Thu, Oct 25, 2012 at 6:03 AM, Oeyvind Brandtsegg
>  wrote:
>> Ah, perfect.
>> The iwlen argument makes it work.
>> Guess it's a case of RTFM for me, ...didn't cross my mind to actually
>> check the manual for downsamp :-)
>> thanks
>> Oeyvind
>>
>> 2012/10/25 Justin Smith :
>>> Provide the optional iwlen argument to downsamp, and make it = ksmps I
>>> think. Unless the averaging crosses over k cycle boundaries? Then
>>> instead of testing for 1 you would test for 1/ksmps.
>>>
>>> Otherwise you could write the asig to a table at least ksmps in size
>>> using tablew with a(0) or [andx line 0 p3 0] as andx, and loop through
>>> the table using loop_lt investigating up to ksmps indexes with tab
>>> until you find a value of 1, then output all 1s if any of the values
>>> were 1, and all 0 if none of them were.
>>>
>>> On Thu, Oct 25, 2012 at 5:06 AM, Oeyvind Brandtsegg
>>>  wrote:
>>>> Hi,
>>>>
>>>> I'm trying to do some conditionals depending on an a-rate pulse signal
>>>> (like counting the number of pulses within a given period and
>>>> similar).
>>>> In this context I want to downsample an a-rate pulse,
>>>> so that where I have a single sample with the value 1 followed by
>>>> zeroes (a rate pulse),
>>>> I want to have ksmps number of samples with the value 1 followed by
>>>> zeroes (k rate pulse).
>>>>
>>>> When ksmps > 1 some of the a-rate pulses are lost in the downsampling,
>>>> while some of them come through fine.
>>>> I suspect that if the first sample of an a-rate vector is 1, then the
>>>> pulse is converted to k-rate,
>>>> but if it happens at any other time during the vector, it is lost.
>>>>
>>>> I know I could write an UDO with ksmps=1, but I'm trying to solve it
>>>> without relying on sr=kr,
>>>> also because I would like to learn more about what happens when
>>>> converting between the different rates in Csound.
>>>>
>>>> Here's a test csd where I generate a pulse, downsample it, then
>>>> upsample it again and output both the original pulse and the resampled
>>>> one (one to the left, the other to the right).
>>>>
>>>> 
>>>> 
>>>> -otest.wav
>>>> 
>>>> 
>>>>         sr = 44100
>>>>         ksmps = 2
>>>>         nchnls = 2
>>>>         0dbfs = 1
>>>>
>>>>         instr   1
>>>> apulse  mpulse  1, 0.25
>>>> kpulse  downsamp apulse
>>>> apulse2 upsamp kpulse
>>>>         outs    apulse, apulse2
>>>>         endin
>>>>
>>>> 
>>>> 
>>>> i1      0       2
>>>> e
>>>> 
>>>> 
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Oeyvind Brandtsegg
>>>> Professor of Music Technology
>>>> NTNU
>>>> 7491 Trondheim
>>>> Norway
>>>> Cell: +47 92 203 205
>>>>
>>>> http://flyndresang.no/
>>>> http://www.partikkelaudio.com/
>>>> http://soundcloud.com/brandtsegg
>>>> http://soundcloud.com/t-emp
>>>>
>>>>
>>>> Send bugs reports to the Sourceforge bug tracker
>>>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>>>> Discussions of bugs and features can be posted here
>>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>>>
>>>
>>>
>>> Send bugs reports to the Sourceforge bug tracker
>>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>>> Discussions of bugs and features can be posted here
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>>
>>
>>
>>
>> --
>>
>> Oeyvind Brandtsegg
>> Professor of Music Technology
>> NTNU
>> 7491 Trondheim
>> Norway
>> Cell: +47 92 203 205
>>
>> http://flyndresang.no/
>> http://www.partikkelaudio.com/
>> http://soundcloud.com/brandtsegg
>> http://soundcloud.com/t-emp
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



-- 

Oeyvind Brandtsegg
Professor of Music Technology
NTNU
7491 Trondheim
Norway
Cell: +47 92 203 205

http://flyndresang.no/
http://www.partikkelaudio.com/
http://soundcloud.com/brandtsegg
http://soundcloud.com/t-emp

Date2012-10-25 14:46
FromJustin Smith
SubjectRe: [Csnd] downsampling a pulse
cool, good to know

On Thu, Oct 25, 2012 at 6:40 AM, Oeyvind Brandtsegg
 wrote:
> No, it seems there seems to be no overlap between vectors, if that is
> why you think it might give false positives(?).
> iwlen=ksmps catches all pulses and not false triggering as far as I
> cen see. I did test a variety of different pulse rates, and it only
> breaks down when the pulse rate is higher than kr/2, as you would
> expect.
> best
> Oeyvind
>
> 2012/10/25 Justin Smith :
>> I am wondering, would a iwlen of ksmps cause two positives if the
>> pulse was right at the beginning or end of a k cycle? what about if
>> iwlen was ksmps/2+1 - would this always catch a pulse, and would it
>> prevent false positives?
>>
>> On Thu, Oct 25, 2012 at 6:03 AM, Oeyvind Brandtsegg
>>  wrote:
>>> Ah, perfect.
>>> The iwlen argument makes it work.
>>> Guess it's a case of RTFM for me, ...didn't cross my mind to actually
>>> check the manual for downsamp :-)
>>> thanks
>>> Oeyvind
>>>
>>> 2012/10/25 Justin Smith :
>>>> Provide the optional iwlen argument to downsamp, and make it = ksmps I
>>>> think. Unless the averaging crosses over k cycle boundaries? Then
>>>> instead of testing for 1 you would test for 1/ksmps.
>>>>
>>>> Otherwise you could write the asig to a table at least ksmps in size
>>>> using tablew with a(0) or [andx line 0 p3 0] as andx, and loop through
>>>> the table using loop_lt investigating up to ksmps indexes with tab
>>>> until you find a value of 1, then output all 1s if any of the values
>>>> were 1, and all 0 if none of them were.
>>>>
>>>> On Thu, Oct 25, 2012 at 5:06 AM, Oeyvind Brandtsegg
>>>>  wrote:
>>>>> Hi,
>>>>>
>>>>> I'm trying to do some conditionals depending on an a-rate pulse signal
>>>>> (like counting the number of pulses within a given period and
>>>>> similar).
>>>>> In this context I want to downsample an a-rate pulse,
>>>>> so that where I have a single sample with the value 1 followed by
>>>>> zeroes (a rate pulse),
>>>>> I want to have ksmps number of samples with the value 1 followed by
>>>>> zeroes (k rate pulse).
>>>>>
>>>>> When ksmps > 1 some of the a-rate pulses are lost in the downsampling,
>>>>> while some of them come through fine.
>>>>> I suspect that if the first sample of an a-rate vector is 1, then the
>>>>> pulse is converted to k-rate,
>>>>> but if it happens at any other time during the vector, it is lost.
>>>>>
>>>>> I know I could write an UDO with ksmps=1, but I'm trying to solve it
>>>>> without relying on sr=kr,
>>>>> also because I would like to learn more about what happens when
>>>>> converting between the different rates in Csound.
>>>>>
>>>>> Here's a test csd where I generate a pulse, downsample it, then
>>>>> upsample it again and output both the original pulse and the resampled
>>>>> one (one to the left, the other to the right).
>>>>>
>>>>> 
>>>>> 
>>>>> -otest.wav
>>>>> 
>>>>> 
>>>>>         sr = 44100
>>>>>         ksmps = 2
>>>>>         nchnls = 2
>>>>>         0dbfs = 1
>>>>>
>>>>>         instr   1
>>>>> apulse  mpulse  1, 0.25
>>>>> kpulse  downsamp apulse
>>>>> apulse2 upsamp kpulse
>>>>>         outs    apulse, apulse2
>>>>>         endin
>>>>>
>>>>> 
>>>>> 
>>>>> i1      0       2
>>>>> e
>>>>> 
>>>>> 
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Oeyvind Brandtsegg
>>>>> Professor of Music Technology
>>>>> NTNU
>>>>> 7491 Trondheim
>>>>> Norway
>>>>> Cell: +47 92 203 205
>>>>>
>>>>> http://flyndresang.no/
>>>>> http://www.partikkelaudio.com/
>>>>> http://soundcloud.com/brandtsegg
>>>>> http://soundcloud.com/t-emp
>>>>>
>>>>>
>>>>> Send bugs reports to the Sourceforge bug tracker
>>>>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>>>>> Discussions of bugs and features can be posted here
>>>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>>>>
>>>>
>>>>
>>>> Send bugs reports to the Sourceforge bug tracker
>>>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>>>> Discussions of bugs and features can be posted here
>>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Oeyvind Brandtsegg
>>> Professor of Music Technology
>>> NTNU
>>> 7491 Trondheim
>>> Norway
>>> Cell: +47 92 203 205
>>>
>>> http://flyndresang.no/
>>> http://www.partikkelaudio.com/
>>> http://soundcloud.com/brandtsegg
>>> http://soundcloud.com/t-emp
>>>
>>>
>>> Send bugs reports to the Sourceforge bug tracker
>>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>>> Discussions of bugs and features can be posted here
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>>
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://flyndresang.no/
> http://www.partikkelaudio.com/
> http://soundcloud.com/brandtsegg
> http://soundcloud.com/t-emp
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>