Corey-M/NAudio.Lame

ReportFunction usage

Closed this issue · 2 comments

Hello,

Can the ReportFunction delegate be used to track progress of the conversion? Or is there another way to track progress?

Thanks

Hi Jeremy. The ReportFunction delegate was intended to allow you to provide functions to hook into the LAME console output via the set_lame_debugf, set_lame_msgf and set_lame_errorf entry points. Unfortunately I didn't get around to actually exposing these entry points in the public release (1.0.3) as I was focused primarily on getting encoding working and fixing some issues with the 32-/64-bit loaders during that release and left some of my experimental stuff exposed.

The print hooks are used to allow the library to output information from things like lame_print_config and lame_print_internals as well as some diagnostics. I'll see what output if any is produced during the normal encoding process and see about how useful it might be for encoding process reporting, etc.

I'll create a new NAudio.Lame.Library class that proxies calls to the various entry points that don't require an encoding context so that people can use them. Currently the only one of these that is exposed is id3tag_genre_list (via the static NAudio.Lame.MP3Writer.Genres property) which was added with the basic ID3 tag support.

Check back for an update in the next few hours. Once I have it working I'll update the NuGet as well.

Turns out that the print function are 1) not very useful and 2) pretty tightly bound to the encoding context. Basically they are just a way to provide for feedback from the LAME library under extraordinary circumstances and don't seem to be used at all during normal encoding. I've added them to the MP3FileWriter class along with the two functions that print config and internal information from the context.

Since that didn't work I added a progress event to the MP3FileWriter that will be invoked after each of the encoder calls. The event will tell your code how many bytes of input and output, as well as sending a flag for end of encoding with a final update.

Since this was getting called a lot in my tests I also added a simple rate limiter so you can choose to receive updates slower or faster depending on your needs. By default it will send one update per 100ms. Timing is done with DateTime so it won't be particularly accurate, but it helps keep the even traffic down.

Updated code is here and the NuGet package is updated as well. See the readme here for a usage example.