This project has moved. For the latest updates, please go here.

ResamplerDmoStream - Problem

Jul 4, 2011 at 10:16 AM
Edited Jul 4, 2011 at 11:30 AM

First, i want to say thank you for your time doing the support for NAudio. This is a great help for me (not only for me) in working with Audio buffers & streams.

Now, I like to do "simple" resampling of 16bit, 8kHz data into 16bit, 44,1Khz data and vice versa.

After testing the ACM based ConversionStream the result was very bad. Like mentioned in another discussion thread, it sounds robotic and out of tune.

Alternatives for better ACM - PCM sample rate conversion didn't found.

So I tried the ResamplerDmoStream. But it hangs in the Read method on IsAcceptingData() --> mediaObject.GetInputStatus:

 

 public bool IsAcceptingData(int inputStreamIndex)
        {
            DmoInputStatusFlags flags;
            int hresult = mediaObject.GetInputStatus(inputStreamIndex, out flags);  //<-- here it hangs
            Marshal.ThrowExceptionForHR(hresult);
            return (flags & DmoInputStatusFlags.DMO_INPUT_STATUSF_ACCEPT_DATA) == DmoInputStatusFlags.DMO_INPUT_STATUSF_ACCEPT_DATA;
        }

Are there any hints, why the interface is locking here? Disabling the IsAcceptionData method results in 0 reads, but without hanging.
Am I missing something in the framework installation? I have a Win7 64x Os, .Net Framework 4.0 installed using VS 2010 and the directX SDK 2009.
Thank you very much for your help.

Best regards,

Micha.


 

Coordinator
Jul 4, 2011 at 9:06 PM

Not come across this issue before, although I tend to use the ACM codec since it is more widely available. Are you able to write a short unit test that recreates the hang on your PC?

Jul 5, 2011 at 8:15 AM

I will try to build a unit test.

Another question I have, are there better ACM PCM codecs I could use than the one from Microsoft? I didn't found any alternatives for PCM sample rate conversion.

Coordinator
Jul 5, 2011 at 9:15 AM

the main issue with the ACM conversion codecs is that they don't do filtering - you have to write your own.

Jul 5, 2011 at 12:46 PM

I have to say, that the stream read method is called inside a Asio bufferCallback. The callback can be backtracked to a thread running in the asio driver. I don't know what the Asio driver is doing there internally.

I'am using the Asio driver from ESI for a Maya44 USB Audio interface. Maybe the behaviour is different with the Asio4All driver?

The solution with a Test project called MyNAudioTests you can download here: https://rapidshare.com/files/2233536498/NAudio.exe

 It is a whole NAudio solution with some adaptations regarding my project.

The file is named NAudio.exe because it is a selfextracting 7Zip archive. You will need the passwort "mediatec" to extract it.

Best regards. Thanks again for your investigations.

Micha.

 

 

 

 

Coordinator
Jul 5, 2011 at 12:53 PM

Oh I see, you're using ASIO. If at all possible, provide audio at the sample rate of your soundcard. Also ResamplerDmoStream should probably only be used on the thread it is created on.

Mark

Jul 5, 2011 at 1:17 PM

My ASIO driver doesn't support 8Khz tough the device specification said it. I suggest it will not be so easy to find an ASIO driver really swallow this sample rate.

I like to implement the rate conversion, because in my eyes it is pretty unsure which ASIO device/driver would be used in the final analysis.

I will try to test what you suggested, regarding the thread the ResamplerDmoStream will running in.

Jul 6, 2011 at 12:44 PM

You were right.

Because the ASIO and the DMO driver has a COM interface, you can use a ResamplerDmoStream in an ASIO  bufferCallback only if it is created inside the bufferCallback itself.

It seems to be a matter of STA / MTA thread apartment.

 



Coordinator
Jul 6, 2011 at 2:46 PM

Yes, I need to hurry up and get a fully managed resampler into NAudio. The DMO was a pain to wrap and is a pain to use.

Jul 7, 2011 at 11:26 AM

But, DMO Resampling sounds much better than ACM resampling.

So, for me right now DMO is a working alternative to the MS-PCM ACM codec. I just worked around the threading problem.

Thanks again for the hint.

Micha.

Coordinator
Jul 7, 2011 at 11:29 AM

glad its working for you. I can't use DMO very often since a lot of my code needs to work on Windows XP.

Mark