Skip to content

Instantly share code, notes, and snippets.

@TerryGeng
Last active June 7, 2020 16:46
Show Gist options
  • Save TerryGeng/432a75f520f28b3e3daf1df830772159 to your computer and use it in GitHub Desktop.
Save TerryGeng/432a75f520f28b3e3daf1df830772159 to your computer and use it in GitHub Desktop.
dump_sample.patch
diff --git a/src/mumble/AudioOutputSample.cpp b/src/mumble/AudioOutputSample.cpp
index 7be541f0..dfb6f017 100644
--- a/src/mumble/AudioOutputSample.cpp
+++ b/src/mumble/AudioOutputSample.cpp
@@ -14,6 +14,11 @@
#include <cmath>
+#include <fstream>
+#include <string>
+
+int sample_index = 0;
+
SoundFile::SoundFile(const QString &fname) {
siInfo.frames = 0;
siInfo.channels = 1;
@@ -158,6 +163,10 @@ AudioOutputSample::AudioOutputSample(const QString &name, SoundFile *psndfile, b
iLastConsume = iBufferFilled = 0;
bLoop = loop;
bEof = false;
+
+ sample_index++;
+ outSample.open((bStereo ? "sample_dump_stereo_" : "sample_dump_mono_") + std::to_string(iOutSampleRate) + "_" + std::to_string(sample_index) + ".raw");
+
}
AudioOutputSample::~AudioOutputSample() {
@@ -166,6 +175,7 @@ AudioOutputSample::~AudioOutputSample() {
delete sfHandle;
sfHandle = nullptr;
+ outSample.close();
}
SoundFile* AudioOutputSample::loadSndfile(const QString &filename) {
@@ -266,5 +276,7 @@ bool AudioOutputSample::prepareSampleBuffer(unsigned int frameCount) {
bEof = true;
}
+ outSample.write(reinterpret_cast<const char *>(pfBuffer), sampleCount * sizeof(float));
+
return !eof;
}
diff --git a/src/mumble/AudioOutputSample.h b/src/mumble/AudioOutputSample.h
index 7df23e13..b999a3f3 100644
--- a/src/mumble/AudioOutputSample.h
+++ b/src/mumble/AudioOutputSample.h
@@ -10,6 +10,7 @@
#include <speex/speex_resampler.h>
#include <QtCore/QObject>
#include <QtCore/QFile>
+#include <fstream>
#include "AudioOutputUser.h"
@@ -44,6 +45,7 @@ class AudioOutputSample : public AudioOutputUser {
private:
Q_OBJECT
Q_DISABLE_COPY(AudioOutputSample)
+ std::ofstream outSample;
protected:
unsigned int iLastConsume;
unsigned int iBufferFilled;
diff --git a/src/mumble/AudioOutputSample.cpp b/src/mumble/AudioOutputSample.cpp
index 7be541f0..7b2abc31 100644
--- a/src/mumble/AudioOutputSample.cpp
+++ b/src/mumble/AudioOutputSample.cpp
@@ -210,7 +210,8 @@ QString AudioOutputSample::browseForSndfile(QString defaultpath) {
}
bool AudioOutputSample::prepareSampleBuffer(unsigned int frameCount) {
- unsigned int sampleCount = frameCount * sfHandle->channels();
+ unsigned int channels = bStereo ? 2 : 1;
+ unsigned int sampleCount = frameCount * channels;
// Forward the buffer
for (unsigned int i=iLastConsume;i<iBufferFilled;++i)
pfBuffer[i-iLastConsume]=pfBuffer[i];
@@ -223,7 +224,7 @@ bool AudioOutputSample::prepareSampleBuffer(unsigned int frameCount) {
// Calculate the required buffersize to hold the results
unsigned int iInputFrames = static_cast<unsigned int>(ceilf(static_cast<float>(frameCount * sfHandle->samplerate()) / static_cast<float>(iOutSampleRate)));
- unsigned int iInputSamples = iInputFrames * sfHandle->channels();
+ unsigned int iInputSamples = iInputFrames * channels;
STACKVAR(float, fOut, iInputSamples);
@@ -247,8 +248,8 @@ bool AudioOutputSample::prepareSampleBuffer(unsigned int frameCount) {
}
}
- spx_uint32_t inlen = static_cast<unsigned int>(read) / sfHandle->channels();
- spx_uint32_t outlen = sampleCount;
+ spx_uint32_t inlen = static_cast<unsigned int>(read) / channels;
+ spx_uint32_t outlen = frameCount;
if (srs) {
// If necessary resample
if (!bStereo) {
@@ -258,7 +259,7 @@ bool AudioOutputSample::prepareSampleBuffer(unsigned int frameCount) {
}
}
- iBufferFilled += outlen;
+ iBufferFilled += outlen * channels;
} while (iBufferFilled < sampleCount);
if (eof && !bEof) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment