DROP TABLE pitchsemitones_fm;

SELECT 
pitch_fm.id AS id, 
pitch_fm.value AS value,
pitch_fm.valid AS valid,
pitch_fm.minimum AS minimum, 
pitch_fm.maximum AS maximum, 
pitch_fm.time0 AS time0, 
pitch_fm.time1 AS time1, 
pitch_fm.time2 AS time2, 
pitch_fm.time3 AS time3, 
pitch_fm.time4 AS time4,
pitch_fm.tmax AS tmax,
pitch_fm.tmin AS tmin,
pitch_fm.best AS best

INTO
pitchsemitones_fm
FROM 
pitch_fm
WHERE
pitch_fm.time2 > 0
;

CREATE INDEX pitchsemitones_fm_index on pitchsemitones_fm (id);

GRANT SELECT on pitchsemitones_fm TO PUBLIC;

UPDATE 
    pitchsemitones_fm
SET
   minimum =  12*(ln(minimum) - ln(50))/ln(2.0)
WHERE
    minimum > 0
;

UPDATE 
    pitchsemitones_fm
SET
   maximum =  12*(ln(maximum) - ln(50))/ln(2.0)
WHERE
    maximum > 0
;

UPDATE 
    pitchsemitones_fm
SET
   time0 =  12*(ln(time0) - ln(50))/ln(2.0)
WHERE
    time0 > 0
;

UPDATE 
    pitchsemitones_fm
SET
   time1 =  12*(ln(time1) - ln(50))/ln(2.0)
WHERE
    time1 > 0
;

UPDATE 
    pitchsemitones_fm
SET
   time2 =  12*(ln(time2) - ln(50))/ln(2.0)
WHERE
    time2 > 0
;

UPDATE 
    pitchsemitones_fm
SET
   time3 =  12*(ln(time3) - ln(50))/ln(2.0)
WHERE
    time3 > 0
;

UPDATE 
    pitchsemitones_fm
SET
   time4 =  12*(ln(time4) - ln(50))/ln(2.0)
WHERE
    time4 > 0
;

UPDATE 
    pitchsemitones_fm
SET
   best =  12*(ln(best) - ln(50))/ln(2.0)
WHERE
    best > 0
;

DROP TABLE pitchsemitones_hm;

SELECT 
pitch_hm.id AS id, 
pitch_hm.value AS value,
pitch_hm.valid AS valid,
pitch_hm.minimum AS minimum, 
pitch_hm.maximum AS maximum, 
pitch_hm.time0 AS time0, 
pitch_hm.time1 AS time1, 
pitch_hm.time2 AS time2, 
pitch_hm.time3 AS time3, 
pitch_hm.time4 AS time4,
pitch_hm.tmax AS tmax,
pitch_hm.tmin AS tmin,
pitch_hm.best AS best

INTO
pitchsemitones_hm
FROM 
pitch_hm
WHERE
pitch_hm.time2 > 0
;

CREATE INDEX pitchsemitones_hm_index on pitchsemitones_hm (id);

GRANT SELECT on pitchsemitones_hm TO PUBLIC;

UPDATE 
    pitchsemitones_hm
SET
   minimum =  12*(ln(minimum) - ln(50))/ln(2.0)
WHERE
    minimum > 0
;

UPDATE 
    pitchsemitones_hm
SET
   maximum =  12*(ln(maximum) - ln(50))/ln(2.0)
WHERE
    maximum > 0
;

UPDATE 
    pitchsemitones_hm
SET
   time0 =  12*(ln(time0) - ln(50))/ln(2.0)
WHERE
    time0 > 0
;

UPDATE 
    pitchsemitones_hm
SET
   time1 =  12*(ln(time1) - ln(50))/ln(2.0)
WHERE
    time1 > 0
;

UPDATE 
    pitchsemitones_hm
SET
   time2 =  12*(ln(time2) - ln(50))/ln(2.0)
WHERE
    time2 > 0
;

UPDATE 
    pitchsemitones_hm
SET
   time3 =  12*(ln(time3) - ln(50))/ln(2.0)
WHERE
    time3 > 0
;

UPDATE 
    pitchsemitones_hm
SET
   time4 =  12*(ln(time4) - ln(50))/ln(2.0)
WHERE
    time4 > 0
;

UPDATE 
    pitchsemitones_hm
SET
   best =  12*(ln(best) - ln(50))/ln(2.0)
WHERE
    best > 0
;

