<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mehrere Sounds gleichzeitig abspielen]]></title><description><![CDATA[<p>Wie kann ich mehrere Sounds gleichzeitig abspielen lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/158262/mehrere-sounds-gleichzeitig-abspielen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 16:50:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/158262.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 03 Sep 2006 16:40:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mehrere Sounds gleichzeitig abspielen on Sun, 03 Sep 2006 16:40:28 GMT]]></title><description><![CDATA[<p>Wie kann ich mehrere Sounds gleichzeitig abspielen lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130278</guid><dc:creator><![CDATA[Jakel]]></dc:creator><pubDate>Sun, 03 Sep 2006 16:40:28 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Sounds gleichzeitig abspielen on Sun, 03 Sep 2006 18:36:39 GMT]]></title><description><![CDATA[<p>sndPlaySound() mit dem Flag SND_ASYNC sollte dir weiterhelfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1130363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1130363</guid><dc:creator><![CDATA[Jansen]]></dc:creator><pubDate>Sun, 03 Sep 2006 18:36:39 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Sounds gleichzeitig abspielen on Tue, 05 Sep 2006 16:55:51 GMT]]></title><description><![CDATA[<p>Nein!<br />
Wenn da mehrere abgespielt werden wird der andere automatisch unterbrochen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1131708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1131708</guid><dc:creator><![CDATA[Jakel]]></dc:creator><pubDate>Tue, 05 Sep 2006 16:55:51 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Sounds gleichzeitig abspielen on Tue, 05 Sep 2006 22:30:26 GMT]]></title><description><![CDATA[<p>Hallo Jakel<br />
Dann benutze doch DirectX für totale Sound-Kontrolle.<br />
Sieht zwar im ersten Moment nach viel Arbeit aus aber wenn Du auf diesem Code aufbaust, ist es ganz einfach.<br />
Auf dem Form befinden sich nur zwei TButton und du brauchst natürlich auch 2 Sounds. Die dsound.lib muss im &quot;Borland\CBuilder5\Lib&quot; - Verzeichnis sein.<br />
Ggf. von &quot;Borland\CBuilder5\Lib\PSDK\&quot; rüber-kopieren !!!<br />
Schaue dir mal besonders die Zeilen 115 und 116 an:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#include &lt;dsound.h&gt;
#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
#define DSBCAPS_CTRLDEFAULT (DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME)
LPDIRECTSOUND dsound;
LPDIRECTSOUNDBUFFER Wave[3];  // 3=Anzahl der Sounds
HWND hWnd;

TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void Play_WAV(int snr, unsigned long freq, long vol)
{
	DWORD WaveStatus;
        Wave[snr]-&gt;GetStatus(&amp;WaveStatus);
        Wave[snr]-&gt;Stop();
        Wave[snr]-&gt;SetCurrentPosition(0);
        Wave[snr]-&gt;Play(0,0,0);
        Wave[snr]-&gt;SetFrequency(freq);
        Wave[snr]-&gt;SetVolume(vol);
}//PLAYWAV

void Error(char* message)
{
	//a function to help me display errors and why
	MessageBox(hWnd,message,&quot;Fehler!&quot;,MB_OK);
	exit(-1);
}

void InitDirectSound()
{
	//get directsound interface
	if(DS_OK != DirectSoundCreate(NULL,&amp;dsound,NULL))
		Error(&quot;InitDirectSound DirectSoundCreate&quot;);

	//setcooperativelevel of interface
	if(DS_OK != dsound-&gt;SetCooperativeLevel(hWnd,DSSCL_PRIORITY))
		Error(&quot;InitDirectSound SetCooperativeLevel&quot;);
}

void LoadDirectSound(LPDIRECTSOUNDBUFFER *buffer,char* filename)
{
	//open a wav file
	HMMIO wavefile;
	wavefile = mmioOpen(filename,0,MMIO_READ|MMIO_ALLOCBUF);
	if(wavefile==NULL)
		Error(&quot;LoadDirectSound mmioOpen&quot;);

	//find wave data
	MMCKINFO parent;
	memset(&amp;parent,0,sizeof(MMCKINFO));
	parent.fccType = mmioFOURCC('W','A','V','E');
	mmioDescend(wavefile,&amp;parent,0,MMIO_FINDRIFF);

	//find fmt data
	MMCKINFO child;
	memset(&amp;child,0,sizeof(MMCKINFO));
	child.fccType = mmioFOURCC('f','m','t',' ');
	mmioDescend(wavefile,&amp;child,&amp;parent,0);

	//read the format
	WAVEFORMATEX wavefmt;
//*******************************************
        wavefmt.nSamplesPerSec=44100;
        wavefmt.nChannels=2;
        wavefmt.wBitsPerSample=16;
        wavefmt.nBlockAlign=4;          //2*16/8
        wavefmt.nAvgBytesPerSec=176400; //44100*4
//*******************************************
        mmioRead(wavefile,(char*)&amp;wavefmt,sizeof(wavefmt));
	if(wavefmt.wFormatTag != WAVE_FORMAT_PCM)
		Error(&quot;LoadDirectSound mmioRead&quot;);

	//find the wave data chunk
	mmioAscend(wavefile,&amp;child,0);
	child.ckid = mmioFOURCC('d','a','t','a');
	mmioDescend(wavefile,&amp;child,&amp;parent,MMIO_FINDCHUNK);

	//create a directsound buffer to hold wave data
	DSBUFFERDESC bufdesc;
	memset(&amp;bufdesc,0,sizeof(DSBUFFERDESC));
	bufdesc.dwSize = sizeof(DSBUFFERDESC);
	bufdesc.dwFlags = DSBCAPS_CTRLDEFAULT;
	bufdesc.dwBufferBytes = child.cksize;
	bufdesc.lpwfxFormat = &amp;wavefmt;
	if(DS_OK != (dsound-&gt;CreateSoundBuffer(&amp;bufdesc,&amp;(*buffer),NULL)))
		Error(&quot;LoadDirectSound CreateSoundBuffer&quot;);

	//write wave data to directsound buffer you just created
	void *write1=0,*write2=0;
	unsigned long length1,length2;
	(*buffer)-&gt;Lock(0,child.cksize,&amp;write1,&amp;length1,&amp;write2,&amp;length2,0);
	if(write1&gt;0)
		mmioRead(wavefile,(char*)write1,length1);
	if(write2&gt;0)
		mmioRead(wavefile,(char*)write2,length2);
	(*buffer)-&gt;Unlock(write1,length1,write2,length2);

	//close the wavefile, don't need it anymore, it's in the directsound buffer now
	mmioClose(wavefile,0);
}

void Game_Init(void)
{
       LoadDirectSound(&amp;Wave[1],&quot;MeinSound_01.wav&quot;);
       LoadDirectSound(&amp;Wave[2],&quot;MeinSound_02.wav&quot;);
}

void Speicher_freigeben(void)
{
		Wave[1]-&gt;Release();
		Wave[1]=NULL;

    		Wave[2]-&gt;Release();
    		Wave[2]=NULL;

    //		Wave[3]-&gt;Release();
    //		Wave[3]=NULL;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Play_WAV(1,10000,-100);      //Frequenz(0 bis 100000),Volume(0 bis -10000)
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Play_WAV(2,10000,-100);      //Frequenz(0 bis 100000),Volume(0 bis -10000)
}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
hWnd=Form1-&gt;Handle;
InitDirectSound(); // DirectSound Initialisieren
Game_Init();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &amp;Action)
{
Speicher_freigeben();
}
//---------------------------------------------------------------------------
</code></pre>
<p>Hiermit lassen sich auf jeden Fall mehrere (wieviele eigentlich?) Sounds parallel abspielen.</p>
<p>Hoffe das hilft.</p>
<p>Bis Bald...<br />
wNw</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1131914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1131914</guid><dc:creator><![CDATA[wNw]]></dc:creator><pubDate>Tue, 05 Sep 2006 22:30:26 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Sounds gleichzeitig abspielen on Tue, 05 Sep 2006 22:39:14 GMT]]></title><description><![CDATA[<p>Sorry, und natürlich bitte Zeilen 134 und 139 beachten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1131917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1131917</guid><dc:creator><![CDATA[wNw]]></dc:creator><pubDate>Tue, 05 Sep 2006 22:39:14 GMT</pubDate></item></channel></rss>