Dear Tim,
first of all Thanks for all the help which u provided, with that i am able to transfer my audio to virtual microphone from my user application.
But while playing the virtual mic recorded audio using audacity i observed lots of noise along with actual audio, may I know why i am getting noise along with actual audio.
I am using ringbuffer to store transferred audio packet from user app, and calling RingBuffer::GetRingBufferInstance()->Put((BYTE*)_Irp->AssociatedIrp.SystemBuffer, inBufLength); inside my custom IOCTL handler api.
NTSTATUS HandleCustomIoctl(In DEVICE_OBJECT* _DeviceObject,
Inout IRP* _Irp)
{
//PIO_STACK_LOCATION irpSp;// Pointer to current stack location
//NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
ULONG inBufLength; // Input buffer length
ULONG outBufLength; // Output buffer length
PCHAR /*inBuf,*/ outBuf; // pointer to Input and output buffer
PCHAR data = "This String is from Device Driver !!!";
size_t datalen = strlen(data) + 1;//Length of data including null
//PMDL mdl = NULL;
//PCHAR buffer = NULL;
UNREFERENCED_PARAMETER(_DeviceObject);
PAGED_CODE();
PIO_STACK_LOCATION stackLocation = NULL;
//CHAR* messageFromKernel = "ohai from them kernelz";
NTSTATUS ntstatus = STATUS_SUCCESS;
stackLocation = IoGetCurrentIrpStackLocation(_Irp);
inBufLength = stackLocation->Parameters.DeviceIoControl.InputBufferLength;
outBufLength = stackLocation->Parameters.DeviceIoControl.OutputBufferLength;
if (stackLocation->Parameters.DeviceIoControl.IoControlCode == IOCTL_CSMT_READ_METHOD_DIRECT_IN)
{
RingBuffer::GetRingBufferInstance()->Put((BYTE*)_Irp->AssociatedIrp.SystemBuffer, inBufLength);
DbgPrint("IOCTL_SPOTLESS (0x%x) issued", stackLocation->Parameters.DeviceIoControl.IoControlCode);
DbgPrint("Input received from userland: %s", (char*)_Irp->AssociatedIrp.SystemBuffer);
DbgPrint("Input bufferlength: %ld", inBufLength);
//inBuf = (BYTE*)_Irp->AssociatedIrp.SystemBuffer;
outBuf = (char*)_Irp->AssociatedIrp.SystemBuffer;
//CAudioDataRingbuffer::getRingBufferInstance()->RingBuffer_Write(CAudioDataRingbuffer::getRingBufferInstance()->m_global_buffer_struct,
//(SHORT*)_Irp->AssociatedIrp.SystemBuffer,4096);
_Irp->IoStatus.Information = 0;// strlen(messageFromKernel);
_Irp->IoStatus.Status = ntstatus;
RtlCopyBytes(outBuf, data, outBufLength);
_Irp->IoStatus.Information = (outBufLength < datalen ? outBufLength : datalen);
//DbgPrint("Sending to userland: %s", messageFromKernel);
//RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, messageFromKernel, strlen(Irp->AssociatedIrp.SystemBuffer));
IoCompleteRequest(_Irp, IO_NO_INCREMENT);
return ntstatus;
}
ntstatus = PcDispatchIrp(_DeviceObject, _Irp);
return ntstatus;
}
}
inside WriteBytes i do,
ULONG bufferOffset = m_ullLinearPosition % m_ulDmaBufferSize;
// Normally this will loop no more than once for a single wrap, but if
// many bytes have been displaced then this may loops many times.
while (ByteDisplacement > 0)
{
ULONG runWrite = min(ByteDisplacement, m_ulDmaBufferSize - bufferOffset);
SIZE_T actuallyWritten;
RingBuffer::GetRingBufferInstance()->Take(m_pDmaBuffer + bufferOffset, runWrite, &actuallyWritten);
if (actuallyWritten < runWrite)
{
RtlZeroMemory(m_pDmaBuffer + bufferOffset + actuallyWritten, runWrite - actuallyWritten);
}
DbgPrint("bytes read : %ld", ByteDisplacement);
bufferOffset = (bufferOffset + runWrite) % m_ulDmaBufferSize;
ByteDisplacement -= runWrite;
}
Plz do let me know if u need any other part of code inorder to understand my issue.