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.

render audio out as wav

fonofono Posts: 45Member
edited April 2020 in Audio

Hallo,

i'm experimenting with AudioEffectRecord and audiogenerator.

Do i miss some sort of initializazion step? Like linking the AudioEffectRecord to the AudioStreamPlayer for example?
The save produces actually no file saving at all.

#Declaration
var rec : AudioEffectRecord = null 


func _process(_delta):
    _get_input()
    _fill_buffer()


func _ready():
    rec = AudioEffectRecord.new()

    $Player.stream.mix_rate = sample_hz # Setting mix rate is only possible before play().
    playback = $Player.get_stream_playback()
    _fill_buffer() # Prefill, do before play() to avoid delay.
    $Player.play()

func _get_input():
    if Input.is_action_pressed("ui_up"):
        pulse_hz += 0.1
    if Input.is_action_pressed("ui_down"):
        pulse_hz -= 0.1
    if Input.is_action_pressed("ui_right"):
        pivar += 0.1
    if Input.is_action_pressed("ui_left"):
        pivar -= 0.1
    if Input.is_action_just_pressed("ui_page_up"):  
        rec.set_recording_active(true)
    if Input.is_action_just_pressed("ui_page_down"):
        #rec.set_recording_active(false)
        rec.get_recording().save_to_wav("res://1.wav") 

Any hints is appreciated. P.s I've skipped other irrelevant code.

Thanks

Comments

  • cyberealitycybereality Posts: 928Moderator

    I don't think you can save to "res://". You should probably open a file dialog to select the path.

  • fonofono Posts: 45Member
    edited April 2020

    Sorry for not updating. I've solved using the bus audio mic example, and changing the routing of
    the audio generator (audioplayer) to the record bus (using the appropriate index that corresponds to the record fx.

    Is possible to save without dialog as well. My function func _new_file_name()
    create recordings named using the follogin pattern:

    fname = "res://" +  str(n) + ".wav"
    
    save path
    
    func _get_input():
        if Input.is_action_pressed("ui_up"):
            pulse_hz += 0.01
        if Input.is_action_pressed("ui_down"):
            pulse_hz -= 0.01
        if Input.is_action_pressed("ui_right"):
            A += 0.01
        if Input.is_action_pressed("ui_left"):
            A -= 0.01
        if Input.is_action_just_pressed("ui_page_up"):  
            if  effect.is_recording_active() == false:
                effect.set_recording_active(true)   
        if Input.is_action_just_pressed("ui_page_down"):
            $Player.stream = recording
            recording = effect.get_recording()
            effect.set_recording_active(false)
            var save_path = _new_file_name()
            recording.save_to_wav(save_path)
            print("salvato in " + save_path)
            get_tree().reload_current_scene() 
    
    func _new_file_name():
        var file2Check = File.new()
        var doFileExists = true
        var fname = ""
        var n=0
        while doFileExists:
            fname = "res://" +  str(n) + ".wav"
            doFileExists = file2Check.file_exists(fname)
            if doFileExists == false:
                return fname
            n+=1
    
  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    If the documentation on saving games is anything to go by, you might need to save the audio files to user:// instead of res://, especially in exported games since res:// is read-only.

    That said, I've never tried to save to res://, so it might be possible.

  • fonofono Posts: 45Member
    edited April 2020

    Ok,

    it writes without problem. However i will follow your advice, to save in another folder.
    Another thing that seems quite strange to me is the beaviour of the audio bus effects.
    The order of the effects seem to change randomly every time i run the project, sometimes disabling the audio. at all

    This is what is happening:

    func _ready():
    var idx = AudioServer.get_bus_index("ToMaster")
    effect = AudioServer.get_bus_effect(idx, 0)

    Since the order change, the AudioServer.get_bus sometimes point to an audio effect not to Recor, indeed to other fx.

    my default bus is like this:

    Master----------ToMaster


    no fx-------------Record
    -------------------Notchfiler
    -------------------Phaser


    Speakers------Master

    Sometimes happen that Record changes position, creating a logical error in this line:
    effect = AudioServer.get_bus_effect(idx, 0)

    Btw wich picture format is allowed by the forum?

    Thanks

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    @fono said:
    Btw wich picture format is allowed by the forum?

    I know that .png and .jpg are supported. I think .gif is also supported.
    Are you having issues with uploading images? If so, does the "Add images" button work?

  • fonofono Posts: 45Member

    No it doesn't work Is there a size limit?
    I get the message file is not allowed.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Hmm, strange. There is a file size limit, but its like 2mb+ if I recall. We've been having issues before with images uploading, but I don't remember if we ever got it fully sorted.
    I'll try to take a look once I have a chance and the time!

  • cyberealitycybereality Posts: 928Moderator

    I've got that image upload error before, usually when drag/dropping or copy/pasting an image. In those cases, I use the image upload button and it usually works. However, you might have to edit the image first (reduce dimensions or file size) if it is too big.

  • fonofono Posts: 45Member

    The capture screen i've tried to upload is 292 kb saved as jpg.
    Hovever for tracking the strange behaviour inside the audio bus, i should do a video capture.

  • fonofono Posts: 45Member

    Ok, png works fine. For the fx that are changing order, i've simply added another bus before for the fx only. However the busses really seems to have some bugs.

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.