Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > Multiple synchronous tones via sound card


Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2004, 08:38 PM
HyperHacker HyperHacker is offline
Regular
 
Join Date: Oct 2004
Location: Ontario, Canada (w00t)
Posts: 58
Question Multiple synchronous tones via sound card


I'm trying to write a simple sound engine, and it needs to be able to play tones of a specific frequency and duration. I know the API function Beep() can do this but it has three problems:
1) The program halts until the tone is done.
2) It uses the PC speaker instead of the sound card.
3) Only one tone can be played at a time, even if called by two separate programs.

I need a way to play up to four different tones at once, through the sound card, without pausing the program. (No, I can't just use WAVs. The tones are generated on the fly.) I have looked at DirectSound but could not find such a function, plus I have seen this done without DirectX installed. How can I do this?
__________________
'Zig' bus lines. Moving for great justice since AD 2101.
Why software patents are really really bad and what you can do about it

Last edited by HyperHacker; 10-03-2004 at 08:39 PM. Reason: Messed up title. ^_^;;
Reply With Quote
  #2  
Old 10-04-2004, 04:58 AM
Jonny's Avatar
Jonny Jonny is offline
Senior Contributor
 
Join Date: Jun 2003
Location: Birmingham, England, UK
Posts: 821
Default

are you basically trying to play MIDI...there is an example here.
__________________
Regards
John, jlsd.co.uk
Reply With Quote
  #3  
Old 10-04-2004, 08:28 AM
HyperHacker HyperHacker is offline
Regular
 
Join Date: Oct 2004
Location: Ontario, Canada (w00t)
Posts: 58
Default

Similar to MIDI, but using tones rather than instruments. (IE, instead of saying 'piano, middle C, 1sec', it would be more like '1000hz, 1 sec' or whatever frequency.)
Reply With Quote
  #4  
Old 10-04-2004, 11:30 AM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

Fill a directsound buffer yourself with the correct sine wave for the frequency you wish to render (alternately you can also generate a .wav file in memory and use api wave playing facilities)

Generating a single 16-bit sample:

Dim Sample As Integer

Sample = 32767 * Sin(2 * Pi * theta)

where theta is derived from:

the playback sampling rate (usualy 44.1khz or 48khz)
the desired tone frequency
and the time the sample will be played

basically,

theta = T * Frequency / SampleRate

where T is the 'time' which is just the sample number (first sample = 0, second = 1, third = 2, and so on...)

For 2 seconds of sound, you generate 2 * SampleRate samples
Reply With Quote
  #5  
Old 10-04-2004, 08:03 PM
HyperHacker HyperHacker is offline
Regular
 
Join Date: Oct 2004
Location: Ontario, Canada (w00t)
Posts: 58
Question

Alright, that worked good, but when I try to use the .GetVolume() function, I get automation errors, and when I try to use .SetVolume() I get 'Invalid Procedure Call or Argument' no matter what I pass to it. I need one sound to be significantly louder than the other, or they sound distorted. O_o What's the proper way to set the volume? (I'm pretty new to DirectX. Never really used it before.)
__________________
'Zig' bus lines. Moving for great justice since AD 2101.
Why software patents are really really bad and what you can do about it
Reply With Quote
  #6  
Old 10-05-2004, 11:15 AM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

I'd suggest just setting the volume at the time of generating the sine wave.. change the 32767 constant to something smaller (16384 for 50% volume)

Its the simplest solution. I have no idea why you are having problems with the volume settings...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->