Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,167 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,882 people online right now. Registration is fast and FREE... Join Now!




Generating a sound of a specific frequency?

 
Reply to this topicStart new topic

Generating a sound of a specific frequency?

molisoft
5 Jan, 2008 - 04:12 AM
Post #1

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 5

Hey,

I wanna generate sound of a specific frequency in Assembly e.g. when I press A the speaker generates sound of 400Hz.

Thanks for your help.
User is offlineProfile CardPM
+Quote Post

Jingle
RE: Generating A Sound Of A Specific Frequency?
5 Jan, 2008 - 01:14 PM
Post #2

D.I.C Head
**

Joined: 20 Oct, 2007
Posts: 249


My Contributions
couldn't you record the sound then play it back?
User is offlineProfile CardPM
+Quote Post

molisoft
RE: Generating A Sound Of A Specific Frequency?
6 Jan, 2008 - 04:25 AM
Post #3

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 5

it's better not it to be like this...
but if there is no other way how I can play a recorded sound.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Generating A Sound Of A Specific Frequency?
6 Jan, 2008 - 04:05 PM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
I think turning it on and off really fast, you can create specific frequencies, but I'm not really sure about this.
User is offlineProfile CardPM
+Quote Post

molisoft
RE: Generating A Sound Of A Specific Frequency?
9 Jan, 2008 - 03:53 AM
Post #5

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 5

I asked someone and he suggested me the same thing...well, how can I do it?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Generating A Sound Of A Specific Frequency?
9 Jan, 2008 - 05:20 AM
Post #6

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
Google is your friend, but this page seems to contain all the information necessary.
User is offlineProfile CardPM
+Quote Post

molisoft
RE: Generating A Sound Of A Specific Frequency?
9 Jan, 2008 - 06:09 AM
Post #7

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 5

how can I do that in assembly?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Generating A Sound Of A Specific Frequency?
9 Jan, 2008 - 08:11 AM
Post #8

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
How much do you know about assembly? I think with the above link it should be pretty easy to write even if you only know the fundamentals. However if you don't know assembly, then first get a tutorial on it.
Here we won't do your homework or give you complete solutions (read the forum rules), but if you have any problems or need pointers, don't hesitate to ask!
User is offlineProfile CardPM
+Quote Post

molisoft
RE: Generating A Sound Of A Specific Frequency?
12 Jan, 2008 - 05:25 AM
Post #9

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 5

I know the rules and that you don't give the complete solution. I have found a way to send signal to 61H,43H and 42H and defining the desired frequency but I'm not sure it is giving me the frequency correctly because I saw in some sites that it had done many calculations before setting the frequency...
well, I can send u the code and u check it for me, thanks.

CODE

        .model small
        .stack 32
        .data  
        freq dw ?
        .code

;The macro which generates the sound of specific frequency.
sound   proc                   ;freq is the frequency

which is gonna be generated.        

        mov     al,0b6h        ;load control word
        out     43h,al         ;send it
    
        mov     ax,freq        ;tone frequency into AX
        out     42h,al         ;send LSB
        mov     al,ah          ;move MSB to AL
        out     42h,al         ;send it
    
        in      al,61h         ;get port 61 state
        or      al,03h         ;turn on speaker
        out     61h,al         ;speaker on now
        mov     bx, 3000
pause3: mov     cx, 65535
pause4: dec     cx
        jne     pause4
        dec     bx
        jne     pause3
        
        in      al,61h        ;get port 61 state        

        
        and     al,0fch        ;turn off speaker
        out     61h,al        ;speaker off now
sound    endp
        
main    proc far
        mov ax,@data
        mov ds,ax
        
next:    mov ah,07
        int 21h

        cmp al,'a'
        je  beepA
        cmp al,'A'
        je  beepA

        cmp al,'s'
        je  beepS
        cmp al,'S'
        je  beepS

        cmp al,'d'
        je  beepD
        cmp al,'D'
        je  beepD

        cmp al,'f'
        je  beepF
        cmp al,'F'
        je  beepF

        cmp al,'g'
        je  beepG
        cmp al,'G'
        je  beepG
        
        cmp al,'h'
        je  beepH
        cmp al,'H'
        je  beepH

        cmp al,'j'
        je  beepJ
        cmp al,'J'
        je  beepJ

        cmp al,'k'
        je  beepK
        cmp al,'K'
        je  beepK    

        cmp al,27
        je exit    

        jmp exit

beepA:  mov freq,400
        call sound
        jmp next        
beepS:  mov freq,450
        call sound
        jmp next
beepD:  mov freq,506
        call sound
        jmp next
beepF:  mov freq,537
        call sound
        jmp next
beepG:  mov freq,604
        call sound
        jmp next
beepH:  mov freq,679
        call sound
        jmp next
beepJ:  mov freq,763
        call sound
        jmp next
beepK:  mov freq,810
        call sound
        jmp next
        
exit:   mov ah,4ch
        int 21h
main    endp
end     main

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:20AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month