❔ Problem with converting WAV byte[] to MP3 byte[] (and vice versa)
I have this code (using NAudio) for converting a wav byte array to an mp3 byte array:
Not sure why, but using the function the end of a wav file just gets cut off (examples attached)
How can I fix this or are there any alternative ways of conversion?
14 Replies
Pretty sure all variables in
using
blocks get disposed before return
Should I move the return statement outside of the using statement?
No, you probably just want to store array before
return
in some variable and then return itdone but audio still gets cut off
Ok then idk how to help, sorry
Call flush before return
Because Dispose get's called after ToArray, so wtr isn't flushed
Still seems like audio gets cut off
Before
ToArray
not after
You could also do
Thanks! It worked. I have a similar function for the other way arround, should it also get the same treatment?
Yeah pretty much, using statement calls
Dispose
method after we leave the scope, so
retMs
isn't getting the latest data from pcmStream
Typically Flush
is called in the Dispose method, and Naudio does follow that, but because ToArray
comes before the Dispose
call, flush
isn't calledso pcmStream.Flush(); should be called before ToArray()?
Yeah, or you could do it like this as well
Calling
ToArray
after wtr
is DisposedI see, thanks!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.