Slimelite BBS

Ami_Square_Wave.py.txt

Back to src

Generate simple audio using Python.

Size
6.3K (6,439 bytes)
Added
2026-11-20 02:44
Downloads
2
Long Description
Distribution: Public Domain, Emailware. ============================================================================ Architectures: Classic AMIGAs, WinUAE and E-UAE. ------------------------------------------------ MINIMUM Requirements Are:- -------------------------- 68EC020 CPU and 2MB RAM total, example, a standard A1200(HD). WinUAE, AF2005 minimum, E-UAE. Standard OS3.0x install or better. Full Python 1.4.x, minimum, installed. (Python 1.5.2 to 2.0.x are also available on AMINET.) (Now Python 2.4.6 is available for advanced 68K machines.) ---------------------------------------------------------------------------- History. -------- 12-12-2011. Version 0.00.30:- Correct a very minor error in the Python code that will probably never, ever, be detected. 21-11-2011. Version 0.00.20:- Added keyboard access to alter output level and show how it is done. 14-11-2011. Version 0.00.10:- Original upload to AMINET... ---------------------------------------------------------------------------- To install just download the "Ami_Square_Wave.py.txt" file and rename it to "Ami_Square_Wave.py" without the quotes. Drag this file into the PYTHON: volume and away you go... From a Python prompt:- >>> execfile("PYTHON:Ami_Square_Wave.py") And away you go... ---------------------------------------------------------------------------- The DEMO assembly code that will be compiled and converted. Call the code beep.asm... From a CLI and using the a68k anf blink from AMINET:- Prompt> a68k beep.asm<RETURN/ENTER> Some reports here... Prompt> blink beep.o<RETURN/ENTER> Some reports here... This code is TOTALLY position independent. start: ;"beep.asm" test code... movem.l d0-d7/a0-a6,-(sp) ;Save all registers just in case. movea.l $4,a6 ;Set ~execbase~. moveq #16,d0 ;Length of square wave data. moveq #2,d1 ;Set to chip ram. jsr -198(a6) ;Allocate memory for the task. beq.s getout ;On error, Quit. move.l d0,a0 ;Set address in chip ram. move.l #$3f3f3f3f,(a0) ;Set first four bytes of sixteen. addq.l #4,a0 ;Move addres by four. move.l #$3f3f3f3f,(a0) ;Set next four bytes of sixteen. addq.l #4,a0 ;Move addres by four. move.l #$80808080,(a0) ;Set next four bytes of sixteen. addq.l #4,a0 ;Move addres by four. move.l #$80808080,(a0) ;Set last four bytes of sixteen. ;This ensures absolute position ;independence. lea $dff000,a5 ;Set HW register base. move.w #$000f,$96(a5) ;Disable audio DMA. move.l d0,$a0(a5) ;Set address of audio data. move.w #8,$a4(a5) ;Set length in words. move.w #64,$a8(a5) ;Set volume to maximun. move.w #220,$a6(a5) ;Set the period. move.w #$00ff,$9e(a5) ;Disable any modulation. move.w #$8201,$96(a5) ;Enable audio DMA. wait: btst #6,$bfe001 ;If LMB pressed then Quit. beq.s closeme ;Do it. bne.s wait ;Play the tone until LMB pressed... closeme: move.w #$000f,$96(a5) ;Disable audio DMA. move.l d0,a0 ;Address of the square wave data. moveq #16,d0 ;The data length to recover. jsr -210(a6) ;Free assigned memory. getout: movem.l (sp)+,d0-d7/a0-a6 ;Restore all registers. clr.l d0 ;Set returm code OK. rts nop even end ---------------------------------------------------------------------------- The text HEX file to be edited for the Python code:- Prompt> Type HEX beep > beep.hex<RETURN/ENTER> Gives a text file "beep.hex" that has the contents:- 0000: 000003F3 00000000 00000001 00000000 ...ó............ 0010: 00000000 00000021 000003E9 00000021 .......!...é...! 0020: 48E7FFFE 2C780004 70107202 4EAEFF3A Hç.þ,x..p.r.N®.: 0030: 67682040 20BC3F3F 3F3F5888 20BC3F3F gZ @ Œ????X. Œ?? 0040: 3F3F5888 20BC8080 80805888 20BC8080 ??X. Œ....X. Œ.. 0050: 80804BF9 00DFF000 3B7C000F 00962B40 ..Kù.ßð.;|....+@ 0060: 00A03B7C 000800A4 3B7C0040 00A83B7C . ;|...€;|.@.š;| 0070: 00DC00A6 3B7C00FF 009E3B7C 82010096 .Ü.Š;|....;|.... 0