By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

VB Code for playing two audio files at the same time

P: 3
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
Share this Question
Share on Google+
2 Replies


Robbie
100+
P: 180
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
100+
P: 180
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

Post your reply

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