Hello there,

Rather than just focussing on short monophonic samples, I’ve decided to incorporate tonal movement into my project, so in addition to frequency & confidence readings, for this section of code I have needed to include some standard deviation calculations.

In consideration of the western scale, it would be sensible to set the conversion from Hertz to the tempered 12 note scale at 50cents (1/4 semitone) each side, I intend to add microtonna features but for this task it makes sense to set the SD at half tones. So once the signal deviates to the value of the frequency interval ratio I would like to store the mean from the current readings as 1 cell, value, then move on to the next batch of readings which will be collected until the pitch once again deviates beyond (above or below) the frequency interval ratios. But yeah I’m stuck on syntax and wanted to ask if anyone might be able to offer some help.

So, I would like to store the mean value, calculated from the first part of the stddev handler and store it as one reading, then move on to the next value until the pitch deviates past the limit then store that average and so on. Most of the tonal anomalies and unhelpful harmonic content has been removed by introducing a confidence threshold. So I should, for the best part be able to rely on the information thats there. Or that will hopefully be there if I can sucessfully procure the separate average readings.

I hope that makes some some and thank you in advance for any advice!

Heres what I have, minus the confidence value shell task/AS code, and theres no CSV so I just added some numbers.

Thanks again

Doug

```
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AVFAudio"
use scripting additions
property freqData : ""
-- reading the CSV
set my_data to read POSIX path of "Mojave:Users:dh:CSV:example.f0.csv" as «class furl»
set csvData to paragraphs 2 thru -2 of my_data as list -- theres a text row i want to be ignored
set freqData to {}
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
repeat with a_reading in csvData
set x to text item 1 of a_reading -- timestamp from CSV
set y to text item 2 of a_reading -- frequency readings from CSV
set z to text item 3 of a_reading -- confidence readings from CSV
set end of freqData to y --frequency readings stored
end repeat
on stddev(readingHz) -- standard deviation handler
set n to count of readingHz
set sum to 0
repeat with val in readingHz -- calculating the mean
set sum to sum + val
end repeat
set mean to sum / n
set sum to 0
repeat with val in readingHz
set sum to sum + (val - mean) ^ 2
end repeat
return (sum / (n - 1)) ^ 0.5
end stddev
stddev({61.05, 67.23, 71.23, 70, 65.84, 60.49}) -- pretend this is the freqData data
--> 4.466536316506
set sD to the result
```

Model: 2019 2.9 or something xeon core 16gb

AppleScript: Script Debugger 8

Browser: Safari 605.1.15

Operating System: macOS 10.15