# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Created on Mon Mar 04 2013 # danilo [dot] bellini [at] gmail [dot] com """ LPC plot with DFT, showing two formants (magnitude peaks) """ from audiolazy import sHz, sin_table, str2freq, lpc import pylab rate = 22050 s, Hz = sHz(rate) size = 512 table = sin_table.harmonize({1: 1, 2: 5, 3: 3, 4: 2, 6: 9, 8: 1}).normalize() data = table(str2freq("Bb3") * Hz).take(size) filt = lpc(data, order=14) # Analysis filter gain = 1e-2 # Gain just for alignment with DFT # Plots the synthesis filter # - If blk is given, plots the block DFT together with the filter # - If rate is given, shows the frequency range in Hz (gain / filt).plot(blk=data, rate=rate, samples=1024, unwrap=False) pylab.ioff() pylab.show()
------- A list with the synthesized note. """ first_dur, a, d, r, gain = [(30 * ms, 10 * ms, 8 * ms, 10 * ms, .4), (60 * ms, 20 * ms, 8 * ms, 20 * ms, .5)][idx] env = chain( adsr(first_dur, a=a, d=d, s=.2, r=r), adsr(dur - first_dur, a=10 * ms, d=30 * ms, s=.2, r=dur - 50 * ms)) result = gauss_noise(dur) * env * gain return list(result) # Values used by the unpitched low synth harmonics = dict(enumerate([3] * 4 + [2] * 4 + [1] * 10)) low_table = sin_table.harmonize(harmonics).normalize() @memoize def unpitched_low(dur, idx): """ Non-harmonic bass/lower frequency sound as a list (due to memoization). Parameters ---------- dur: Duration, in samples. idx: Zero or one (integer), for a small difference to the sound played. Returns
Returns ------- A list with the synthesized note. """ first_dur, a, d, r, gain = [(30 * ms, 10 * ms, 8 * ms, 10 * ms, 0.4), (60 * ms, 20 * ms, 8 * ms, 20 * ms, 0.5)][idx] env = chain( adsr(first_dur, a=a, d=d, s=0.2, r=r), adsr(dur - first_dur, a=10 * ms, d=30 * ms, s=0.2, r=dur - 50 * ms) ) result = gauss_noise(dur) * env * gain return list(result) # Values used by the unpitched low synth harmonics = dict(enumerate([3] * 4 + [2] * 4 + [1] * 10)) low_table = sin_table.harmonize(harmonics).normalize() @memoize def unpitched_low(dur, idx): """ Non-harmonic bass/lower frequency sound as a list (due to memoization). Parameters ---------- dur: Duration, in samples. idx: Zero or one (integer), for a small difference to the sound played. Returns