Recording and outputting wav files in Unity3d

Source: Internet
Author: User

Recently in the video recording of things to see the next audio recording and output. The main reference is the official framecapturer:

Https://github.com/unity3d-jp/FrameCapturer

Because the demand is not very complex, only recorded and simple WAV output.

WAV file structure is relatively simple, divided into two parts of the file header and data, the file header format on the Internet, the data can be directly using uncompressed data.

One thing to note here is that C # does not populate all bytes when writing with StreamWriter.

For example, the int data occupies 4 bytes, and the write will only fill in the corresponding data size byte, so here use Bitconverter to do byte write

Mfilestream.write (bitconverter.getbytes (04);

Get audio This piece can be provided by unity itself with events:

void Onaudiofilterread (floatint  channels) {    ...}

Audio write order is mono channel-right channel, left channel-right channel ... Cycle. Since unity is in this order by default, the second parameter is not available.

Corresponding to the different bits of the WAV file, the corresponding numeric conversion operation can be done when the byte is written.

Project file Address:

Https://gitee.com/Hont/WavAudioRecorder

Recording and outputting wav files in Unity3d

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.