Board index » cppbuilder » Play Sound

Play Sound


2006-01-03 04:09:17 AM
cppbuilder16
Hi
I want to know how could I play a Sound from PC internal Speaker or sound
cart speakers by both C++ and Assembly.
In this case, I should mailnly program in C++ but I have to use assembly
interrupts for making a sound from speaker.
I know I must use the keyword : asm, but I'm wondering about its INT # and
also codes of sound frequency...
Anyway, Any help about solving this kind of problem is useful to me
please write me, thanks
 
 

Re:Play Sound

Pedram wrote:
Quote
I want to know how could I play a Sound from PC internal Speaker or
sound cart speakers by both C++ and Assembly.
In this case, I should mailnly program in C++ but I have to use
assembly interrupts for making a sound from speaker.
I know I must use the keyword : asm, but I'm wondering about its INT
# and also codes of sound frequency...
If you are using the VCL, go to torry.net and get a component from
there that does it for you.
Jonathan
jomitech.com/mtbcc32.shtml - Multi-threaded compilation for BCB
jomitech.com/forum - JomiTech Forums
 

Re:Play Sound

"Pedram" < XXXX@XXXXX.COM >wrote in message
Quote
I want to know how could I play a Sound from PC internal Speaker
or sound cart speakers by both C++ and Assembly. In this case, I
should mailnly program in C++ but I have to use assembly interrupts
for making a sound from speaker. I know I must use the keyword : asm,
but I'm wondering about its INT # and also codes of sound frequency...
Under NT-based systems (NT4, 2000, Xp, 2003, Vista), you don't need any
assembly (especially since you cannot access the hardware directly anyway).
You can use the Win32 API Beep() function. It has Frequency and Duration
parameters.
Under 9x/Me systems, Beep() also has such parameters, but they do not
actually do anything. Fortunately, the hardware can be accessed directly
using assembly.
Have a look at the following code snippets for custom Beep() implementations
that work on all systems:
groups.google.com/group/borland.public.cppbuilder.winapi/msg/e70534c4c7606825
groups.google.com/group/borland.public.cppbuilder.nativeapi/msg/b918707fc590a218&
Gambit
 

{smallsort}

Re:Play Sound

Pedram wrote:
Quote
I'm wondering about its INT # and
also codes of sound frequency...
For a list of all Interrupts and options, see
Ralph Brown's Interrupt List:
www-2.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html
Or in HTML (I found this dificult to use)
www.ctyme.com/rbrown.htm
 

Re:Play Sound

At 21:09:17, 02.01.2006, Pedram wrote:
Quote
Hi
I want to know how could I play a Sound from PC internal Speaker or
sound cart speakers by both C++ and Assembly.
From my Console unit (well, it is Delphi, but the principle is the same,
and it was modified a bit):
procedure Sound(Frequency: Smallint; Duration: Integer);
var
Count: Word;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
Windows.Beep(Frequency, Duration);
else
begin
Count := 1193280 div Frequency;
asm
MOV AL,$B6
OUT $43,AL
MOV AX,Count
OUT $42,AL
MOV AL,AH
OUT $42,AL
MOV AL,3
OUT $61,AL
MOV EAX,Duration
PUSH EAX
CALL Sleep
MOV AL,0
OUT $61,AL
end;
end;
--
Rudy Velthuis [TeamB] rvelthuis.de/
"There is a country in Europe where multiple-choice tests are illegal."
-- Sigfried Hulzer
 

Re:Play Sound

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
From my Console unit (well, it is Delphi, but the principle
is the same, and it was modified a bit):
Translated to C++:
void __fastcall Sound(WORD Frequency, DWORD Duration)
{
if( Win32Platform == VER_PLATFORM_WIN32_NT )
::Beep(Frequency, Duration);
else
{
WORD Count = (1193280 / Frequency);
asm
{
MOV AL, 0xB6
OUT 0x43, AL
MOV AX, Count
OUT 0x42, AL
MOV AL, AH
OUT 0x42, AL
MOV AL, 3
OUT 0x61, AL
MOV EAX, Duration
PUSH EAX
CALL Sleep
MOV AL, 0
OUT 0x61, AL
}
}
}
Gambit
 

Re:Play Sound

At 19:31:38, 03.01.2006, Remy Lebeau (TeamB) wrote:
Quote

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
news:xn0egsvxujwrc8e008-velthuis@www.teamb.com...

>From my Console unit (well, it is Delphi, but the principle
>is the same, and it was modified a bit):

Translated to C++:

