On 21 October 2011 14:25, Edward Costello <
edwardcostello@gmail.com> wrote:
> So this is what I came up with
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
> sr = 44100
> ksmps = 128
> nchnls = 2
> 0dbfs = 1
>
> instr Init
> i_Threshold = 1.7
> i_MovingAverageSize = 64
>
> i_FFTSize = 1024
> i_HopSize = i_FFTSize / 4
> gi_AudioFileTable ftgen 0, 0, 0, -1, "major.wav", 0, 0, 1
> gi_PreviousMagnitudesTable ftgen 0, 0, i_FFTSize / 2, 2, 0
> gi_MovingAverageTable ftgen 0, 0, i_MovingAverageSize, 2, 0
> k_Trigger init 0
> gi_FFTFrameAmp ftgen 0, 0, i_FFTSize / 2, 2, 0
> f_AudioFile pvstanal 1, 1, 1, gi_AudioFileTable, 0, 0, 0, i_FFTSize,
> i_HopSize, 0
> k_Flag pvsftw f_AudioFile, gi_FFTFrameAmp
> if k_Flag == 1 then
> k_Index = 0
> k_Sum = 0
> k_Flux = 0
> AmpLoop:
>
> k_Amp table k_Index, gi_FFTFrameAmp
> k_PreviousAmp table k_Index, gi_PreviousMagnitudesTable
> k_Flux = k_Flux + abs(k_Amp - k_PreviousAmp)
> tablew k_Amp, k_Index, gi_PreviousMagnitudesTable
> loop_le k_Index, 1, i_FFTSize / 2, AmpLoop
> k_ShiftIndex = i_MovingAverageSize
> ShiftLoop:
>
> k_Shift table k_ShiftIndex - 1, gi_MovingAverageTable
> tablew k_Shift, k_ShiftIndex, gi_MovingAverageTable
>
> loop_ge k_ShiftIndex, 1, 0, ShiftLoop
>
> k_AverageSum = 0
> k_AverageIndex = 0
> k_Index = 0
> AverageLoop:
>
> k_AverageVal table k_Index, gi_MovingAverageTable
> k_AverageSum = k_AverageSum + k_AverageVal
> loop_le k_Index, 1, i_MovingAverageSize, AverageLoop
> k_MovingAverage = k_AverageSum / i_MovingAverageSize
> tablew k_Flux, 0,gi_MovingAverageTable
> endif
> a_Out pvsynth f_AudioFile
> ; printk2 k_Flux
> ; printk2 k_MovingAverage,5
> if k_Flux > k_MovingAverage * i_Threshold then
> if k_Trigger == 0 then
> k_Trigger = 1
> schedkwhen k_Trigger, 0, 1, "Beep", 0, 0.05
> endif
> endif
> if k_Flux >= k_MovingAverage * i_Threshold then
> k_Trigger = 0
> endif
> outs a_Out, a_Out
> endin
> instr Beep
> ares vco2 .2, 440
> outs ares, ares
> endin
> </CsInstruments>
> <CsScore>
> i "Init" 0 10
>
> </CsScore>
> </CsoundSynthesizer>
>
> The amplitudes of each bin are read and are subtracted from the previous
> bins amplitude, the absolute value of this figure for every bin is added
> together and this gives the flux value, this value is then written to a
> table which is used to take a running average of the flux. An onset is
> detected when the current flux value is larger than the current running
> average value multiplied by a threshold value, which is 1.7 in this example.
> It works ok but there are still plenty of false positives, you really need
> to tune the running average size and threshold values for the best results.
> Ed
>
>
>
>
>
> On 20 October 2011 20:13, Ed Costello <
edwardcostello@gmail.com> wrote:
>
> No problem, I'll try and get something up by the weekend,
> Ed
>
> On 20 October 2011 20:08, peiman khosravi <
peimankhosravi@gmail.com> wrote:
>
> I'd love to study your code when it's done :-)
>
> P
>
> On 20 October 2011 20:05, Ed Costello <
edwardcostello@gmail.com> wrote:
>> Thanks a million Pieman,
>> It looks like it will be easier than expected to get onset detection
>> working
>> :)
>> Cheers
>> Ed
>>
>> On 20 October 2011 19:24, peiman khosravi <
peimankhosravi@gmail.com>
>> wrote:
>>>
>>> * much easier [compared] to....
>>>
>>> On 20 October 2011 19:22, peiman khosravi <
peimankhosravi@gmail.com>
>>> wrote:
>>> > To be more specific.
>>> >
>>> > The analysed frames streamed from 'pvsanal' are written to table
>>> > consecutively by 'pvsftw'. So if you want to get the bin data you need
>>> > to process your table on each frame (once the data has been written).
>>> > For this you can use kflag as demonstrated in my last reply.
>>> >
>>> > So upon receiving each new frame you need to then loop through your
>>> > table indices in order to extract the data (now we can use the new t
>>> > signals too I guess for array operations).
>>> >
>>> > Once you get used to it it's actually a piece of cake, much easier to
>>> > how fft data is dealt with in maxmsp.
>>> >
>>> >
>>> > P
>>> >
>>> >
>>> > On 20 October 2011 19:09, peiman khosravi <
peimankhosravi@gmail.com>
>>> > wrote:
>>> >> Hi Ed,
>>> >>
>>> >> Yes.
>>> >>
>>> >> The kflag will be 1 when a new frame is written. So something like
>>> >> this would work:
>>> >>
>>> >> kflag pvsftw fsrc,ifn ; export amps to table
>>> >> if (kflag==1) then
>>> >> ;do something to the frame (I insert an UDO here)
>>> >> pvsftr fsrc,ifn
>>> >> endif
>>> >>
>>> >>
>>> >> For this kind of thing I usually make a UDO and pass the ftable to it,
>>> >> which is being read frame-by-frame.
>>> >>
>>> >> I have an article that discusses this method and might be worth
>>> >> looking at.
>>> >>
>>> >>
http://www.csounds.com/journal/issue12/implementingFrequencyWarping.html
>>> >>
>>> >> Best,
>>> >>
>>> >> Peiman
>>> >>
>>> >> On 20 October 2011 18:17, Ed Costello <
edwardcostello@gmail.com>
>>> >> wrote:
>>> >>> Hey List,
>>> >>> I want to compare the summed amplitudes of consecutive spectral
>>> >>> frames
>>> >>> in
>>> >>> order to make a note onset detector in Csound. It looks like I need
>>> >>> to
>>> >>> use pvsftw to accomplish this. I was just wondering how pvsftw works
>>> >>> as I
>>> >>> can't figure out how it goes about reading frames, does it just read
>>> >>> each
>>> >>> frame as they are streamed to it from a pvstanal or similar?
>>> >>> Thanks
>>> >>> Ed
>>> >>
>>> >
>>>
>>>
>>> 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"
>
>
>
>
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"