0

When decompressing frames of Mp3 from Server the above mentioned exception occurs while the Mp3 have been played for 10 to 15 sec.My application is a Client/Server application.I m sending the Mp3 Frames by composing Mp3 Packets and serializing it over Network Stream.I m using NAudio Open Source API for Compressing and Decompressing Frames and Playing the Mp3.I get the following exception with Stack Trace.

NAudio.MmException.Try(MmResult result, String function)

at NAudio.Wave.Compression.AcmStreamHeader.Convert(Int32 bytesToConvert, Int32& sourceBytesConverted)

at NAudio.Wave.Compression.AcmStream.Convert(Int32 bytesToConvert, Int32& sourceBytesConverted)

at NAudio.Wave.AcmMp3FrameDecompressor.DecompressFrame(Mp3Frame frame, Byte[] dest, Int32 destOffset)

at Client.Audio.SoundPlayer.StreamMP3(Object state)

Samie
  • 83
  • 2
  • 11

2 Answers2

1

AcmNotPossible is an error code returned by the acmStreamConvert Windows function, which calls into the MP3 ACM codec. This error likely indicates either an invalid MP3 frame, or that you have passed in too many frames at once. How sure are you that you are getting whole MP3 frames? It is a good idea to debug problems like this by also writing the data you receive to an MP3 file and then checking that can play as expected.

Mark Heath
  • 48,273
  • 29
  • 137
  • 194
  • As reported by you there may be invalid frame.Let me talk about Naudio API.When you parse the Mp3Frame using Naudio,it can only be parsed when correct Mp3 Frame be returned out of Stream.there Couldn't be chance of second probability because at one instance one frame is being written on the Stream. – Samie Feb 07 '12 at 07:35
  • 1
    is there anything odd about the frame? is it mono while the others are stereo? is it a different sample rate to the others? – Mark Heath Feb 07 '12 at 07:49
  • Can you brief me about mono and stereo frames?No!The sample rate is same for all frames – Samie Feb 07 '12 at 12:31
0

Converting to mp3 requires extended info.

  • move mp3formatin "pwaveformatEx" to a "bytebuffer" of 512 bytes.
  • add mp3 codec extended information to bytebuffer.

I declared the mp3 codec info as

const MP3Extend = chr(0)+chr(1)+chr(0)+chr(4)+chr(0)+chr(0)+chr(0)+chr(192)+chr(3)+chr(1)+chr(0)+chr(0);

then i created the var buffer buffer=array[0..511] of byte; mp3formatin:PWaveformatEx;

  • initialize mp3formatin and formatout
  • move the mp3formatin pwaveformatEx to the byte buffer
  • move(mp3formatin^,buffer[0],sizeof(pWaveformatex))
  • add then mp3 extended codec info move(mp3extend,buffer[sizeof(pWaveformatex)-1],length(MP3EXTEND)) acmstreamopen(Instance, nil,pwaveformatEx(@buffer[0])^,outputwaveformatEx^, etc

when you now refer to the mp3formatin eg pWaveformatEx(@buffer[0]).thevalues

Hope this solves your problem.

Vimanyu
  • 625
  • 2
  • 9
  • 24