This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Convert stereo audio data to mono

Wirtschaft Ist TotWirtschaft Ist Tot Posts: 3Member

Hi friends, I have an AudioStreamSample with stereo data. How can I convert it to mono? This will reduce the size by half, I think.

Tags :


  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Welcome to the forums!

    In the import tab on the Godot Editor, I believe there is an option to convert audio to mono. From what I remember, it is near the bottom of the import settings for audio files.

  • Wirtschaft Ist TotWirtschaft Ist Tot Posts: 3Member
    edited March 2020

    Hello TwistedTwigleg =) !

    Thanks for your help! But this is not quite for me. I need to convert throughout the gameplay.

  • Wirtschaft Ist TotWirtschaft Ist Tot Posts: 3Member
    edited March 2020

    I already wrote a small function for this:

    func convert_stereo_to_mono(stream:AudioStreamSample):
        var old_data = stream.get_data()
        var new_data = range(old_data.size() / 2)
        if stream.format == stream.FORMAT_16_BITS:
            for i in new_data.size() / 2:
                new_data[i * 2] = (old_data[i * 4] + old_data[i * 4 + 2]) / 2.0
                new_data[i * 2+1] = (old_data[i * 4 + 1] + old_data[i * 4 + 3])/2.0
            for i in new_data.size():
                new_data[i] = (old_data[i * 2] + old_data[i * 2 + 1]) / 2.0 = new_data
        stream.stereo = false

    It works great.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.