An adaptive waveform coding algorithm and its application in speech coding