0

Hello I'm trying to write a program that will wrap an ASD envelop to a trangle wave sound. I can't seem to get my trangle one to work. I did get my sine wave to work. What could I change to get it to do a trangle?

def asd(fileName,nSeconds,cyclesPerSecond,maxAmp):
 newsound=makeEmptySound(nSeconds)
 samplesPerSecond=getSamplingRate(newsound)
 samplesPerCycle=samplesPerSecond/cyclesPerSecond
 maxCycle=2*pi
 ns=getLength(newsound)+1
 ns1=ns/3
 ns2=ns1*2
 #attack
 for s in range(1,ns1):
  rawSample=sin(((s%samplesPerCycle)/samplesPerCycle)*maxCycle)
  sampleValue=int((float(s)%ns1)/ns1*maxAmp*rawSample)
  setSampleValueAt(newsound,s,sampleValue)
 #sustain
 for s in range(ns1,ns2):
  rawSample=sin(((s%samplesPerCycle)/samplesPerCycle)*maxCycle)
  sampleValue=int(maxAmp*rawSample)
  setSampleValueAt(newsound,s,sampleValue)
 #decay
 for s in range(ns2,ns):
  rawSample=sin(((s%samplesPerCycle)/samplesPerCycle)*maxCycle)
  sampleValue=int((ns1-(float(s)%ns1))/ns1*maxAmp*rawSample)
  setSampleValueAt(newsound,s,sampleValue)
 return(newsound)
#To run type newsound=asd("aa",1,440,4000)
#then play(newsound)
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by sneekula
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.