News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

musical rhythms

Started by shankle, December 19, 2004, 03:30:49 PM

Previous topic - Next topic

shankle

My latest attempt with  the MIDI fiasco is below.
It is a lot better than my previous attempt but NOT perfect.

Your comments would be most appreciated.
Regards,
JPS


; test of note time duration
; 12-19-04

.data
tc          dd      dword
notes       dd    007f4890h,007f4a90h,007f4890h,007f4390h,007f4890h,007f4a90h,
                  007f4890h,007f4790h,007f4890h,007f4a90h,007f4890h

duration    dd    00000320h,00000320h,00000320h,00000320h,000000c8h,000000c8h,
                  000000c8h,000000c8h,00000190h,00000190h,00000640h
                       
.data?
hInstance   dd        ?
lphmo       HANDLE    ?

    .code
PlayNotes proc notex:dword, durationx:dword, NbrNotes:dword
         invoke midiOutOpen, offset lphmo, -1, NULL, 0, CALLBACK_NULL
      ; ecx points to notes
      ; edx points to duration
         push esi
         xor esi, esi
         mov ecx, notex
         mov edx, durationx
         .WHILE esi < NbrNotes   
           push esi
           push ecx
           push edx
           invoke midiOutShortMsg, lphmo, dword ptr[ecx]     ; varying notes
           pop edx
           pop ecx
           push ecx
           push edx
           invoke timeBeginPeriod, 1  ; wait for time interval of note           
           pop edx
           pop ecx
           push ecx
           push edx           
           invoke timeGetTime       ; get a time reference
           pop edx
           pop ecx
           mov tc, eax
           mov eax, [edx]
           add tc, eax
TimeCount:
           push ecx
           push edx
           invoke timeGetTime
           pop edx
           pop ecx
           .if tc > eax
             jmp TimeCount
           .endif
           push ecx
           push edx
           invoke timeEndPeriod, 1           
           pop edx
           pop ecx
           push ecx
           push edx
           invoke midiOutReset, lphmo
           pop edx
           pop ecx           
           add ecx, 4     ; next note array value
           add edx, 4     ; next duration array value
           pop esi
           inc esi         
         .ENDW
         pop esi
         invoke midiOutClose, lphmo         
        ret
PlayNotes endp         






The greatest crime in my country is our Congress

pbrennick

I tried writing a wrapper to test it but failed miserably.
Paul

Kayaker

Heheh, actually it seems to work pretty well. Chances are you may need to set your speaker volume WAY up to hear the code in action. You can change midi volume dynamically with midiOutShortMsg, but I find that's still too low for my default speaker volume.

Nice one Shankle, I don't really have any comments on the code, other than it works and the timing seemed OK. In my app code I can change instruments via a listbox to any supported, and your tune played fine with the new sound setting. Just an example of using this (or other) midi message:

; MsgInstrument      dd 000012C0h   ; Program Change
invoke midiOutShortMsg, lphmo, MsgInstrument   ; Program change

Cheers,
Kayaker