From f69febfd71a4bd1e9420844cef603f4256a0c098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Wed, 22 Jan 2020 13:50:27 -0300 Subject: [PATCH] Add `.wav` support for sound recording. WAV is also set to be the default extension for audio recording. --- src/common/ffmpeg.cpp | 22 ++++++++++++++++++---- src/wx/cmdevents.cpp | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/common/ffmpeg.cpp b/src/common/ffmpeg.cpp index 1b366912..6c2cd315 100644 --- a/src/common/ffmpeg.cpp +++ b/src/common/ffmpeg.cpp @@ -12,7 +12,8 @@ struct supportedCodecs { const supportedCodecs audioSupported[] = { { AV_CODEC_ID_MP3, "MP3 (MPEG audio layer 3)", "mp3" }, - { AV_CODEC_ID_AAC, "ADTS AAC (Advanced Audio Coding)", "aac,adts" } + { AV_CODEC_ID_AAC, "ADTS AAC (Advanced Audio Coding)", "aac,adts" }, + { AV_CODEC_ID_PCM_S16LE, "WAV / WAVE (Waveform Audio)", "wav" } }; const supportedCodecs videoSupported[] = { @@ -120,7 +121,7 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream() } } } - if (!isSupported) return MRET_ERR_NOCODEC; + if (!isSupported && acodec->supported_samplerates) return MRET_ERR_NOCODEC; aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout); aenc->channel_layout = AV_CH_LAYOUT_STEREO; if (acodec->channel_layouts) @@ -143,7 +144,10 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream() return MRET_ERR_BUFSIZE; // number of samples per frame if (aenc->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) - nb_samples = 10000; + { + //nb_samples = 10000; // can be any value, but we use our aud buffer size + nb_samples = 1470; + } else nb_samples = aenc->frame_size; // audio frame for input @@ -552,6 +556,16 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int int realLength = length / sizeof *aud; bool isMissing = false; int cp = -1; + + if (c->frame_size == 0) // no compression/limit for audio frames + { + int maxCopy = realLength; + memcpy(audioBuffer + posInAudioBuffer, aud, maxCopy * 2); + posInAudioBuffer += maxCopy; + samplesInAudioBuffer += (maxCopy / 2); + aud += maxCopy; + } + if (samplesInAudioBuffer < c->frame_size) { int missingSamples = (c->frame_size - samplesInAudioBuffer); @@ -568,7 +582,7 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int cp = realLength - maxCopy; } } - if (samplesInAudioBuffer != c->frame_size) // not enough samples + if (samplesInAudioBuffer != c->frame_size && (c->frame_size > 0 || samplesInAudioBuffer != realLength)) // not enough samples { return MRET_OK; } diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index 75b08721..796b9ceb 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -1197,7 +1197,7 @@ EVT_HANDLER_MASK(RecordSoundStartRecording, "Start sound recording...", CMDEN_NS ext.Replace(wxT(","), wxT(";*.")); ext.insert(0, wxT("*.")); - if (sound_extno < 0 && ext.find(wxT("*.mp3")) != wxString::npos) + if (sound_extno < 0 && ext.find(wxT("*.wav")) != wxString::npos) sound_extno = extno; sound_exts.append(ext);