Source code checked in, #53bf2cd3f8d6
New Post: BlackmannHarrisWindow Function has an error
Thanks Mark,
That was quick of you. The window function code now looks correct.
Best wishes
John C
Source code checked in, #44f1f88aa4a4
Source code checked in, #f61b413ba7b8
New Post: Resampler Transform
hello,
(between two business trips) I created a class ResamplerTransform(based on dmo.resamplermediaobject)
I wonder if this basis is correct
///<summary>/// From wmcodecsdp.h/// Implements:/// - IMediaObject /// - IMFTransform (Media foundation - we will leave this for now as there is loads of MF stuff)/// - IPropertyStore /// - IWMResamplerProps /// Can resample PCM or IEEE///</summary> [ComImport, Guid("f447b69e-1884-4a7e-8055-346f74d6edb3")]class CLSID_CResamplerMediaObject {// SAME DMO ResamplerMediaObjects, but rename :-) }///<summary>/// Resampler (base Dmo.ResamplerMediaObjects)///</summary>publicclass ResamplerTranform : IDisposable {/* * * TODO implante channelConversionMatrix * TODO implante Quality properties ???? * */ NAudio.Dmo.IWMResamplerProps resamplerPropsInterface; IMFTransform resamplerTransformInterface; CLSID_CResamplerMediaObject mediaComObject; public ResamplerTranform() : this(60) { }///<summary>/// Creates a new Resampler based on the DMO Resampler///</summary>public ResamplerTranform(int outputQuality) { mediaComObject = new CLSID_CResamplerMediaObject(); resamplerPropsInterface = (NAudio.Dmo.IWMResamplerProps)mediaComObject; // Quality resamplerPropsInterface.SetHalfFilterLength(outputQuality);// Channels// resamplerPropsInterface.SetUserChannelMtx(channelConversionMatrix); resamplerTransformInterface = (IMFTransform)mediaComObject; } public IMFTransform Transform {get { return resamplerTransformInterface; } }public NAudio.Dmo.IWMResamplerProps ResamplerProps {get { return resamplerPropsInterface; } }#region IDisposable Memberspublicvoid Dispose() {if (resamplerPropsInterface != null) { Marshal.ReleaseComObject(resamplerPropsInterface); resamplerPropsInterface = null; }if (resamplerTransformInterface != null) { Marshal.ReleaseComObject(resamplerTransformInterface); resamplerTransformInterface = null; }if (mediaComObject != null) { Marshal.ReleaseComObject(mediaComObject); mediaComObject = null; } }#endregion }
New Post: Resampler Transform
Yes, this is very similar to how we do it for DMO (although I didn't know there was quality property). The main challenge is learning how to use the IMediaTransform interface to efficiently pass byte arrays in and out, and also getting it to flush its buffers on a reposition.
On a different note, I got encoding to AAC from a byte array working last night, and some of your interop definitions proved very helpful so thanks very much.
Mark
New Post: Resampler Transform
I still continued my example (http://code.google.com/p/bitspersampleconv2/wiki/HowToUseResamplerMFT) integrated Mediafoundationreader the moment and to learn.
I saw your approach Encoder and use of buffers, I think it will be very useful for my procedure.
Incidentally I found a book for you
http://books.google.fr/books?id=w4EkIF_O7F8C&pg=PT507&lpg=PT507&dq=f447b69e-1884-4a7e-8055-346f74d6edb3&source=bl&ots=pOpwYyqMGZ&sig=RYVpx1puLD0S8X9cOCE6qx8dm0M&hl=fr&sa=X&ei=RIi4UJ6pK4WRhQeqrIDYDw&ved=0CFsQ6AEwBg
can be a gift idea for Christmas;-) ok this is not funny :-)
New Post: Resampler Transform
So, I need your help.
I created this procedure from a c + + example
I came across an error (HResult): The called 0xC00D35B5 no longer accept additional input.
You know of this error?
IMFSourceReader retSourceReader = null;
int hr = 0;// ADD Constant Guid MF_MT_ALL_SAMPLES_INDEPENDENT = new Guid("c9173739-5e56-461c-b713-46fb995cb95f");// see MFErreurconstint MF_E_TRANSFORM_NEED_MORE_INPUT = unchecked((int)0xC00D6D72);// FOR TEST HERE :: Audio Format Output (todo properties) WaveFormat wfOutput = new WaveFormat(44100, 2);/* 1 Initialization */ MediaFoundationInterop.MFStartup(MediaFoundationInterop.MF_VERSION);/* 2. Create Resampler MFT Object CComPtr<IUnknown> spTransformUnk; IMFTransform *pTransform = NULL; //< this is Resampler MFT hr = CoCreateInstance(CLSID_CResamplerMediaObject, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&spTransformUnk); */ CLSID_CResamplerMediaObject mediaComObject; mediaComObject = new CLSID_CResamplerMediaObject();//hr = spTransformUnk->QueryInterface(IID_PPV_ARGS(&pTransform)); IMFTransform pTransform = null; pTransform = (IMFTransform)mediaComObject; //rsampler.Transform;/* 3. Specify input/output PCM format to Resampler MFT */ IMFMediaType mediaType = null;// Create MediaType MediaFoundationInterop.MFCreateMediaType(out mediaType);// hr = pMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio)); mediaType.SetGUID(MediaFoundationAttributes.MF_MT_MAJOR_TYPE, NAudio.MediaFoundation.MediaTypes.MFMediaType_Audio);// hr = pMediaType->SetGUID(MF_MT_SUBTYPE, (fmt.sampleFormat == MyBitFormatInt) ? MFAudioFormat_PCM : MFAudioFormat_Float);if (wfOutput.Encoding == WaveFormatEncoding.Pcm) mediaType.SetGUID(MediaFoundationAttributes.MF_MT_SUBTYPE, AudioSubtypes.MFAudioFormat_PCM);else mediaType.SetGUID(MediaFoundationAttributes.MF_MT_SUBTYPE, AudioSubtypes.MFAudioFormat_Float);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, fmt.nChannels); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_NUM_CHANNELS, wfOutput.Channels);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, fmt.sampleRate); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_SAMPLES_PER_SECOND, wfOutput.SampleRate);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, fmt.FrameBytes()); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_BLOCK_ALIGNMENT, wfOutput.BlockAlign);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, fmt.BytesPerSec()); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_AVG_BYTES_PER_SECOND, wfOutput.AverageBytesPerSecond);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, fmt.bits);//mediaType.SetUINT32(MediaFoundationInterop.MF_MT_AUDIO_BITS_PER_SAMPLE, wfOutput.BitsPerSample);// hr = pMediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); mediaType.SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, -1);
/* * if (0 != fmt.dwChannelMask) { * hr = pMediaType->SetUINT32(MF_MT_AUDIO_CHANNEL_MASK, fmt.dwChannelMask); * } */if (wfOutput.Encoding == WaveFormatEncoding.Pcm) {/* if (fmt.bits != fmt.validBitsPerSample) { hr = pMediaType->SetUINT32(MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, fmt.validBitsPerSample); } */ mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_BITS_PER_SAMPLE, wfOutput.BitsPerSample); } // pTransform->SetInputType(0, spOutputType, 0); pTransform.SetInputType(0, mediaType, 0);/* 4. Send stream start message to Resampler MFT */// hr = pTransform->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, NULL); pTransform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_COMMAND_FLUSH, IntPtr.Zero);// hr = pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL);// Erreur ????????????//pTransform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, IntPtr.Zero);// hr = pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, NULL); pTransform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_NOTIFY_START_OF_STREAM, IntPtr.Zero);/* 5. Create IMFSample from uncompressed PCM input data *//* BYTE *data = ...; //< input PCM data DWORD bytes = ...; //< bytes need to be smaller than approx. 1Mbytes IMFMediaBuffer *pBuffer = NULL; hr = MFCreateMemoryBuffer(bytes , &pBuffer); */// IMFMediaBuffer *pBuffer = NULL; IMFMediaBuffer pBuffer = null;// hr = MFCreateMemoryBuffer(bytes , &pBuffer); MFCreateMemoryBuffer(wfOutput.AverageBytesPerSecond*4, out pBuffer);// BYTE *pByteBufferTo = NULL;// hr = pBuffer->Lock(&pByteBufferTo, NULL, NULL); IntPtr pByteBufferTo;int maxLength;int currentLength; pBuffer.Lock(out pByteBufferTo, out maxLength, out currentLength);//memcpy(pByteBufferTo, data, bytes);byte[] data = newbyte[maxLength]; Marshal.Copy(pByteBufferTo,data,0, maxLength); // pBuffer->Unlock(); pBuffer.Unlock();// pByteBufferTo = NULL; pByteBufferTo = IntPtr.Zero;//hr = pBuffer->SetCurrentLength(bytes); pBuffer.SetCurrentLength(maxLength); //IMFSample *pSample = NULL; IMFSample pSample = null;//hr = MFCreateSample(&pSample); MediaFoundationInterop.MFCreateSample(out pSample);//hr = pSample->AddBuffer(pBuffer); pSample.AddBuffer(pBuffer);// SafeRelease(&pBuffer); Marshal.ReleaseComObject(pBuffer);/* 6. Set input data to Resampler MFT */// hr = pTransform->ProcessInput(0, pSample, 0);
hr = pTransform.ProcessInput(0, pSample, 0); // <- ERREUR !!!!! MFError.ThrowExceptionForHR(hr);
New Post: Resampler Transform
From: ManuN
So, I need your help.
I created this procedure from a c + + example
I came across an error (HResult): The called 0xC00D35B5 no longer accept additional input.
You know of this error?IMFSourceReader retSourceReader = null;
int hr = 0;// ADD Constant Guid MF_MT_ALL_SAMPLES_INDEPENDENT = new Guid("c9173739-5e56-461c-b713-46fb995cb95f");// see MFErreurconstint MF_E_TRANSFORM_NEED_MORE_INPUT = unchecked((int)0xC00D6D72);// FOR TEST HERE :: Audio Format Output (todo properties) WaveFormat wfOutput = new WaveFormat(44100, 2);/* 1 Initialization */ MediaFoundationInterop.MFStartup(MediaFoundationInterop.MF_VERSION);/* 2. Create Resampler MFT Object CComPtr<IUnknown> spTransformUnk; IMFTransform *pTransform = NULL; //< this is Resampler MFT hr = CoCreateInstance(CLSID_CResamplerMediaObject, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&spTransformUnk); */ CLSID_CResamplerMediaObject mediaComObject; mediaComObject = new CLSID_CResamplerMediaObject();//hr = spTransformUnk->QueryInterface(IID_PPV_ARGS(&pTransform)); IMFTransform pTransform = null; pTransform = (IMFTransform)mediaComObject; //rsampler.Transform;/* 3. Specify input/output PCM format to Resampler MFT */ IMFMediaType mediaType = null;// Create MediaType MediaFoundationInterop.MFCreateMediaType(out mediaType);// hr = pMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio)); mediaType.SetGUID(MediaFoundationAttributes.MF_MT_MAJOR_TYPE, NAudio.MediaFoundation.MediaTypes.MFMediaType_Audio);// hr = pMediaType->SetGUID(MF_MT_SUBTYPE, (fmt.sampleFormat == MyBitFormatInt) ? MFAudioFormat_PCM : MFAudioFormat_Float);if (wfOutput.Encoding == WaveFormatEncoding.Pcm) mediaType.SetGUID(MediaFoundationAttributes.MF_MT_SUBTYPE, AudioSubtypes.MFAudioFormat_PCM);else mediaType.SetGUID(MediaFoundationAttributes.MF_MT_SUBTYPE, AudioSubtypes.MFAudioFormat_Float);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, fmt.nChannels); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_NUM_CHANNELS, wfOutput.Channels);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, fmt.sampleRate); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_SAMPLES_PER_SECOND, wfOutput.SampleRate);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, fmt.FrameBytes()); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_BLOCK_ALIGNMENT, wfOutput.BlockAlign);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, fmt.BytesPerSec()); mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_AVG_BYTES_PER_SECOND, wfOutput.AverageBytesPerSecond);// hr = pMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, fmt.bits);//mediaType.SetUINT32(MediaFoundationInterop.MF_MT_AUDIO_BITS_PER_SAMPLE, wfOutput.BitsPerSample);// hr = pMediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); mediaType.SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, -1);/* * if (0 != fmt.dwChannelMask) { * hr = pMediaType->SetUINT32(MF_MT_AUDIO_CHANNEL_MASK, fmt.dwChannelMask); * } */if (wfOutput.Encoding == WaveFormatEncoding.Pcm) {/* if (fmt.bits != fmt.validBitsPerSample) { hr = pMediaType->SetUINT32(MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, fmt.validBitsPerSample); } */ mediaType.SetUINT32(MediaFoundationAttributes.MF_MT_AUDIO_BITS_PER_SAMPLE, wfOutput.BitsPerSample); } // pTransform->SetInputType(0, spOutputType, 0); pTransform.SetInputType(0, mediaType, 0);/* 4. Send stream start message to Resampler MFT */// hr = pTransform->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, NULL); pTransform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_COMMAND_FLUSH, IntPtr.Zero);// hr = pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL);// Erreur ????????????//pTransform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, IntPtr.Zero);// hr = pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, NULL); pTransform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_NOTIFY_START_OF_STREAM, IntPtr.Zero);/* 5. Create IMFSample from uncompressed PCM input data *//* BYTE *data = ...; //< input PCM data DWORD bytes = ...; //< bytes need to be smaller than approx. 1Mbytes IMFMediaBuffer *pBuffer = NULL; hr = MFCreateMemoryBuffer(bytes , &pBuffer); */// IMFMediaBuffer *pBuffer = NULL; IMFMediaBuffer pBuffer = null;// hr = MFCreateMemoryBuffer(bytes , &pBuffer); MFCreateMemoryBuffer(wfOutput.AverageBytesPerSecond*4, out pBuffer);// BYTE *pByteBufferTo = NULL;// hr = pBuffer->Lock(&pByteBufferTo, NULL, NULL); IntPtr pByteBufferTo;int maxLength;int currentLength; pBuffer.Lock(out pByteBufferTo, out maxLength, out currentLength);//memcpy(pByteBufferTo, data, bytes);byte[] data = newbyte[maxLength]; Marshal.Copy(pByteBufferTo,data,0, maxLength); // pBuffer->Unlock(); pBuffer.Unlock();// pByteBufferTo = NULL; pByteBufferTo = IntPtr.Zero;//hr = pBuffer->SetCurrentLength(bytes); pBuffer.SetCurrentLength(maxLength); //IMFSample *pSample = NULL; IMFSample pSample = null;//hr = MFCreateSample(&pSample); MediaFoundationInterop.MFCreateSample(out pSample);//hr = pSample->AddBuffer(pBuffer); pSample.AddBuffer(pBuffer);// SafeRelease(&pBuffer); Marshal.ReleaseComObject(pBuffer);/* 6. Set input data to Resampler MFT */// hr = pTransform->ProcessInput(0, pSample, 0);hr = pTransform.ProcessInput(0, pSample, 0); // <- ERREUR !!!!! MFError.ThrowExceptionForHR(hr);Read the full discussion online.
To add a post to this discussion, reply to this email (naudio@discussions.codeplex.com)
To start a new discussion for this project, email naudio@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online atcodeplex.com
New Post: Resampler Transform
I deleted the Marshal.ReleaseComObject (pBuffer) but it is always the same
New Post: Resampler Transform
the message MFT_MESSAGE_START_OF_STREAM is already performing. (see Part 4)
New Post: Resampler Transform
From: ManuN
the message MFT_MESSAGE_START_OF_STREAM is already performing. (see Part 4)
Read the full discussion online.
To add a post to this discussion, reply to this email (naudio@discussions.codeplex.com)
To start a new discussion for this project, email naudio@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online atcodeplex.com
New Post: Resampler Transform
MFT_MESSAGE_NOTIFY_BEGIN_STREAMING
Error :: A valid type was not specified for this data stream or stream on which it depends
New Post: Resampler Transform
m: ManuN
MFT_MESSAGE_NOTIFY_BEGIN_STREAMING
Error :: A valid type was not specified for this data stream or stream on which it depends
New Post: Resampler Transform
I probably need to follow this procedure
Get Stream Identifiers
An MFT has one or more streams. Input streams receive input data, and output streams generate output data. Streams are not represented as distinct objects. Instead, various MFT methods take stream identifiers as parameters.
Some MFTs allow the client to add or remove input streams. During streaming, an MFT can add or remove output streams. (The client cannot add or remove output streams.)
- (Optional.) Call IMFTransform::GetStreamLimits to get the minimum and maximum number of streams that the MFT can support. If the minimum and maximum are the same, the MFT has a fixed number of streams.
- Call IMFTransform::GetStreamCount to get the initial number of streams.
- Call IMFTransform::GetStreamIDs to get the stream identifiers. If this method returns E_NOTIMPL, it means the MFT has a fixed number of streams, and the stream identifiers are consecutive starting from zero.
- (Optional.) If the MFT does not have a fixed number of streams, call IMFTransform::AddInputStreams to add more input streams, or IMFTransform::DeleteInputStream to remove input streams. (You cannot add or remove output streams.)
reference : http://msdn.microsoft.com/en-us/library/windows/desktop/aa965264(v=vs.85).aspx
New Post: Resampler Transform
yes obviously
After searching the label of the error
hr = pTransform.ProcessInput(0, pSample, 0); // <- ERREUR == MF_E_NOTACCEPTING
Not accepting, not accepting , pffffff :-(
New Post: How to code circullar buffer to create a delay and used the wavein for micrcophone and output to speaker?
Hi Mark thank you for responding,
I am newbie to this framework. kindly explain how to do it? your answer was "put the audio received into a BufferedWaveProvider and play from that."
I don't get it actually. please help me for this stuff.
New Post: Resampler Transform
Hello,I continue my investigations.
But obviously there are some errors in interface Transform
///<summary>/// Gets the buffer requirements and other information for an input stream on this Media Foundation transform (MFT). ///</summary>///<remarks>/// virtual HRESULT STDMETHODCALLTYPE GetInputStreamInfo( /// DWORD dwInputStreamID,/// /* [out] */ __RPC__out MFT_INPUT_STREAM_INFO *pStreamInfo) = 0;///</remarks>void GetInputStreamInfo([In] int dwInputStreamID, [In, Out] MFT_INPUT_STREAM_INFO pStreamInfo); Modify to void GetInputStreamInfo([In] int dwInputStreamID, out MFT_INPUT_STREAM_INFO pStreamInfo);
Same erreur in GetOutputStreamInfo
Exact ?????
New Post: Resampler Transform
New Post: Resampler Transform
that is a strange one. The MSDN documentation says [out] but it is only a single level of indirection. I would expect a **ppStreamInfo for a genuine out parameter, which is why I made it [In,Out] (I assumed the caller creates the struct and it is filled in by the user). I'll see what is in the header file