Skip to content

Commit

Permalink
Replace wavparse with decodebin to enable arbitrary audio files (#28)
Browse files Browse the repository at this point in the history
* Replace wavparse with decodebin to enable arbitrary audio files (not just .wav)

* Replace `stimulus_ref.wav` with `stimulus_ref.flac`

To test parsing of other files than WAV works. Also add a test with ref
and test stimulus reversed to ensure both formats work for both inputs.

* Mention possibility of file format other than WAV in README

---------

Co-authored-by: Manuel <mincequi@web.de>
  • Loading branch information
martinholters and mincequi authored Jul 8, 2024
1 parent ecb8b03 commit 7397e49
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/stimulus_ref.wav filter=lfs diff=lfs merge=lfs -text
test/stimulus_ref.flac filter=lfs diff=lfs merge=lfs -text
test/stimulus_test.wav filter=lfs diff=lfs merge=lfs -text
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SUBDIRS = src doc
EXTRA_DIST=INSTALL.Windows vs/gstpeaq.props \
vs/gstpeaq.vcxproj vs/peaq.vcxproj vs/gstpeaq.sln \
INSTALL.OSX xcode/GstPEAQ.xcodeproj/project.pbxproj \
test/stimulus_ref.wav test/stimulus_test.wav
test/stimulus_ref.flac test/stimulus_test.wav
5 changes: 3 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ for details.
GstPEAQ comes as a GStreamer plugin providing an element named "peaq". The
element has two sink pads, "ref" and "test" for reference and test signal,
respectively. The computed ODG can be obtained by reading the "odg" property.
For the common case that reference and test signal are available as WAV files,
a command line utility "peaq" is provided that can simply be invoked as
For the common case that reference and test signal are available as WAV files
(or in another format readable by GStreamer), a command line utility "peaq" is
provided that can simply be invoked as
peaq [--advanced] {REFFILE} {TESTFILE}
where --advanced chooses the advanced version of the algorithm (the basic
version is used by default), and {REFFILE} and {TESTFILE} give the reference
Expand Down
48 changes: 26 additions & 22 deletions src/peaq.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,22 @@ my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
return TRUE;
}

static void on_pad_added(GstElement *element, GstPad *pad, gpointer data) {
GstElement *sink = (GstElement *)data;
GstPad *sinkpad = gst_element_get_static_pad(sink, "sink");
gst_pad_link(pad, sinkpad);
gst_object_unref(sinkpad);
}

int
main(int argc, char *argv[])
{
gdouble odg, di;
GError *error = NULL;
GOptionContext *context;
GOptionGroup *option_group;
GstElement *pipeline, *ref_source, *ref_parser, *ref_converter, *ref_resample,
*test_source, *test_parser, *test_converter, *test_resample, *peaq;
GstElement *pipeline, *ref_source, *ref_decodebin, *ref_converter, *ref_resample,
*test_source, *test_decodebin, *test_converter, *test_resample, *peaq;
gchar *reffilename;
gchar *testfilename;

Expand Down Expand Up @@ -156,11 +163,6 @@ main(int argc, char *argv[])
puts ("Error: filesrc element could not be instantiated");
exit (2);
}
ref_parser = gst_element_factory_make ("wavparse", "ref_wav-parser");
if (!ref_parser) {
puts ("Error: wavparse element could not be instantiated");
exit (2);
}
g_object_set (G_OBJECT (ref_source), "location", reffilename, NULL);
ref_converter = gst_element_factory_make ("audioconvert", "ref-converter");
if (!ref_converter) {
Expand All @@ -172,16 +174,18 @@ main(int argc, char *argv[])
puts ("Error: audioresample element could not be instantiated");
exit (2);
}
ref_decodebin = gst_element_factory_make("decodebin", "ref_decodebin");
if (!ref_decodebin) {
puts("Error: decodebin element could not be instantiated");
return 2;
}
g_signal_connect(ref_decodebin, "pad-added", G_CALLBACK(on_pad_added), ref_converter);

