Thanks for the numpy advice earlier.
I have now have two numpy-generated sine waves which have abrupt starts and stops:
They still make a click when played, so the adjustment to the nearest cycle seems off. What can I do to have the wave form end naturally at an amplitude of 0?
1) Should the formula, round(frequency * duration * 2, 0) / frequency / 2 be tweaked?
or
2) Is there a way to "gradually" increase the amplitude over n cycles at the beginning of each sample and decrease it for n cycles at the end at the one = (amplitude * one) formula by replacing 'amplitude' with some kind of range?
I have now have two numpy-generated sine waves which have abrupt starts and stops:
Code:
duration = 0.1amplitude = 1.0 # range [0.0, 1.0]sampleRate = 8000 # integer sample rate, Hzfrequency = 440.0 # float sine frequency, Hz# try to adjust to nearest cycleoneDuration = round(frequency * duration * 2, 0) / frequency / 2 twoDuration = round(frequency * duration * 2 * 3, 0) / frequency / 2# generate sine sample, with float32 array conversionone = ( numpy.sin( numpy.arange( sampleRate * oneDuration ) \ * frequency / sampleRate \ * numpy.pi * 2 ) ).astype( numpy.single )two = ( numpy.sin( numpy.arange( sampleRate * twoDuration ) \ * frequency / sampleRate \ * numpy.pi * 2 ) ).astype( numpy.single )one = (amplitude * one)two = (amplitude * two)1) Should the formula, round(frequency * duration * 2, 0) / frequency / 2 be tweaked?
or
2) Is there a way to "gradually" increase the amplitude over n cycles at the beginning of each sample and decrease it for n cycles at the end at the one = (amplitude * one) formula by replacing 'amplitude' with some kind of range?
Statistics: Posted by tpyo kingg — Sat Mar 22, 2025 9:53 am