stupid n00bie question: Part III
1. What is the simplest way to detect the pitch of an audio signal (from the mic) in Chuck? 2. How much wood could a woodChucK ChucK if a woodchucK could chucK wood? ------- -.- 1/f ))) --. ------- ... http://www.algomantra.com
AlgoMantra schrieb:
1. What is the simplest way to detect the pitch of an audio signal (from the mic) in Chuck?
zero crossing detection. count how many times the signal crosses zero. how many times a second it changes from positive to negative values or vice versa. that could be a rough estimate of the frequency. this is not very reliable but works quite well with sounds that are not too hissy. low pass filtering before counting helps a little bit. best joerg -- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/
Thanks Joerg.
although to be honest, I wasn't looking for the theoretical solution
but what kind of Chuck code objects to use for this. My Chuck
learning curve seems way slower than Python/PD, I don't know why.
I think it's the lack of explanatory notes in examples, or some kind
of proper tutorial.
On 10/16/07, joerg piringer
AlgoMantra schrieb:
1. What is the simplest way to detect the pitch of an audio signal (from the mic) in Chuck?
zero crossing detection. count how many times the signal crosses zero. how many times a second it changes from positive to negative values or vice versa. that could be a rough estimate of the frequency. this is not very reliable but works quite well with sounds that are not too hissy. low pass filtering before counting helps a little bit.
best joerg
-- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/ _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- ------- -.- 1/f ))) --. ------- ... http://www.algomantra.com
there's a zero crossing unit-gen in chuck: http://chuck.cs.princeton.edu/doc/program/ugen_full.html#zerox the example is not very meaningful i am afraid. here's some code i hacked together in a few minutes. it has some flaws (don't know exactly why i have to divide by four to get the correct value), but it works somehow. to use your mic you should substitute the SawOsc with adc. SawOsc o => ZeroX z => blackhole; o => dac; 1000 => o.freq; 0 => float val; 0 => float counter; 0 => float sampcounter; 1::second/1::samp => float samplerate; <<< "samplerate: ", samplerate >>>; while(true) { if(z.last() != val) { z.last() => val; 1 +=> counter; } 1 +=> sampcounter; if(sampcounter > samplerate) { <<< "freq: ", counter/4 >>>; 0 => sampcounter; 0 => counter; } 1::samp => now; } AlgoMantra schrieb:
Thanks Joerg.
although to be honest, I wasn't looking for the theoretical solution but what kind of Chuck code objects to use for this. My Chuck learning curve seems way slower than Python/PD, I don't know why. I think it's the lack of explanatory notes in examples, or some kind of proper tutorial.
On 10/16/07, *joerg piringer* < joerg@piringer.net mailto:joerg@piringer.net> wrote:
AlgoMantra schrieb: > 1. What is the simplest way to detect the pitch > of an audio signal (from the mic) in Chuck?
zero crossing detection. count how many times the signal crosses zero. how many times a second it changes from positive to negative values or vice versa. that could be a rough estimate of the frequency. this is not very reliable but works quite well with sounds that are not too hissy. low pass filtering before counting helps a little bit.
best joerg
-- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.iftaf.org http://www.vegetableorchestra.org/ _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu mailto:chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- ------- -.- 1/f ))) --. ------- ... http://www.algomantra.com
------------------------------------------------------------------------
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/
On 10/16/07, Martin Ahnelöv
each other time.
I thought you could make zeroX only count postive zero crossings as well, that would make it a bit easier, though it you count all of them you can also count half-cycles which should give a lower rounding error. I can't explain the x4 issue either. Another issue is this; if(sampcounter > samplerate) I think that should be "greater then or equal to". This way we are counting over a period of "second + samp", I think? Generally I think we are way better off using Uanae, that should result in a faster response, less influence from hiss and complicated wave-forms and there is no need to use a LPF and set it's cut-off in a way that requires assumptions about the signal. There will still be a trade between response-time and accuracy but it's a more efficient trade and there is no way around that anyway. Kas.
Martin Ahnelöv schrieb:
tis 2007-10-16 klockan 09:41 +0200 skrev joerg piringer:
if(sampcounter > samplerate) { <<< "freq: ", counter/4 >>>; 0 => sampcounter; 0 => counter; } 1::samp => now; }
Are you sure? Shouldn't it be counter/2? AFAIK, the sine crosses zero each other time.
i thought that too but trying out the program showed that /4 gave the right result. best joerg -- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/
ons 2007-10-17 klockan 10:50 +0200 skrev joerg piringer:
Martin Ahnelöv schrieb:
tis 2007-10-16 klockan 09:41 +0200 skrev joerg piringer:
if(sampcounter > samplerate) { <<< "freq: ", counter/4 >>>; 0 => sampcounter; 0 => counter; } 1::samp => now; }
Are you sure? Shouldn't it be counter/2? AFAIK, the sine crosses zero each other time.
i thought that too but trying out the program showed that /4 gave the right result.
Well, if that's the case... :) Gasten
On 10/16/07, AlgoMantra
1. What is the simplest way to detect the pitch of an audio signal (from the mic) in Chuck?
To add to Joerg's sugestion; Tracking zero crossings is a viable option, it gets used in a fair amount of hardware but due to it's limitations it tends to work best on simple signals and such hardware tends to be aimed at specific instruments (say bass guitar) because it helps if you can make a good guess what range the ouput should be in. Typically I'd only use zero-crossing for sub-octave generation. Another option is a phase-locked loop which comes down to synthesising a sine, comparing it to the signal to be analysed, look at the difference in phase, then tweak the sine until this difference becomes as small as possible. It has some of the same weaknesses but should be more accurate most of the time, it's less simple. It kinda depends in what way you want it to be simple; FFT analysis is not at all simple on a fundamental level but it's simplified considerably if Ge & Rebecca do all of the hard stuff for you :¬). Have a look at /chuck1.2.1.1/examples/analysis/tracking/tracking.ck (I think that's your solution) 2. How much wood could a woodChucK ChucK
if a woodchucK could chucK wood?
That's on the wish-list, Ge said it depends on garbage collection because of the splinters. Perry commented a while back that woodChucKs might be protected as well so that would further complicate matters. Obviously it won't be useful at all until we have trees which are generally a form of lists and we don't have lists (yet?). ;¬) Kas.
Joerg, I'll try your method in a week or so, when I have gone past the basic
ontological hurdles.
Kassen...I had to install the latest version 1.2.1.1 to find that tracking
example.
I never realised when that came up! Your various points are very insightful,
but obviously I tried the simplest looking option - the last. I just had to
add a line to
make it work:
<<< Tracking.the_freq >>>;
I am presuming this would be the frequency in Hertz? The mic seems quite
sensitive, I get a
reading of around 64.6 from the ambient noise, mostly traffic from the
nearby road. Hmm....
That's on the wish-list, Ge said it depends on garbage collection because of
the splinters.
Perry commented a while back that woodChucKs might be protected as well so
that
would further complicate matters. Obviously it won't be useful at all until
we have trees
which are generally a form of lists and we don't have lists (yet?).
Yesterday afternoon I was just sitting at my new office/studio, and in my
head battling
out Chuck versus PD, both of which I know very little. I was wondering which
one to
invest time with to get fast results for my current experiment. Then from
the balcony
sauntered in the sound of three kids playing cricket....the fat kid was
scolding one
of the skinny boys.....
"You're chucking!"
"No chucking!"
"That was a Chuck!"
For a moment, I thought it was an Omen.
(PS: In cricket, "chucking" is when you do not complete the circular
follow-through
action while bowling, or bend your elbow weirdly. Its a form of cheating.)
------- -.-
1/f ))) --.
------- ...
http://www.algomantra.com
On 10/16/07, Kassen
On 10/16/07, AlgoMantra
wrote: 1. What is the simplest way to detect the pitch of an audio signal (from the mic) in Chuck?
To add to Joerg's sugestion;
Tracking zero crossings is a viable option, it gets used in a fair amount of hardware but due to it's limitations it tends to work best on simple signals and such hardware tends to be aimed at specific instruments (say bass guitar) because it helps if you can make a good guess what range the ouput should be in. Typically I'd only use zero-crossing for sub-octave generation.
Another option is a phase-locked loop which comes down to synthesising a sine, comparing it to the signal to be analysed, look at the difference in phase, then tweak the sine until this difference becomes as small as possible. It has some of the same weaknesses but should be more accurate most of the time, it's less simple.
It kinda depends in what way you want it to be simple; FFT analysis is not at all simple on a fundamental level but it's simplified considerably if Ge & Rebecca do all of the hard stuff for you :¬). Have a look at /chuck1.2.1.1/examples/analysis/tracking/tracking.ck (I think that's your solution)
2. How much wood could a woodChucK ChucK
if a woodchucK could chucK wood?
That's on the wish-list, Ge said it depends on garbage collection because of the splinters. Perry commented a while back that woodChucKs might be protected as well so that would further complicate matters. Obviously it won't be useful at all until we have trees which are generally a form of lists and we don't have lists (yet?).
;¬)
Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
--
On 10/16/07, AlgoMantra
example.
The example should be in 1.2.1.0 already, I think. 1.2.1.1 wasn't announced that loudly, it's mainly a small update to correct some rather odd behaviour in Envelope. I'd say that upgrading can't hurt, except that this is ChucK and there is every chance that it *can* hurt :¬), for one thing I wrote a fix for the Envelope and I don't even speak C++..... I never realised when that came up! Your various points are very insightful,
but obviously I tried the simplest looking option - the last. I just had to add a line to make it work:
<<< Tracking.the_freq >>>;
I am presuming this would be the frequency in Hertz?
Yeah, I thinks so, it seems to be used that way (I'm still very new to the FFT game). The mic seems quite sensitive, I get a
reading of around 64.6 from the ambient noise, mostly traffic from the nearby road. Hmm....
Yes, that's likely caused by the room/mic/amp/ADC combination having a higher noise floor then your least significant bit. That's entirely normal, I don't think I've ever seen a system where that wasn't the case. What you can do is disregard peaks that are below a certain minimum amplitude or you could make the whole analysis thing stop running (and save cpu) as long as the signal is below a certain amplitude.... or you can set up a noise gate, doesn't Dyno have a expander option?
Yesterday afternoon I was just sitting at my new office/studio, and in my head battling out Chuck versus PD, both of which I know very little. I was wondering which one to invest time with to get fast results for my current experiment. Then from the balcony sauntered in the sound of three kids playing cricket....the fat kid was scolding one of the skinny boys.....
"You're chucking!" "No chucking!" "That was a Chuck!"
For a moment, I thought it was an Omen.
(PS: In cricket, "chucking" is when you do not complete the circular follow-through action while bowling, or bend your elbow weirdly. Its a form of cheating.)
Beautiful!!! Kas.
participants (4)
-
AlgoMantra
-
joerg piringer
-
Kassen
-
Martin Ahnelöv