[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Sound Mixing

Wow is it possible to mix for example 2 wave files (or .raw's, I mean that sort things that the Soundcard mixer normally does).
Does anyone have a source sample or a Component (with source)?

Shellmen
0
Shellman
Asked:
Shellman
1 Solution
 
rwilson032697Commented:
Here's a sample from my PAQs: (Credit to Kretschmar...) This is for playing them.

TWaveMix can be downloaded from:

ftp://carlos.123webhosting.net/pub/dwavemix.zip

unit dwave_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,
  //Add additional in the uses clause
  WaveMix, mmsystem;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    Procedure MyWaveNotify(var Msg : TMessage); Message MM_WOM_DONE;
    { Private-Deklarationen }
  public
    WaveMix1: TWaveMix; //Do not use the icon from the componentpalette
    w : array[0..3] of PMixWave;
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Procedure TForm1.MyWaveNotify(var Msg : TMessage);
var
  PMW : PMixWave;
begin
  PMW := Pointer(Msg.LParam);
  Memo1.Lines.Add('Wave ended - Channel '+IntToStr(msg.wParam)+' - '+
                  StrPas(@PMW^.szWaveFilename[0]));
  //now you can do something with this infos
end;


procedure TForm1.FormCreate(Sender: TObject);
Var MC : TMixConfig;
begin
  //Create and configure
  MC.dwFlags := 0;
  MC.wChannels := 2;       //Stereo
  MC.wSamplingRate := 44;  //44 khz
  MC.wSize := SizeOf(MC);
  WaveMix1 := TWaveMix.CreateConfigured(Self,MC);
  WaveMix1.Channels := 15; //4 Channels
  WaveMix1.Activated := True;  //Activate
  //Load WaveFiles
  w[0] := WaveMix1.OpenFromFile('1.wav');
  w[1] := WaveMix1.OpenFromFile('2.wav');
  w[2] := WaveMix1.OpenFromFile('3.wav');
  w[3] := WaveMix1.OpenFromFile('4.wav');
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
  WaveMix1.Close(w[3]);
  WaveMix1.Close(w[2]);
  WaveMix1.Close(w[1]);
  WaveMix1.Close(w[0]);
  WaveMix1.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  WaveMix1.Play(0,w[0],self,0,0);  //mix together with other channels
//  WaveMix1.Play(0,w[0],self,WMIX_QUEUEWAVE,0);  //wait until previous channel is ready
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  WaveMix1.Play(1,w[1],self,0,0);  //self means the message is sent to the form
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  WaveMix1.Play(2,w[2],self,0,0);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  WaveMix1.Play(3,w[3],self,0,0);
end;

end.
0
 
nricoCommented:
You can *also* get DelphiX (go to delphi.about.com to find a link to the DelhpiX pages) and use DirectSound. That way, your sound will get mixed with other applications as well.
0
 
rwilson032697Commented:
<Lock!>
0
 
IndefreiCommented:
Hi, just a note
I remember meikls source very well cause he made it for me half a year ago.
that time i tried to use dwavemix.
But very early you could see
the sound is not safe !
it's disturbed by to many windows operations, even by the upcoming screensaver (  or picture transitions for instance)

So i changed to directsound ( can also be found on carlos site up above)
It's much better. but there is one bad thing with it :
after 40 - 50 waves loaded into the soundbuffer, the quality becomes
a bit squeaky
so you better free the directsoundbuffer and
create the tdirectsound again for further good wavequality
after let's say every 30 played waves in one channel
good luck
Indi
0
 
ShellmanAuthor Commented:
Works very fine. Thank you.
I know it is possible to mix sounds with directx. But I didn't want to use DX (I know DX a bit, I do also know DirectDelphi / DelphiX / all the other packages, and I do also know it is really easy to mix two (or more) sounds with DSound), because I thougth, it would have been too much work for my little project. AFAIK the DX packages for delphi are quite slow, because they are (and must be, cause they are packages :-P) too generic.

Finally this sample does everything I want and I've got a source to read, so im happy :o)

Shellman
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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