Wednesday, May 21, 2014

24. rand, buzz and gbuzz


rand, buzz and gbuzz are three opcodes producing frequency rich signals. They usually have to be filtered to remove frequencies, a topic covered later.




The rand opcode generates a random sequence. All the random values are between minus and positive of the first parameter, and the only required one.




This String uses a rand opcode, to generate a sequence between negative .5 and positive .5.




A noise signal will have a nearly uniform frequency spectrum.




The buzz opcode uses a sine input frequency, to create a signal with many harmonics. In xcps we give the fundamental frequency, and then we give the number of harmonics we need.




In this String using the buzz opcode, we request 3 harmonics of 440 Hz. The parameter value 1 indicates the table where the sine function is located, for our example.




In the frequency spectrum, we can see that there are three frequencies, 440 Hz, 2 times 440 Hz, and 3 times 440 Hz. All three have the same magnitude.




The gbuzz opcode creates a set of harmonics based on a cosine wave. We have to give it the fundamental frequency, number of harmonics in the output and the lowest harmonic that will be in the output. In addition, there is a parameter, kmul, which is a multiplying factor, controlling how harmonics increase or decrease.




This Instrument String, uses gbuzz to create 3 harmonics of 440 Hz, but we start with the 2nd harmonic (2 times 440 Hz) and the higher frequencies damp off with a multiplying factor of 0.7. We use the cosine table, which is numbered 2, in our program.


# Main.py

from moduleCsound import *
addTag(startSyn,startOpt,stopOpt,startIns)
header()

# *** Instrument Strings ***

randStr="""
asig rand 0.5
out asig
"""

buzzStr="""
asig buzz 1, 440, 3, 1
out asig 
"""

gbuzzStr="""
asig gbuzz 1, 440, 3, 2, 0.7, 2
out asig
"""


instrument('rand',1,randStr)
instrument('buzz',2,buzzStr)
instrument('gbuzz',3,gbuzzStr)

addTag(stopIns,startSco)

# *** Table ***
table('1. Sine wave',1,0,8192,10,1)
table('2. Cosine wave',2,0,8192,11,1,1)

# *** Score ***
score(1,0,3)
score(2,3,3)
score(3,6,3)

addTag(stopSco,stopSyn)
writeRun('Tut24')



This shows the three frequencies starting at 880 Hz (2 times 440 Hz) which are reducing at the rate of 0.7.


; Tut24.csd
<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 10
nchnls = 1
0dbfs = 1
; rand
instr 1
  asig rand 0.5
  out asig
endin
; buzz
instr 2
  asig buzz 1, 440, 3, 1
  out asig 
endin
; gbuzz
instr 3
  asig gbuzz 1, 440, 3, 2, 0.7, 2
  out asig
endin
</CsInstruments>
<CsScore>
; 1. Sine wave
f 1 0 8192 10 1
; 2. Cosine wave
f 2 0 8192 11 1 1
i 1 0 3
i 2 3 3
i 3 6 3
</CsScore>
</CsoundSynthesizer>



You will find additional information at pythonaudio.blogspot.com, including the source code.



This is the video of Tutorial 24:


24 comments:

  1. Nice blog..! I really loved reading through this blog and coding ... Thanks for sharing such an amazing post with us and keep blogging...
    Python Training

    ReplyDelete
  2. Nice One. Thanks for Sharing this Valuable Information
    Python Training

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Nice blog..Keep sharing your knowledge through blog
    visit Best Python Course Jaipur

    ReplyDelete
  5. Nice blog. thank you.
    web programming tutorial
    welookups

    ReplyDelete
  6. Nice blog,Thank you for sharing and keep sharing your information through this blog.Click Here: Python Online Training || Python Online Course

    ReplyDelete
  7. Nice blog for beginners.thank you for sharing useful post.Click here: Python Online Training || Python Online Training

    ReplyDelete
  8. Nice blog...Thanks for sharing Great Content...Keep Going On...
    Best Python Training Institutes in Hyderabad

    ReplyDelete
  9. Thank you for your Tutorial, well more than that actually. Im working on something now, inspired by this and Ill comment again when its complete. Thank you!

    ReplyDelete
  10. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Artificial Intelligence Training
    Java Training
    AWS Training
    Machine Learning Training
    Data Science Training
    DevOps Training

    ReplyDelete
  11. Trainingicon is offering Python training in Delhi NCR. We are a training institute in Delhi and Noida.We provide industrial training in programming like Python, PHP, Web designing, R Programming etc so if any body is looking to get trained into any skills, just let us know.following is the link to get enrilled into python batch
    Python Training in Delhi

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. landscaping,landscaping ideas,front yard landscaping ideas,landscaping business,تنسيق الحدائق المنزلية في مصر,افكار تنسيق حدائق تنسيق حدائق منزلية,أسس تصميم الحدائق المنزلية,تنسيق الحدائق,تنسيق حدائق,تنسيق حدائق منزلية بالصور,تنسيق,حدائق منزلية صغيرة,تنسيق حدائق منزلية,شركة تنسيق حدائق,لاند سكيب حدائق منزلية صغيرة,أفكار حدائق بسيطة,الحدائق المنزلية البسيطة,تصميم حدائق,تنسيق حدائق منازل,مدخل حديقة المنزل,تنسيق حدائق منزلية مصر

    ReplyDelete
  17. You've shared some extremely valuable knowledge. This is often a fantastic way for us to expand our skills while still being useful to us. Many thanks for bringing this post to our attention. python training in delhi

    ReplyDelete
  18. Thanks for sharing it. I always enjoy reading such superb content with valuable information. The ideas presented are excellent and really cool, making the post truly enjoyable. Keep up the fantastic work.
    visit: Exploring Network Programming with Sockets

    ReplyDelete

About Me

I have used Python for the last 10+ years. I have a PhD in Electrical Engineering. I have taught Assembly Language programming of Intel-compatible chips as well as PC hardware interfacing. In my research, I have used Python to automate my calculations in physics and chemistry. I also use C++ and Java, often with Python.