Max
Max

Reputation: 11

InvalidParameter calling waveOutOpen

I am attempting to implement Mp3 streaming using NAudio's BufferedWaveProvider following Mark Heath's blog here.

I have all of my streaming implemented, but I'm getting an MmException with the message "InvalidParameter calling waveOutOpen."

I saw this related question: InvalidParameter calling waveOutOpen MmException, so I took a look at the WaveFormat I was getting using the following code snippet:

private WaveFormat CreateWaveFormat(Mp3Frame frame)
{
    var numberOfChannels = frame.ChannelMode == ChannelMode.Mono ? 1 : 2;
    return new Mp3WaveFormat(frame.SampleRate, numberOfChannels, frame.FrameLength, frame.BitRate);
}

Here is the WaveFormat I get, taken from my debugger:

-       sampleProvider.WaveFormat   {MpegLayer3}    NAudio.Wave.WaveFormat {NAudio.Wave.Mp3WaveFormat}
    AverageBytesPerSecond   32000   int
    BitsPerSample   0   int
    BlockAlign  1   int
    Channels    2   int
    Encoding    MpegLayer3  NAudio.Wave.WaveFormatEncoding
    ExtraSize   12  int
    SampleRate  48000   int
    averageBytesPerSecond   32000   int
    bitsPerSample   0   short
    blockAlign  1   short
    blockSize   768 ushort
    channels    2   short
    codecDelay  0   ushort
    extraSize   12  short
    flags   PaddingIso  NAudio.Wave.Mp3WaveFormatFlags
    framesPerBlock  1   ushort
    id  Mpeg    NAudio.Wave.Mp3WaveFormatId
    sampleRate  48000   int
    waveFormatTag   MpegLayer3  NAudio.Wave.WaveFormatEncoding
+       Static members  

To test all this, I'm loading a test Mp3 file into a FileStream. I decided to see what the WaveFormat looked like when I used Mp3FileReader to read the whole stream, and interestingly I got a completely different WaveFormat:

-       format  {16 bit PCM: 48kHz 2 channels}  NAudio.Wave.WaveFormat
    AverageBytesPerSecond   192000  int
    BitsPerSample   16  int
    BlockAlign  4   int
    Channels    2   int
    Encoding    Pcm NAudio.Wave.WaveFormatEncoding
    ExtraSize   0   int
    SampleRate  48000   int
    averageBytesPerSecond   192000  int
    bitsPerSample   16  short
    blockAlign  4   short
    channels    2   short
    extraSize   0   short
    sampleRate  48000   int
    waveFormatTag   Pcm NAudio.Wave.WaveFormatEncoding

I took a look at the first 16 bytes of the stream in both cases, and they were identical. Any ideas where I'm going wrong? Or are the differing WaveFormats a red herring? Could something else be the problem?

Thanks for your time!

Upvotes: 0

Views: 979

Answers (1)

Max
Max

Reputation: 11

I have found the problem. Issue was that I was using the WaveFormat from the Mp3Frame, rather than the WaveFormat provided by the Mp3 decompressor. The WaveOut expects the format of the fully decompressed audio.

Upvotes: 1

Related Questions