• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Mixing Wav's Component (2 channels !!)

Hello,
I am searching the WEB for a component which can help me by making a project to mix two WAV-files. For example, I have found such a component (Component-name: "Delphi WaveMix v1.21" at http://www.digiserve.com/cmab) for 8 channels, but the sound-quality is too bad, even when I mix only two channels at the same time. Please help me to find such a (free !!) component for only 2 channels with a much better soundquality. Thanx very much!!! These many points (200!!) are only for a really good working component. By the way: I am using Delphi 3.
J.v.Barchum.
0
roosiedb
Asked:
roosiedb
  • 2
  • 2
  • 2
1 Solution
 
MatveyCommented:
0
 
ZifNabCommented:
Hi roosiedb, the latest version of this component is v2.0, maybe it's renewed? Zif.
0
 
roosiedbAuthor Commented:
Both components (dwavemix.zip I allready had found myself, see my question) do not have the quality I want them to have... So that's why I asked for a better component. The components I have found myself have to same quality as a short-wave-radio...!!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MatveyCommented:
I have found sources of a sample module player application. If you can understand how it works (written in C), you will understand how you can play some sounds at the same time.
Leave your email if you want to take a look.
bosism@netvision.net.il
0
 
roosiedbAuthor Commented:
I'm sorry, it has to be in Delphi because I don't understand C or C++ at all.
0
 
ZifNabCommented:
It's in explained in a previous UNDU :

----

Digital Sound in Delphi - Part II

by Stanislav Holenda - texmurphy@email.cz

As I promised in my previous article, I’m back with more Delphi sound stuff. Today we shall look at possibilities of producing multi-channel
sound effects. First of all we should theoretically discuss how to play two samples at one time on one sound device - this bring us to:

Mixing the Samples

Windows has ability to play sounds (I call them samples) by "itself", but when you want to, for example, play digital music together with sound
FX (like clicking sounds on buttons, ...) you have a hard choice - to play music or sounds?

Well if you want to play them both, you’ll have to mix them. Mixing of samples with same sample rate (frequency) is fairly easy - you just have to
calculate average value of their current values:

If you have stored your sample in array like this (let’s assume they are 8-bit mono, <64kB):

     type
       Tsample = array[0..65520] of byte;
     var
       samples : array[1..4] of ^Tsample;

You will mix them like this:

     value:= (samples[1]^[ppos] + samples[2]^[ppos] + samples[3]^[ppos] + samples[4]^[ppos]) div 4;

In the ppos variable is stored the playing position, and the return value is the current value to be send to the DAC. A bit harder is when you must
play sample on different rates (when playing music, you’ll have to play the instrument sample on different rate to create accord, for example) -
you’ll have to choose the mixing rate which will be the frequency of sending data to DAC.

For example: Let’s assume we have mixing rate 11025 Hz (=11025 times per second, we will write to DAC) and want to play one sample on
11025 Hz and second on 22050 Hz. We will take each byte from first sample (play rate/mixing rate = step) and each second byte from second
sample (22050/11025=2) and mix them together and the output will be one sound playing two times faster than another. This is relatively easy to
understand but harder to make a mixing routine that is fast enough to keep up. To make a good mixing routine, you’ll have to think out an
optimized algorithm and write it in assembly language, if you're a tough programmer, or you can use the easy and simple interface of the MIDAS
Digital Sound System.

MIDAS Sound FX engine

I expect you are now either bored or confused from my previous paragraph full of theory and now you'd like to do something easy that works
well... Well here goes a step-by-step sound FX engine guide:

First of all you need to initialize MIDAS (best in the form.create method or in application startup), but slightly different as in previous article:

     midasStartup;
     midasInit;
     MIDASstartBackgroundPlay(100); {this orders MIDAS to poll the buffers 100 times/second}

Second open some channels for sound FX:

     MIDASopenChannels(5); {opens 5 channels}
     MIDASallocAutoEffectChannels(4); {allocates 4 for AUTO_CHANNEL mode (look below)}

Third load samples:

     var sample,sample2:MIDASsample;

     sample:=MIDASloadRawSample('explod11.snd',MIDAS_SAMPLE_8BIT_MONO,MIDAS_LOOP_NO);
     sample2:=MIDASloadWaveSample('laugh1.wav',MIDAS_LOOP_NO);

Fourth play them when you want:

     MIDASplaySample(sample,MIDAS_CHANNEL_AUTO,0,11025,63,MIDAS_PAN_MIDDLE);

'sample' is a variable of type MIDASsample which must point to some data loaded with MIDASloadWave/RawSample function.
MIDAS_CHANNEL_AUTO  commands MIDAS to select some free channel for playing the sample automatically. 0  this number is priority -
higher means higher priority
11025  play rate of sample (=the rate you want to sample at). 63 is the volume, and MIDAS_PAN_MIDDLE is the panning constants - you can
use constants or numbers in range -63..63 for panning from left to right.

Also this usage of PlaySample command will only play it, if you want also control sample properties during playback (rate, volume, panning)
you’ll have to use it like this:

     var laugh_handle:MIDASsamplePlayHandle;
     laugh_handle:=MIDASplaySample(sample2,MIDAS_CHANNEL_AUTO,0,11025,63,MIDAS_PAN_RIGHT);

And then use commands described in MIDAS help under "Controlling sample playback".

Fifth you must deallocate all samples, close sound device, and other stuff when you exit your program:

     MIDASfreeAutoEffectchannels; {deallocate AUTO_CHANNELS}
     MIDASfreeSample(sample); {free memory occupied by samples}
     MIDASfreeSample(sample2);
     {Note: MIDAS may remove samples automatically when midasClose is called, but I’m not sure}

     MIDASstopBackgroundPlay; {stop poll-playing}

     midasClose;

So this would be in brief how to use MIDAS sound mixing capabilities. Next time we might talk about echo-effects and post processor in
MIDAS and also samples & modules type and formats. If anybody got any questions about this article, or other sound-related problems let me
know.

You can get a copy of the source code for my demo application by clicking here, and you can also download the files for a minimal Midas
configuration, by clicking here.

--------

Regards, Zif.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now