Esempio n. 1
0
        public Formant[] GetMFCCFormants(float[] mfcc, int maxCount)
        {
            //TODO: details
            List <Formant> formants = new List <Formant>();

            float dx   = 0.1f;
            float xmax = 1f;

            for (int i = 1; i < mfcc.Length - 1; i++)
            {
                //sharp top
                if (mfcc[i] > mfcc[i - 1] && mfcc[i] >= mfcc[i + 1])
                {
                    Formant formant = new Formant();

                    formant.TrackIndex = i;

                    float firstDerivative  = mfcc[i + 1] - mfcc[i - 1];
                    float secondDerivative = 2 * mfcc[i] - (mfcc[i - 1] + mfcc[i + 1]);

                    formant.MelFrequency = dx * (i - 1.0f + 0.5f * firstDerivative / secondDerivative);

                    float min3dB = 0.5f * (mfcc[i] + 0.125f * firstDerivative * firstDerivative / secondDerivative);

                    /* Search left. */
                    int j = i - 1;

                    while (mfcc[j] > min3dB && j > 1)
                    {
                        j--;
                    }

                    formant.MelBandwidth = mfcc[j] > min3dB ? formant.MelFrequency : formant.MelFrequency - dx * (j - 1 + (min3dB - mfcc[j]) / (mfcc[j + 1] - mfcc[j]));

                    /* Search right. */
                    j = i + 1;

                    while (mfcc[j] > min3dB && j < mfcc.Length)
                    {
                        j++;
                    }

                    formant.MelBandwidth += mfcc[j] > min3dB ? xmax - formant.MelFrequency : dx * (j - 1 - (min3dB - mfcc[j]) / (mfcc[j - 1] - mfcc[j])) - formant.MelFrequency;

                    formants.Add(formant);

                    if (formants.Count == maxCount)
                    {
                        break;
                    }
                }
            }
            return(formants.ToArray());
        }
Esempio n. 2
0
 static List<Formant[]> csvToObservations(string filename) {
     string[] lines = File.ReadAllLines(filename);
     List<Formant[]> observations = new List<Formant[]>(lines.Length - 1);
     for (int i = 1; i < lines.Length; i++) {
         Formant[] observation = new Formant[3];
         string[] parts = lines[i].Split(',');
         if (parts.Length != 6) {
             throw new InvalidDataException("Invalid number of items in csv line: " + lines[i]);
         }
         for (int j = 0; j < 3; j++) {
             observation[j].freq = float.Parse(parts[j]);
             observation[j].value = float.Parse(parts[j + 3]);
         }
         observations.Add(observation);
     }
     return observations;
 }
Esempio n. 3
0
 public Channel()
 {
     m_vco = new Envelope(0.0, 60.0 / VELOCITY_MAX2, 30.0 / VELOCITY_MAX2, 1.0 / VELOCITY_MAX2);
     m_vcf = new Envelope(0.0, 30.0 / VELOCITY_MAX2, 0.0, 1.0);
     m_osc1 = new Oscillator();
     m_mod1 = m_osc1.CurrentModulator;
     m_osc2 = new Oscillator() { Form = OscillatorForm.Sine };
     m_osc2.MakeAsLFO();
     m_mod2 = m_osc2.CurrentModulator;
     m_filter = new Filter();
     m_osc2connect = m_enableFilter = false;
     m_formant = new Formant();
     m_volumeMode = 0;
     m_expression = 0;
     m_onCounter = 0;
     m_lfoDelay = 0;
     m_lfoDepth = 0;
     m_lfoEnd = 0;
     m_lpfAmount = 0;
     m_lpfFrequency = 0;
     m_lpfResonance = 0;
     NoteIndex = 0;
     Detune = 0;
     m_frequencyIndex = 0;
     Pan = 64;
     Expression = 127;
     Velocity = 100;
     Input = new Events.Input() { Sens = 0, Pipe = 0 };
     Output = new Events.Output() { Mode = ChannelOutputMode.Default, Pipe = 0 };
     Ring = new Events.Ring() { Sens = 0, Pipe = 0 };
     Sync = new Events.Sync() { Mode = ChannelOutputMode.Default, Pipe = 0 };
 }