test_source = gst_element_factory_make ("filesrc", "test_file-source");
if (!test_source) {
puts ("Error: filesrc element could not be instantiated");
exit (2);
}
test_parser = gst_element_factory_make ("wavparse", "test_wav-parser");
if (!test_parser) {
puts ("Error: wavparse element could not be instantiated");
exit (2);
}
g_object_set (G_OBJECT (test_source), "location", testfilename, NULL);
test_converter = gst_element_factory_make ("audioconvert", "test-converter");
if (!test_converter) {
Expand All @@ -193,18 +197,22 @@ main(int argc, char *argv[])
puts ("Error: audioresample element could not be instantiated");
exit (2);
}
test_decodebin = gst_element_factory_make("decodebin", "test_decodebin");
if (!test_decodebin) {
puts("Error: decodebin element could not be instantiated");
return 2;
}
g_signal_connect(test_decodebin, "pad-added", G_CALLBACK(on_pad_added), test_converter);

gst_bin_add_many (GST_BIN (pipeline),
ref_source, ref_parser, ref_converter, ref_resample,
test_source, test_parser, test_converter, test_resample,
ref_source, ref_decodebin, ref_converter, ref_resample,
test_source, test_decodebin, test_converter, test_resample,
peaq,
NULL);
gst_element_link (ref_source, ref_parser);
gst_element_link (ref_parser, ref_converter);
gst_element_link(ref_source, ref_decodebin);
gst_element_link (ref_converter, ref_resample);
gst_element_link_pads (ref_resample, "src", peaq, "ref");
gst_element_link (test_source, test_parser);
gst_element_link (test_parser, test_converter);
gst_element_link(test_source, test_decodebin);
gst_element_link (test_converter, test_resample);
gst_element_link_pads (test_resample, "src", peaq, "test");

Expand All @@ -220,12 +228,8 @@ main(int argc, char *argv[])
g_printf ("Distortion Index: %.3f\n", di);

gst_object_unref (peaq);

g_main_loop_unref (loop);

gst_deinit ();

return 0;
}


10 changes: 9 additions & 1 deletion src/runtest-1.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ if [ x$ODG != x-2.007 ]; then
fi

ODG=`LC_ALL=C ./peaq --gst-disable-segtrap --gst-debug-level=2 --gst-plugin-load=.libs/libgstpeaq.so \
${srcdir}/../test/stimulus_ref.wav ${srcdir}/../test/stimulus_test.wav \
${srcdir}/../test/stimulus_ref.flac ${srcdir}/../test/stimulus_test.wav \
| grep "Objective Difference Grade:" | cut -d " " -f4`
echo $ODG
if [ x$ODG != x-1.077 ]; then
exit 1
fi
ODG=`LC_ALL=C ./peaq --gst-disable-segtrap --gst-debug-level=2 --gst-plugin-load=.libs/libgstpeaq.so \
${srcdir}/../test/stimulus_test.wav ${srcdir}/../test/stimulus_ref.flac \
| grep "Objective Difference Grade:" | cut -d " " -f4`
echo $ODG
if [ x$ODG != x-3.096 ]; then
exit 1
fi

exit 0
3 changes: 3 additions & 0 deletions test/stimulus_ref.flac
Git LFS file not shown
3 changes: 0 additions & 3 deletions test/stimulus_ref.wav

This file was deleted.

9 changes: 8 additions & 1 deletion vs/runtest-win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ if ($ODG -ne -2.007) {

$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\win32\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\win32\Release\gstpeaq.dll " + `
"$PSScriptRoot\..\test\stimulus_ref.wav $PSScriptRoot\..\test\stimulus_test.wav") `
"$PSScriptRoot\..\test\stimulus_ref.flac $PSScriptRoot\..\test\stimulus_test.wav") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -1.077) {
throw "$ODG -ne -1.077"
}
$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\win32\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\win32\Release\gstpeaq.dll " + `
"$PSScriptRoot\..\test\stimulus_test.wav $PSScriptRoot\..\test\stimulus_ref.flac ") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -3.096) {
throw "$ODG -ne -3.096"
}
9 changes: 8 additions & 1 deletion vs/runtest-x64.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ if ($ODG -ne -2.007) {

$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\x64\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\x64\Release\gstpeaq.dll " + `
"$PSScriptRoot\..\test\stimulus_ref.wav $PSScriptRoot\..\test\stimulus_test.wav") `
"$PSScriptRoot\..\test\stimulus_ref.flac $PSScriptRoot\..\test\stimulus_test.wav") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -1.077) {
throw "$ODG -ne -1.077"
}
$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\x64\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\x64\Release\gstpeaq.dll " + `
"$PSScriptRoot\..\test\stimulus_test.wav $PSScriptRoot\..\test\stimulus_ref.flac ") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -3.096) {
throw "$ODG -ne -3.096"
}

0 comments on commit 7397e49

Please sign in to comment.