void __fastcall Sound(WORD Frequency, DWORD Duration)
{
if( Win32Platform == VER_PLATFORM_WIN32_NT )
::Beep(Frequency, Duration);
else
{
WORD Count = (1193280 / Frequency);
asm
{
MOV AL, 0xB6
OUT 0x43, AL
MOV AX, Count
OUT 0x42, AL
MOV AL, AH
OUT 0x42, AL
MOV AL, 3
OUT 0x61, AL
MOV EAX, Duration
PUSH EAX
CALL Sleep
MOV AL, 0
OUT 0x61, AL
}
}
}


Gambit
Thanks!
--
Rudy Velthuis [TeamB] rvelthuis.de/
"When you hear hoofbeats, think of horses, not zebras."
-- Old saying
 

Re:Play Sound

Rudy Velthuis [TeamB] wrote:
Quote
Thanks!

Oh, Rudy...
 

Re:Play Sound

At 19:43:48, 03.01.2006, Alex Bakaev [TeamB] wrote:
Quote
Rudy Velthuis [TeamB] wrote:

>Thanks!
>

Oh, Rudy...
<sigh>I was just about to cancel it.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"Victory goes to the player who makes the next-to-last mistake."
-- Chessmaster Savielly Grigorievitch Tartakower (1887-1956)
 

Re:Play Sound

At 19:31:38, 03.01.2006, Remy Lebeau (TeamB) wrote:
Quote
>From my Console unit (well, it is Delphi, but the principle
>is the same, and it was modified a bit):

Translated to C++:

void __fastcall Sound(WORD Frequency, DWORD Duration)
Thanks!
--
Rudy Velthuis [TeamB] rvelthuis.de/
"He has all the virtues I dislike and none of the vices I admire."
-- Sir Winston Churchill (1874-1965)
 

Re:Play Sound

Thanks to friends
and I was also asking another question also...
I am remembering a code that could send the frequence to speakers, not only
internal speaker, the speaker attached to sound cart, ... :-\
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
news:xn0egsvxujwrc8e008-velthuis@www.teamb.com...

>From my Console unit (well, it is Delphi, but the principle
>is the same, and it was modified a bit):

Translated to C++:

void __fastcall Sound(WORD Frequency, DWORD Duration)
{
if( Win32Platform == VER_PLATFORM_WIN32_NT )
::Beep(Frequency, Duration);
else
{
WORD Count = (1193280 / Frequency);
asm
{
MOV AL, 0xB6
OUT 0x43, AL
MOV AX, Count
OUT 0x42, AL
MOV AL, AH
OUT 0x42, AL
MOV AL, 3
OUT 0x61, AL
MOV EAX, Duration
PUSH EAX
CALL Sleep
MOV AL, 0
OUT 0x61, AL
}
}
}


Gambit


 

Re:Play Sound

"Pedram" < XXXX@XXXXX.COM >wrote in message
Quote
I am remembering a code that could send the frequence
to speakers, not only internal speaker, the speaker
attached to sound cart, ... :-\
There are various APIs available for multimedia playback. When dealing with
a sound card, I suggest you use DirectSound, or a WAV or MIDI file, since
all of the hardware acess is done by the OS for you.
Also note that Beep() will go through the sound card if one is present.
Gambit
 

Re:Play Sound

At 20:16:29, 04.01.2006, Remy Lebeau (TeamB) wrote:
Quote
Also note that Beep() will go through the sound card if one is present.
On my main machine, it doesn't. It uses the internal speaker. Ony my
laptop, it seems to use the sound card.
One could of course generate a range of buffers with a waveform with the
desired frequency, and play that using the waveOutXXX APIs. I've written
a simple synth program (including Moog-like filter) that uses that method.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"Sometimes when reading Goethe I have the paralyzing suspicion that he is
trying to be funny."
- Guy Davenport
 

Re:Play Sound

Thanks for your kindly advice but imagine that I'm forcing to use this way
by my team leader...
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Pedram" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I am remembering a code that could send the frequence
>to speakers, not only internal speaker, the speaker
>attached to sound cart, ... :-\

There are various APIs available for multimedia playback. When dealing
with
a sound card, I suggest you use DirectSound, or a WAV or MIDI file, since
all of the hardware acess is done by the OS for you.

Also note that Beep() will go through the sound card if one is present.


Gambit


 

Re:Play Sound

"Pedram" < XXXX@XXXXX.COM >wrote in message
Quote
Thanks for your kindly advice but imagine that I'm forcing
to use this way by my team leader...
So? My earlier statement still applies. When dealing with a sound card,
you really should let the OS access the hardware for you under all OS
versions. What operations you choose to have the OS perform is up to you.
DirectX is specifically designed for multimedia, such as audio. But if you
don't want to use DirectX, then the simpliest way is to record a WAV file
and then use the PlaySound() function. Otherwise, like Rudy mentioned, you
can prepare WAV buffers in your code and then push them out to the sourd
card using the waveOut...() functions.
Gambit