-
-
Notifications
You must be signed in to change notification settings - Fork 20.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audio Recording from godot #15967
Audio Recording from godot #15967
Conversation
931e16e
to
27e5184
Compare
@@ -0,0 +1,101 @@ | |||
/*************************************************************************/ | |||
/* audio_effect_record.cpp */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the */
in line on both files.
Thanks for contributing! Very nice feature. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks for spotting it quickly
27e5184
to
03c2afe
Compare
Aaah I thought it was for recording with a mic ^^" |
How do you change the output format ? |
The output format is raw audio (no format really). In order to play it with a media player you have to encode it to a real format. |
I like the idea, but I wonder if how it is useful when building a game. But maybe you have a good counter-example. ^^ |
The original intention of this were to use it for pre-rendered cutscenes created in the godot engine (using the --fixed-fps and --disable-render-loop flags and using a GD-script to save frames). |
Memory allocation and IO in audio threads is forbidden, you should probably use a ringbuffer for this and write in another thread. Also, we should expose AudioEffect via GDNative, so you can do this without needing to modify core godot. |
Being able to write AudioEffects using GDNative would be awesome :D |
I have moved the IO to a separate thread and instead buffered the Audio as requested. Also the recording audio effect now creates a header in the file so that we get valid (though completely uncompressed) .wav files. I am not sure if there isn't a better way of dealing with creation of the thread though. Optimally it should only be started when beginning a new recording, but i am not sure if it is allowed to start the thread from within the Audio thread. |
a4a791d
to
ff2bb19
Compare
83842c9
to
d80bb24
Compare
I have rebased the PR to adhere to the guidelines. Also the audio is now saved as uncompressed .wav files instead of raw audio. |
@SaracenOne is working on something similar that also includes audio input. Holding off on this one to see how both mix, if they do. |
@reduz It should be fine I think. As per what we discussed, my microphone code is only interested in trying to get microphone input from the audio driver into an audio stream, and then ultimately into the mixer where we can do things with it. |
After discussion, probably a more desired functionality would be to just record to an AudioStreamSample, and eventually add a function to it to save to a wav file. This way we can use it together with the new option to record from microphone |
c2b9574
to
caa01ad
Compare
@reduz PR has been updated in an attempt to implement it like the desired functionality. PR description has been updated as well. |
@@ -509,6 +509,34 @@ PoolVector<uint8_t> AudioStreamSample::get_data() const { | |||
return pv; | |||
} | |||
|
|||
void AudioStreamSample::save_to_wav(String path) { | |||
// float sample_rate = AudioServer::get_singleton()->get_mix_rate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind amend the first commit to remove/not add the commented out code? (You can leave a stub with a TODO comment if you want though.)
//Read from the buffer into file | ||
_io_store_buffer(); | ||
//Update the header | ||
//_create_wav_header(ring_buffer_pos); //The ring_buffer_pos will be consistent with the amount of frames written |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New commented out code here, should it be removed or fixed?
@@ -509,6 +511,76 @@ PoolVector<uint8_t> AudioStreamSample::get_data() const { | |||
return pv; | |||
} | |||
|
|||
void AudioStreamSample::save_to_wav(String p_path) { | |||
if (format == AudioStreamSample::FORMAT_IMA_ADPCM) { | |||
printf("Saving IMA_ADPC samples are not supported yet\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use WARN_PRINTS
to issue a proper warning (it takes a String, with no need for newline character at the end).
There seems to be a build issue on Android: https://travis-ci.org/godotengine/godot/jobs/407176455 (you might need to press the "Raw log" button if it doesn't show up) |
I will look into those that build issue. It seems to be linked to the fact that i made |
That's up to you, but I think it makes sense to have two commits, once for implementing the audio recording feature, and one for implement the save to WAV. |
3b04390
to
c1f6808
Compare
Implements an Audio bus effect that outputs the audio from the bus into a wav file Now channels audio recording into an AudioStreamSample instead of saving to wav
8 and 16 bit sample saving has been implemented.
c1f6808
to
adb43b6
Compare
Recommended changes have been applied, and the Android build issue resolved |
Awesome, thanks! |
This pull request implements an Audio bus effect, that outputs the audio from the bus into a raw audio file.
I implemented this since i needed it myself but figured i would put it up as a PR in case it could be useful for others.
Potential use case examples:
[edit]
As per the suggestions, the functionality has been changed in the following ways
The audio effect now records into a buffer that a user can get an AudioStreamSample object from.
AudioStreamSample formats supported are 8-bit and 16-bit PCM, as well as IMA_ADPCM
Additionally a function has been added to AudioStreamSample that allows the user to save it as a WAV file.
Supported formats for saving as WAV are 8-bit and 16-bit PCM