home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / mus / Maestix / demos / SineTone.s < prev    next >
Text File  |  1995-02-25  |  9KB  |  288 lines

  1. *****************************************************************
  2. *                                *
  3. *    maestix.library-Demo:    SineTone            *
  4. *                                *
  5. *****************************************************************
  6. *
  7. *    Programmed by        Richard Körber
  8. *    Date            1995-01-30
  9. *
  10. *****************************************************************
  11. *  This  demonstration shows the  basic transmit  functions of  *
  12. *  the  maestix library.  It allocates the  Maestro soundcard,  *
  13. *  prepares a sine  wave buffer  and outputs it  with a 48 kHz    *
  14. *  Rate, resulting a 1.5 kHz sine wave.                *
  15. *****************************************************************
  16.  
  17.         INCDIR    "include:"
  18.         INCLUDE    exec.i            ; Library call macros
  19.         INCLUDE    intuition.i
  20.         INCLUDE    graphics.i
  21.         INCLUDE    dos.i
  22.         INCLUDE    maestix.i
  23.         INCLUDE    libraries/maestix.i    ;Reference includes
  24.         INCLUDE    intuition/intuition.i
  25.         INCLUDE    dos/dostags.i
  26.         INCLUDE    exec/ports.i
  27.  
  28. BUFSIZE        EQU    12*1024            ;size of FIFO data block
  29.  
  30.         SECTION text,CODE
  31.  
  32. *---------------------------------------------------------------*
  33. *    == START OF PROGRAM ==                    *
  34. *                                *
  35. start    ;-- Open all libraries -----------------;
  36.         lea    maestname(PC),a1    ;maestix
  37.         moveq    #35,d0            ; V35+
  38.         exec    OpenLibrary        ; open
  39.         move.l    d0,maestbase        ; store base
  40.         beq    error1            ; not found!
  41.         lea    intuiname(PC),a1    ;intuition
  42.         moveq    #36,d0            ; V36+
  43.         exec    OpenLibrary        ; open
  44.         move.l    d0,intuibase        ; store base
  45.         beq    error2
  46.         lea    dosname(PC),a1        ;dos
  47.         moveq    #36,d0            ; V36+
  48.         exec    OpenLibrary        ; open
  49.         move.l    d0,dosbase        ; store base
  50.         beq    error3
  51.     ;-- Create buffer ----------------------;
  52.         move.l    #BUFSIZE*2,d0        ;size of two buffers
  53.         moveq    #$1,d1            ;PUBLIC
  54.         exec    AllocMem
  55.         move.l    d0,buffer
  56.         beq    error4
  57.     ;-- Fill the buffer --------------------;
  58.         lea    sintab(PC),a0        ;^Sine tab
  59.         move.l    buffer(PC),a1        ;^Output puffer
  60.         moveq    #0,d0            ;sine tab index pointer
  61.         move.l    #BUFSIZE*2/4,d1        ;longword counter
  62. .fillbuff    subq.l    #1,d1            ;one lw less
  63.         bcs.b    .filldone        ; fill has been done
  64.         move    (a0,d0.w),(a1)+        ;left channel
  65.         move    (a0,d0.w),(a1)+        ;right channel
  66.         addq    #2,d0            ;index to next word
  67.         and    #63,d0            ;modulo 64
  68.         bra.b    .fillbuff
  69.     ;-- Alloc signal bits ------------------;
  70. .filldone    sub.l    a1,a1            ;get task ptr
  71.         exec    FindTask
  72.         move.l    d0,maintask
  73.         moveq    #-1,d0            ;Allocate a signal bit
  74.         exec    AllocSignal
  75.         move.b    d0,donesigbit
  76.         cmp.b    #-1,d0            ;no signals free?
  77.         beq.w    error5
  78.     ;-- Open a window ----------------------;
  79.         sub.l    a0,a0            ;no newwindow struct
  80.         lea    windowtags(PC),a1    ; but loads of tags
  81.         intui    OpenWindowTagList
  82.         move.l    d0,window
  83.         beq    error6
  84.     ;-- Launch level task ------------------;
  85.         move.l    #tasktags,d1        ;Tags for new task
  86.         dos    CreateNewProc        ;create new process
  87.         tst.l    d0            ;got the task?
  88.         beq    error7
  89.         moveq    #0,d0            ;wait 'till 2nd task setup'd
  90.         move.b    donesigbit(PC),d1    ; signal
  91.         bset    d1,d0
  92.         exec    Wait            ;wait for this event
  93.     ;-- Wait for reply (main loop) ---------;
  94. .mainloop    move.l    window(PC),a0        ;window message?
  95.         move.l    wd_UserPort(a0),a0    ; ^message port
  96.         exec    WaitPort
  97. .nextmsg    move.l    window(PC),a0        ;window message?
  98.         move.l    wd_UserPort(a0),a0    ; ^message port
  99.         exec    GetMsg            ; try to get it...
  100.         tst.l    d0            ; got one?
  101.         beq.b    .mainloop        ; nope: wait for next msg
  102.     ;---- got a window event ---------------;
  103.         move.l    d0,a0            ;^IDCMP-message -> a0
  104.         cmp.l    #IDCMP_CLOSEWINDOW,im_Class(a0) ;close window?
  105.         bne.b    .nextmsg        ; no -> look for next msg
  106.     ;-- Exit program -----------------------;
  107. exit        move.l    sinetask(PC),a1        ;Shut sine task
  108.         moveq    #0,d0
  109.         move.b    sinesigbit(PC),d1
  110.         bset    d1,d0
  111.         exec    Signal            ; signals the exit
  112.         moveq    #0,d0            ;wait 'till 2nd task exited
  113.         move.b    donesigbit(PC),d1    ; signal
  114.         bset    d1,d0
  115.         exec    Wait            ;wait for this event
  116.         moveq    #20,d1
  117.         dos    Delay
  118. error7        move.l    window(PC),a0        ;Close output window
  119.         intui    CloseWindow
  120. error6        move.b    donesigbit(PC),d0
  121.         exec    FreeSignal
  122. error5        move.l    buffer(PC),a1        ;^Buffer
  123.         move.l    #BUFSIZE*2,d0
  124.         exec    FreeMem
  125. error4        move.l    dosbase(PC),a1        ;close dos library
  126.         exec    CloseLibrary
  127. error3        move.l    intuibase(PC),a1    ;close intuition library
  128.         exec    CloseLibrary
  129. error2        move.l    maestbase(PC),a1    ;close maestix library
  130.         exec    CloseLibrary
  131. error1        moveq    #0,d0            ;Reply 0
  132.         rts                ;back to CLI
  133.  
  134. *---------------------------------------------------------------*
  135. *    == SINE PROCESS ==                    *
  136. *                                *
  137. SineProc
  138.     ;-- Get exiting signal -----------------;
  139.         sub.l    a1,a1            ;Get task structure
  140.         exec    FindTask
  141.         move.l    d0,sinetask
  142.         moveq    #-1,d0            ;get sig bit
  143.         exec    AllocSignal
  144.         move.b    d0,sinesigbit
  145.         cmp.b    #-1,d0            ;got no bit
  146.         beq    .error1
  147.         move.l    maintask(PC),a1        ;task is done
  148.         moveq    #0,d0
  149.         move.b    donesigbit(PC),d1
  150.         bset    d1,d0
  151.         exec    Signal            ; signals the exit
  152.     ;-- Allocate Maestro -------------------;
  153.         sub.l    a0,a0            ;no tags
  154.         maest    AllocMaestro
  155.         move.l    d0,maestro        ;^Maestro base
  156.         beq    .error2
  157.     ;-- Set Modus --------------------------;
  158.         move.l    maestro(PC),a0        ;^Maestro base
  159.         lea    modustags(PC),a1    ;^Modus tags
  160.         maest    SetMaestro        ;set it now
  161.     ;-- Create Transmit-Messageport --------;
  162.         exec    CreateMsgPort        ;create a messageport
  163.         move.l    d0,tport        ; as transmit port
  164.         beq    .error4
  165.     ;-- Init messages ----------------------;
  166.         move.l    tport(PC),d1        ;^Receive Reply Port
  167.         lea    msg1(PC),a0        ;^1st Message
  168.         lea    msg2(PC),a1
  169.         move.l    buffer(PC),d0        ;get buffer ptr
  170.         move.l    d0,(dmn_BufPtr,a0)    ; set buffer1
  171.         add.l    #BUFSIZE,d0
  172.         move.l    d0,(dmn_BufPtr,a1)    ; set buffer2
  173.         move.l    #BUFSIZE,(dmn_BufLen,a0) ;Set buffer length
  174.         move.l    #BUFSIZE,(dmn_BufLen,a1)
  175.         move.l    d1,(MN_REPLYPORT,a0)    ;Set Reply-Port
  176.         move.l    d1,(MN_REPLYPORT,a1)
  177.         move    #dmn_SIZEOF,(MN_LENGTH,a0) ;Set msg length
  178.         move    #dmn_SIZEOF,(MN_LENGTH,a1)
  179.     ;-- Start transmit process -------------;
  180.         move.l    maestro(PC),a0        ;transmit msg to library
  181.         lea    msg1(PC),a1
  182.         maest    TransmitData        ; the 1st (starts transmitter!)
  183.         move.l    maestro(PC),a0
  184.         lea    msg2(PC),a1
  185.         maest    TransmitData        ; and the 2nd
  186.     ;-- wait for messages ------------------;
  187. .mainloop    move.l    tport(PC),a0        ;maestix message?
  188.         exec    GetMsg            ; try to get it...
  189.         tst.l    d0            ; got one?
  190.         bne.b    .gotmaestro        ; then evaluate it
  191.         moveq    #0,d0            ;create wait mask
  192.         move.b    sinesigbit(PC),d1    ; signal for exiting
  193.         bset    d1,d0
  194.         move.l    tport(PC),a0        ; second, from receive port
  195.         move.b    MP_SIGBIT(a0),d1    ; sig bit
  196.         bset    d1,d0            ; set this bit
  197.         exec    Wait            ;wait for these events
  198.         move.b    sinesigbit(PC),d1    ; exit forced?
  199.         btst    d1,d0            ; test this bit
  200.         beq.b    .mainloop        ;not wanted -> main loop
  201.         bra.b    .exit            ; wanted -> leave
  202.     ;---- got a maestix event --------------;
  203. .gotmaestro    move.l    maestro(PC),a0        ;Re-send message
  204.         move.l    d0,a1
  205.         maest    TransmitData        ; to maestix library
  206.         bra.b    .mainloop
  207.     ;-- Leave task -------------------------;
  208. .exit        move.l    maestro(PC),a0        ;Flush messages
  209.         maest    FlushTransmit
  210.         move.l    tport(PC),a0        ;delete receive port
  211.         exec    DeleteMsgPort
  212. .error4        move.b    sinesigbit(PC),d0    ;free signal bit
  213.         exec    FreeSignal
  214. .error3        move.l    maestro(PC),a0        ;Set maestro free
  215.         maest    FreeMaestro
  216. .error2        move.l    maintask(PC),a1        ;task is done
  217.         moveq    #0,d0
  218.         move.b    donesigbit(PC),d1
  219.         bset    d1,d0
  220.         exec    Signal            ; signals the exit
  221. .error1        rts                ;done (freed by DOS)
  222.  
  223. *---------------------------------------------------------------*
  224. *    == DATA SECTION ==                    *
  225. *                                *
  226. maintask    dc.l    0            ;^Main task
  227. sinetask    dc.l    0            ;^Sine task
  228. sinesigbit    dc.b    0            ;Sine task signal bit
  229. donesigbit    dc.b    0            ;Main task done sigbit
  230.         even
  231. maestbase    dc.l    0            ;^Maestix Lib Base
  232. intuibase    dc.l    0            ;^Intuition Lib Base
  233. dosbase        dc.l    0            ;^DOS Lib Base
  234. maestro        dc.l    0            ;^Maestro Base
  235. tport        dc.l    0            ;^Transmit MsgPort
  236. buffer        dc.l    0            ;^Data buffer
  237. window        dc.l    0            ;^Window structure
  238. msg1        ds.b    dmn_SIZEOF        ;^first message
  239. msg2        ds.b    dmn_SIZEOF        ;^second message
  240.  
  241. modustags    dc.l    MTAG_Output,OUTPUT_FIFO    ;FIFO -> Output
  242.         dc.l    MTAG_Input,INPUT_SRC48K    ;constant 48kHz rate
  243.         dc.l    MTAG_CopyProh,CPROH_OFF    ;no copy protection
  244.         dc.l    MTAG_Emphasis,EMPH_OFF    ;no emphasis
  245.         dc.l    MTAG_Source,SRC_DAT    ;source is DAT
  246.         dc.l    MTAG_Rate,RATE_48000    ;rate is 48 kHz
  247.         dc.l    TAG_DONE
  248.  
  249. tasktags    dc.l    NP_Entry,SineProc    ;<- New process' tags
  250.         dc.l    NP_Priority,25
  251.         dc.l    NP_Name,.name
  252.         dc.l    TAG_DONE
  253. .name        dc.b    "Maestix output process",0
  254.         even
  255.  
  256. windowtags    dc.l    WA_IDCMP,IDCMP_CLOSEWINDOW ;<- New window's tags
  257.         dc.l    WA_Title,.title
  258.         dc.l    WA_InnerWidth,100
  259.         dc.l    WA_InnerHeight,0
  260.         dc.l    WA_DragBar,-1
  261.         dc.l    WA_DepthGadget,-1
  262.         dc.l    WA_CloseGadget,-1
  263.         dc.l    WA_Activate,-1
  264.         dc.l    WA_RMBTrap,-1
  265.         dc.l    TAG_DONE
  266. .title        dc.b    "Sine Output",0
  267.         even
  268.  
  269. maestname    dc.b    "maestix.library",0    ;Maestix name
  270. intuiname    dc.b    "intuition.library",0    ;Intuition name
  271. dosname        dc.b    "dos.library",0        ;DOS name
  272.         even
  273.  
  274.     ;-- output sine table ------------------;
  275. sintab        dc.w    00000,06393,12540,18205
  276.         dc.w    23170,27246,30274,32138
  277.         dc.w    32767,32138,30274,27246
  278.         dc.w    23170,18205,12540,06393
  279.         dc.w    000000,-06393,-12540,-18205
  280.         dc.w    -23170,-27246,-30274,-32138
  281.         dc.w    -32768,-32138,-30274,-27246
  282.         dc.w    -23170,-18205,-12540,-06393
  283.  
  284. *---------------------------------------------------------------*
  285. *    == END ==                        *
  286. *                                *
  287.         END
  288.