Author: nyadav
Date: Thu Jun 9 23:06:06 2011
New Revision: 52167
URL:
http://svn.reactos.org/svn/reactos?rev=52167&view=rev
Log:
[AUDSRV] mixer routine for signed 16 bit data
Modified:
branches/nyadav-audio-branch/base/services/audsrv/audsrv.c
branches/nyadav-audio-branch/base/services/audsrv/audsrv.h
branches/nyadav-audio-branch/base/services/audsrv/mixer.c
branches/nyadav-audio-branch/base/services/audsrv/stream.c
branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c
branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h
Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/audsrv.c [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/audsrv.c [iso-8859-1] Thu Jun 9
23:06:06 2011
@@ -159,7 +159,7 @@
MixAndFill(MixerEngine * mixer,
int buffer)
{
- while(WaitForSingleObject(mixer->streampresent,
+ while(WaitForSingleObject(mixer->newStreamEvent,
100) != 0)
{
if(mixer->dead)
@@ -583,7 +583,7 @@
FALSE,
NULL);
- pengine->streampresent=CreateEvent(NULL,
+ pengine->newStreamEvent=CreateEvent(NULL,
TRUE,
FALSE,
NULL);
@@ -625,7 +625,7 @@
pengine->masterbuf[1] = NULL;
pengine->played=CreateEvent(NULL,FALSE,FALSE,NULL);
pengine->filled=CreateEvent(NULL,FALSE,FALSE,NULL);
- pengine->streampresent=CreateEvent(NULL,TRUE,FALSE,NULL);
+ pengine->newStreamEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
SetConsoleCtrlHandler(Close,TRUE);
SpawnMixerThread(pengine);
SpawnPlayerThread(pengine);
Modified: branches/nyadav-audio-branch/base/services/audsrv/audsrv.h
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/audsrv.h [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/audsrv.h [iso-8859-1] Thu Jun 9
23:06:06 2011
@@ -69,7 +69,7 @@
long streamidpool;
HANDLE played;
HANDLE filled;
- HANDLE streampresent;
+ HANDLE newStreamEvent;
HANDLE mixerthread;
HANDLE playerthread;
HANDLE rpcthread;
Modified: branches/nyadav-audio-branch/base/services/audsrv/mixer.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/mixer.c [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/mixer.c [iso-8859-1] Thu Jun 9
23:06:06 2011
@@ -14,9 +14,58 @@
}
void * MixS16(MixerEngine * mixer,int buffer)
{
- mixer->masterbuf[buffer] = HeapAlloc(GetProcessHeap(), 0,
mixer->serverstreamlist->length_filtered);
+ int length=0;
+ short minsamplevalue,maxsamplevalue;
+ float coefficient = 1.0;
+ int streamcount = 0,i;
+ PSHORT localsinkbuf,localsrcbuf;
+ ServerStream * stream = mixer->serverstreamlist;
+
+ /*TODOAssert(mixer->serverstreamlist == NULL)*/
+
+ /*Find the Longest Buffer within all ServerStreams*/
+ length = stream->length_filtered;
+ while(stream->next != NULL)
+ {
+ if(stream->length_filtered > length && stream->ready == TRUE )
+ length = stream->length_filtered;
+ stream = stream->next;
+ }
+
+ /*Allocate MasterBuffer*/
+ mixer->masterbuf[buffer] = HeapAlloc(GetProcessHeap(), 0, length);
+ localsinkbuf = mixer->masterbuf[buffer];
+ mixer->bytes_to_play = length;
+
+ /*Perform Actual Mixing*/
+ stream = mixer->serverstreamlist;
+ minsamplevalue = *(short *) stream->minsamplevalue;
+ maxsamplevalue = *(short *) stream->maxsamplevalue;
+ while(stream->next != NULL)
+ {
+ localsrcbuf = stream->filteredbuf;
+ if(stream->ready == TRUE )
+ {
+ if( *(short *)stream->maxsamplevalue != maxsamplevalue ||
+ *(short *)stream->minsamplevalue != minsamplevalue )
+ {
+ if( (float) maxsamplevalue / (float)*(short *)stream->maxsamplevalue <
+ (float) minsamplevalue / (float)*(short *)stream->minsamplevalue )
+ coefficient = (float) maxsamplevalue / (float)*(short *)stream->maxsamplevalue;
+ else
+ coefficient = (float) minsamplevalue / (float)*(short *)stream->minsamplevalue;
+
+ for(i=0;i<stream->length_filtered;i++)
+ {
+ localsinkbuf[i] = (short) (( (localsinkbuf[i] * streamcount) + ((short)((float)
localsrcbuf[i] ) * coefficient) ) / (streamcount +1));
+ }
+ }
+ }
+ stream->ready = 0;
+ streamcount++;
+ stream = stream->next;
+ }
CopyMemory(mixer->masterbuf[buffer],mixer->serverstreamlist->filteredbuf,mixer->serverstreamlist->length_filtered);
- mixer->bytes_to_play = mixer->serverstreamlist->length_filtered;
return NULL;
}
Modified: branches/nyadav-audio-branch/base/services/audsrv/stream.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/base/servic…
==============================================================================
--- branches/nyadav-audio-branch/base/services/audsrv/stream.c [iso-8859-1] (original)
+++ branches/nyadav-audio-branch/base/services/audsrv/stream.c [iso-8859-1] Thu Jun 9
23:06:06 2011
@@ -192,7 +192,7 @@
localstream = localstream->next;
localstream->next = newstream;
}
- SetEvent(pengine->streampresent);
+ SetEvent(pengine->newStreamEvent);
return newstream->streamid;
error:
Modified: branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/drivers/wdm…
==============================================================================
--- branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c
[iso-8859-1] (original)
+++ branches/nyadav-audio-branch/drivers/wdm/audio/backpln/audclient/audclient.c
[iso-8859-1] Thu Jun 9 23:06:06 2011
@@ -12,6 +12,9 @@
#include <audsrvapi.h>
#include <stdio.h>
+#include <debug.h>
+#include <windows.h>
+#include <winbase.h>
void OpenComplete (int error );
void BufferCopied (int error );
@@ -28,7 +31,7 @@
DWORD WINAPI RunAudioThread(LPVOID param)
{
ClientStream * localstream = (ClientStream *) param;
- playaudio(localstream);
+ PlayAudio(localstream);
return 0;
}
@@ -45,7 +48,6 @@
}
void PlayComplete (int error )
{
- OutputDebugStringA("Playback Completed\n");
}
int
__cdecl
@@ -55,11 +57,11 @@
DWORD dwID;
HANDLE audiothread = NULL;
char input='\0';
- OutputDebugStringA("ReactOS Audio Mixer Sample Client.Enter 'a' to
Stop.\n");
+ printf("ReactOS Audio Mixer Sample Client.Enter 'a' to Stop.\n");
//if (clientstream->callbacks.OpenComplete == NULL ||
clientstream->callbacks.BufferCopied == NULL || clientstream->callbacks.PlayComplete
== NULL) printf("");
/*[out]HANDLE * streamhandle,[in] long frequency,[in] int number of channels,[in] int
bitspersample,[in]ULONG channelmask,[in] int volume,[in] int mute,[in] float balance*/
- error = initstream ( &clientstream ,
+ error = InitStream ( &clientstream ,
44100 ,
2 ,
16 ,
@@ -71,20 +73,17 @@
if ( error )
{
- OutputDebugStringA("Failed to Initialize Stream.Error \n");
goto error;
}
else
{
- OutputDebugStringA("StreamID : %ld\n",clientstream.stream);
audiothread = CreateThread(NULL,0,RunAudioThread,&clientstream,0,&dwID);
}
while ( input != 'a' )
scanf("%c",&input);
- OutputDebugStringA("Stoping Audio Stream.\n");
- stopaudio(&clientstream);
+ StopAudio(&clientstream);
WaitForSingleObject(audiothread,INFINITE);
return 0;
Modified: branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h
URL:
http://svn.reactos.org/svn/reactos/branches/nyadav-audio-branch/include/rea…
==============================================================================
--- branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h [iso-8859-1]
(original)
+++ branches/nyadav-audio-branch/include/reactos/libs/audsrv/audsrvapi.h [iso-8859-1] Thu
Jun 9 23:06:06 2011
@@ -24,7 +24,7 @@
} ClientStream;
/********************API Functions******************/
-WINAPI int initstream (ClientStream * clientstream,
+WINAPI int InitStream (ClientStream * clientstream,
LONG frequency,
int channels,
int bitspersample,
@@ -34,8 +34,8 @@
int mute,
float balance);
-WINAPI int playaudio ( ClientStream * clientstream);
-WINAPI int stopaudio (ClientStream * clientstream );
+WINAPI int PlayAudio ( ClientStream * clientstream);
+WINAPI int StopAudio (ClientStream * clientstream );
WINAPI int Volume(ClientStream * clientstream,
int * volume );