473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB Code for playing two audio files at the same time

I would like someone to help me with VB code for the following problem.

I want to play a composed audio file of a certain beat cycle. A metronome file corresponding to the audio file beat cycle is also to be played in the background so that the user gets a feel for the synchronization.

The user should be able to fully control the start, stop, volume, and tempo variation of each of the two audio files individually.

Thanks in advance.

gskrishnan.
Jan 31 '08 #1
2 5030
Robbie
180 100+
The FMOD music and sound effects system can do this (and much more). It's a really great combination of DLL and programming language code (including VB 6 modules) which I recommend to anyone trying to do anything with sound more than just play a single simple sound. The enourmous number of sound formats it supports is great too (the most notable probably being WAV, MP3, WMA, OGG and even tracker music files such as IT). If that hasn't convinced you of its awesomeness, then it can even play streaming files in realtime across the internet and give you access to sound spectrums of the playing sound(s).
EDIT: I just realized how much this makes me sound like I'm part of the FMOD team trying to promote their product, haha... I'm not. >_<

Sounds are played on channels (1 sound on 1 channel, but you can group channels into 'channel groups').
To apply an effect to a playing channel (or channel group) then you connect a DSP to it. There is no DSP for slowing down or speeding up the audio. However, you can set the playback speed (sampling rate) of the playing channel to lower than normal and use a DSP for pitch-shifting to make the pitch higher to counteract the pitch-decreasing caused by the lower sample rate. So in other words, it would be at the original pitch, just slower. This would almost certainly not sound very good quality though. If you're not worried about the pitch being changed with the tempo, just change the sampling rate of the channel without the pitch-shifting DSP and there won't be a loss in quality.

I've never done this, but it sounds very interesting to me, and I'd like to make a working example, if only for myself. I'll release it here though, but it will be a lot of code (I'll try to comment it well). It will probably take a few hours, but please bear with me. ;)
I know I'll have to.

EDIT 2: Note that if you're planning to go shareware or commercial, their licenses are very expensive. But when you realize all that's packed into FMOD, it is a justifiable price.
Jan 31 '08 #2
Robbie
180 100+
DONE! :D
It took just about exactly 4 hours to make.

You control for each sound the volume and frequency (speed), stop and start.
For the music (not metronome) you also can make it not affect the pitch, while only changing the speed (tempo). Note that that adds a slight delay to the music though.
You can also start and stop both (metronome and music) at the same time.

http://robbi-985.homeip.net:8000/hos..._Metronome.zip
EDIT: I think there's a bug in the forum software. It keeps turning "http://site" into "http:// http//site", so the link doesn't work. But it seems to work now.
(Sorry about the slow download speed)

The download includes the DLL of the needed version for my program, and 2 little audio files I made for trying it out, which the program will try to load when run. In other words, as long as you extract everything to the same directory, open the project and then save over the file you just opened (sometimes needed to make VB realize the working path), it should all work. Note that the metronome sound I provided is exactly half the length of the music sound (right down to the number of samples), so they should never get out of sync if left playing at the same speed. The metronome sound was made with Audacity (freeware, open-source) and the beatbox rhythm using MAGIX Music Maker Gen.6.

Much more info throughout the comments of the VB project. ;)

IMPORTANT: While debugging your program which uses FMOD, do not stop the program (once FMOD's been initialized) using VB's Stop button - VB will crash (you could lose your changed work)! Always exit the program using its top-right Close button, which will execute CloseSystem before exitting to exit safely. If that's not possible, type DoShutDownStuff in the immediate window, which will execute CloseSystem followed by End to exit the program without crashing VB.
Feb 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: SOB-like MIDIs | last post by:
The applet for endlessly rising/falling scale (auditory illusion) on this page is fantastic! http://www.cs.ubc.ca/nest/imager/contributions/flinn/Illusions/ST/st.html How is this done?...
5
by: Lauren Wilson | last post by:
Hi Folks, I have an Access 2k app that is often run on a LAN with several users. Unfortunately there is one feature that fails to work in that setup. Our app allows the user to play WAV audio...
7
by: Lee Moody | last post by:
I just want quick and easy way to play a .wav file out the standard sound device. It could even be as simple as activating a sound assigned to an existing windows sound event. Any suggestions?...
1
by: Terry Olsen | last post by:
Using the following routine to play embedded wav files: Private Sub PlaySound(ByVal Sound As Int32) Select Case Sound Case 1 : My.Computer.Audio.Play(My.Resources.Sounds.GoOnline,...
0
by: Mark Rae | last post by:
Hi, Can anyone recommend a good technique, or point me at a good 3rd party utility, which will play media files on ASP.NET 2 pages? Typically, the audio files will be MP3s and the videos will be...
2
by: =?Utf-8?B?ZGF2ZS5oYXJkeQ==?= | last post by:
Hi, there have been loads of posts about this problem on loads of forums and I have tried everything suggested (except the stuff I’m not comfortable with like deleting drivers and reg. edits). ...
1
by: poo22 | last post by:
Please help, i've looked everywhere on the internet for the answer, but nothing works! here is my problem: I have a Pong game, and would like to have a background .wav file playing. I also have...
0
by: Juanma1 | last post by:
My program is supposed to play a wav file of a ticking clock using the media player object so that only after the file is over (this is to build tension), some textboxes are populated with data...
1
by: Sobin Thomas | last post by:
Hi All, I want to play an audio file (wav)in my web page.I used the embed tag method.But it does'n work well in firefox.Is there any .NET class to play audio files?I already tried soundpalyer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.