Solved

Mixing Wav's Component (2 channels !!)

Posted on 1998-08-02
6
309 Views
Last Modified: 2010-04-03
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
Comment
Question by:roosiedb
  • 2
  • 2
  • 2
6 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1359530
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359531
Hi roosiedb, the latest version of this component is v2.0, maybe it's renewed? Zif.
0
 

Author Comment

by:roosiedb
ID: 1359532
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Matvey
ID: 1359533
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
 

Author Comment

by:roosiedb
ID: 1359534
I'm sorry, it has to be in Delphi because I don't understand C or C++ at all.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1359535
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Memory leak using records in a TVirtualStringTree 11 108
Delphi with SQL Natvie Client 15 85
loading dll from external path 1 209
delphi custom sort exception 6 131
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now