Popular recipes tagged "mod"http://code.activestate.com/recipes/tags/mod/2013-01-31T23:41:21-08:00ActiveState Code RecipesAmplitude Modulation - Tremolo, Was:- An Audio/Sound Snippet For Linux... ;o) (Python)
2012-01-21T14:18:28-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578013-amplitude-modulation-tremolo-was-an-audiosound-sni/
<p style="color: grey">
Python
recipe 578013
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amplitude/">amplitude</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/mod/">mod</a>, <a href="/recipes/tags/modulation/">modulation</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/tremolo/">tremolo</a>).
Revision 2.
</p>
<p>This IS for the big guns as well as the amatuer...</p>
<p>I am always being told that too many comments inside any code is bad and that professional coders are clever enough to work out what a program does without comments...</p>
<p>So here goes! This snippet of code hits /dev/dsp in Linux and has no comments as to what it does.
Make sure that /dev/dsp is available in your Linux install - if not then install oss.compat from your repository.</p>
<p>It needs Python 2.6 minimum, but may well work on a much earlier version</p>
<p>Don't run the code first but have a go at working out what it does and see if you are correct... ;o)</p>
<p>You can email me if you think you are/were correct:- <a href="http://wisecracker_at_tesco.net" rel="nofollow">wisecracker_at_tesco.net</a></p>
<p>Bear in mind I don't think this has ever been done before by hitting the /dev/dsp __directly__.</p>
<p>NOTE:- NO imports are required at all!!!</p>
<p>It runs for about 7 seconds before exiting...</p>
<p>Another BIG PLUS for Linux.</p>
<p>(I have a feeling poeple on here might like this, possibly even vote it up. ;)</p>
<p>Answer now at the bottom of this page...</p>
<p>Enjoy...</p>
<p>Bazza, G0LCU...</p>
Inverse modulo p (Python)
2013-01-31T23:41:21-08:00Justin Shawhttp://code.activestate.com/recipes/users/1523109/http://code.activestate.com/recipes/576737-inverse-modulo-p/
<p style="color: grey">
Python
recipe 576737
by <a href="/recipes/users/1523109/">Justin Shaw</a>
(<a href="/recipes/tags/mod/">mod</a>, <a href="/recipes/tags/modulo/">modulo</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/theory/">theory</a>).
Revision 4.
</p>
<p>Very rarely it is necessary to find the multiplicative inverse of a number in the ring of integers modulo p. Thie recipe handles those rare cases. That is, given x, an integer, and p the modulus, we seek a integer x^-1 such that x * x^-1 = 1 mod p. For example 38 is the inverse of 8 modulo 101 since 38 * 8 = 304 = 1 mod 101. The inverse only exists when a and p are relatively prime.</p>