generate pcm wav file: fix bug about open file mode and free memory