The crash mentioned above is caused by memory/heap corruption in st_resample_flow. In a nutshell, the input file has 1024 samples, but the loop in st_resample_flow computes Xsize to be 4465 so the code walks off the end of the sample buffer (ibuf).
A naive fix to prevent crashes is to limit the loop by the actual number of input samples.
>diff ..\..\pcmenc.cpp pcmenc.cpp 161c161 < int rv = st_resample_flow(effp, ibuf + iLen, obuf + oLen, &idone, &odone); --- > int rv = st_resample_flow(effp, ibuf + iLen, inLen - iLen, obuf + oLen, &idone, &odone); >diff ..\..\resample.c resample.c 268c268 < int st_resample_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, --- > int st_resample_flow(eff_t effp, st_sample_t *ibuf, long cbuf, st_sample_t *obuf, 297c297 < for(i = r->Xread; i < Nx + r->Xread ; i++) --- > for(i = r->Xread; i < Nx + r->Xread && i < cbuf; i++) 396c396 < rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); --- > rc = st_resample_flow(effp, NULL, 0, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); >diff ..\..\st.h st.h 86c86 < int (*flow)(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, --- > int (*flow)(eff_t effp, st_sample_t *ibuf, long cbuf, st_sample_t *obuf, 116c116 < int st_resample_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, --- > int st_resample_flow(eff_t effp, st_sample_t *ibuf, long cbuf, st_sample_t *obuf,
Whether this results in valid output is a separate question. But it does fix the crash.
I should note that in general, this code has a number of alignment issues that may or may not cause crashes depending on the CPU and OS. I didn't spend time addressing them, but a couple jumped out at me: calloc params in wrong order, and using a char buffer to host structure (st_effect) which contains larger fields.
Thanks for explaining,
i did not try my samples on other then audacity, which has no problems with u8 etc
i have in mind that all samples are equaly long, but i will check my 'source' being me on my computer ;-)
thanks for pcmenc anyway
edit:
i tested all vowels on my opensuse 64 bit, but they all work in vlc and they all are u8, 11khz with a length off 1408 to 1414 bytes,
my (old) rersult is OO and UU are 1412b and dont convert while vowel EE is 1414 and does convert and AA is 1412 and converted and from the 1408 byte a,e,o,u,i only e and i converted, thats half only.
But i do notice the size difference and i had in mind i did exact cuts, but apperently not 100%.
Hi,
I get the message that some is not complete
i changed pcmenc.exe to pcmenc2 since there are no *.exe in linux. Maybe its not OS changable??
ch@linux-6n36:~/Desktop/some-zx/dutchvox/pcmenc_msx_source/gcc> g++ pcmenc.cpp resample.c -o pcmenc2 -O2 -Wall In file included from pcmenc.cpp:117:0: st.h:25:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_size_t; ^ st.h:27:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_rate_t; ^ st.h:65:5: error: ‘st_rate_t’ does not name a type st_rate_t rate; /* sampling rate */ ^ st.h:87:17: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:87:35: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:88:49: error: ‘st_size_t’ has not been declared int (*drain)(eff_t effp, st_sample_t *obuf, st_size_t *osamp); ^ st.h:99:5: error: ‘st_size_t’ does not name a type st_size_t odone, olen; /* consumed, total length */ ^ st.h:117:22: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:117:40: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:118:54: error: ‘st_size_t’ has not been declared int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp); ^ pcmenc.cpp: In function ‘double* resample(double*, UInt32, UInt32, UInt32, UInt32*)’: pcmenc.cpp:135:50: warning: narrowing conversion of ‘inRate’ from ‘UInt32 {aka long unsigned int}’ to ‘signed char’ inside { } is ill-formed in C++11 [-Wnarrowing] st_signalinfo_t iinfo = { inRate, 4, 0, swap }; ^ pcmenc.cpp:135:50: warning: narrowing conversion of ‘swap’ from ‘int’ to ‘char’ inside { } is ill-formed in C++11 [-Wnarrowing] pcmenc.cpp:136:51: warning: narrowing conversion of ‘outRate’ from ‘UInt32 {aka long unsigned int}’ to ‘signed char’ inside { } is ill-formed in C++11 [-Wnarrowing] st_signalinfo_t oinfo = { outRate, 4, 0, swap }; ^ pcmenc.cpp:136:51: warning: narrowing conversion of ‘swap’ from ‘int’ to ‘char’ inside { } is ill-formed in C++11 [-Wnarrowing] pcmenc.cpp:142:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] }; ^ pcmenc.cpp:151:26: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] char* argv[] = {"-ql"}; ^ pcmenc.cpp:155:5: error: ‘st_size_t’ was not declared in this scope st_size_t iLen = 0; ^ pcmenc.cpp:155:15: error: expected ‘;’ before ‘iLen’ st_size_t iLen = 0; ^ pcmenc.cpp:156:15: error: expected ‘;’ before ‘oLen’ st_size_t oLen = 0; ^ pcmenc.cpp:159:19: error: expected ‘;’ before ‘idone’ st_size_t idone = ST_BUFSIZ; ^ pcmenc.cpp:160:19: error: expected ‘;’ before ‘odone’ st_size_t odone = ST_BUFSIZ; ^ pcmenc.cpp:161:48: error: ‘iLen’ was not declared in this scope int rv = st_resample_flow(effp, ibuf + iLen, obuf + oLen, &idone, &odone); ^ pcmenc.cpp:161:61: error: ‘oLen’ was not declared in this scope int rv = st_resample_flow(effp, ibuf + iLen, obuf + oLen, &idone, &odone); ^ pcmenc.cpp:161:68: error: ‘idone’ was not declared in this scope int rv = st_resample_flow(effp, ibuf + iLen, obuf + oLen, &idone, &odone); ^ pcmenc.cpp:161:76: error: ‘odone’ was not declared in this scope int rv = st_resample_flow(effp, ibuf + iLen, obuf + oLen, &idone, &odone); ^ pcmenc.cpp:169:15: error: expected ‘;’ before ‘odone’ st_size_t odone = ST_BUFSIZ; ^ pcmenc.cpp:170:36: error: ‘oLen’ was not declared in this scope st_resample_drain(effp, obuf + oLen, &odone); ^ pcmenc.cpp:170:43: error: ‘odone’ was not declared in this scope st_resample_drain(effp, obuf + oLen, &odone); ^ In file included from resample.c:56:0: st.h:25:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_size_t; ^ st.h:27:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_rate_t; ^ st.h:65:5: error: ‘st_rate_t’ does not name a type st_rate_t rate; /* sampling rate */ ^ st.h:87:17: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:87:35: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:88:49: error: ‘st_size_t’ has not been declared int (*drain)(eff_t effp, st_sample_t *obuf, st_size_t *osamp); ^ st.h:99:5: error: ‘st_size_t’ does not name a type st_size_t odone, olen; /* consumed, total length */ ^ st.h:117:22: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:117:40: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:118:54: error: ‘st_size_t’ has not been declared int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp); ^ resample.c: In function ‘int st_resample_start(eff_t)’: resample.c:180:26: error: ‘struct st_signalinfo’ has no member named ‘rate’ if (effp->ininfo.rate == effp->outinfo.rate) ^ resample.c:180:48: error: ‘struct st_signalinfo’ has no member named ‘rate’ if (effp->ininfo.rate == effp->outinfo.rate) ^ resample.c:186:43: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate; ^ resample.c:186:71: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate; ^ resample.c:188:45: error: ‘struct st_signalinfo’ has no member named ‘rate’ gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate); ^ resample.c:188:71: error: ‘struct st_signalinfo’ has no member named ‘rate’ gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate); ^ resample.c:189:29: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->a = effp->ininfo.rate / gcdrate; ^ resample.c:190:30: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->b = effp->outinfo.rate / gcdrate; ^ resample.c:251:21: error: ‘uint32_t’ was not declared in this scope r->Xsize = (uint32_t)(2*Xoff + i/(1.0+r->Factor)); ^ resample.c: At global scope: resample.c:269:22: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp) ^ resample.c:269:40: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp) ^ resample.c: In function ‘int st_resample_flow(eff_t, st_sample_t*, st_sample_t*, int*, int*)’: resample.c:279:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] i = (r->Ysize < *osamp)? r->Ysize : *osamp; ^ resample.c:289:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if ((unsigned long)Nx > *isamp) ^ resample.c: At global scope: resample.c:379:54: error: ‘st_size_t’ has not been declared int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp) ^ resample.c: In function ‘int st_resample_drain(eff_t, st_sample_t*, int*)’: resample.c:396:58: error: ‘st_size_t’ was not declared in this scope rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); ^ resample.c:396:69: error: expected primary-expression before ‘)’ token rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); ^ resample.c:396:90: error: expected primary-expression before ‘)’ token rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); ^ resample.c: In function ‘int st_updateeffect(eff_t, st_signalinfo_t*, st_signalinfo_t*, int)’: resample.c:742:13: error: ‘st_signalinfo_t’ has no member named ‘rate’ if (in->rate != out->rate) ^ resample.c:742:26: error: ‘st_signalinfo_t’ has no member named ‘rate’ if (in->rate != out->rate) ^ resample.c:750:30: error: ‘struct st_signalinfo’ has no member named ‘rate’ effp->ininfo.rate = out->rate; ^ resample.c:750:42: error: ‘st_signalinfo_t’ has no member named ‘rate’ effp->ininfo.rate = out->rate; ^ resample.c:752:31: error: ‘struct st_signalinfo’ has no member named ‘rate’ effp->outinfo.rate = in->rate; ^ resample.c:752:42: error: ‘st_signalinfo_t’ has no member named ‘rate’ effp->outinfo.rate = in->rate; ^ ch@linux-6n36:~/Desktop/some-zx/dutchvox/pcmenc_msx_source/gcc>
I changed st.h as experiment:
by moving the ENDIF a few lines DOWN
#ifndef __GNUC__ typedef signed int int32_t; typedef unsigned int uint32_t; typedef int32_t st_sample_t; typedef uint32_t st_size_t; typedef int32_t st_ssize_t; typedef uint32_t st_rate_t; #endif
now the in my above tread mentioned error log starts a few lines LATEr in st.h
In file included from pcmenc.cpp:117:0: st.h:56:8: error: ‘st_sample_t’ does not name a type static st_sample_t st_gcd(st_sample_t a, st_sample_t b) ^ st.h:66:5: error: ‘st_rate_t’ does not name a type st_rate_t rate; /* sampling rate */ ^ st.h:87:29: error: ‘st_sample_t’ has not been declared int (*flow)(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, ^ st.h:87:48: error: ‘st_sample_t’ has not been declared int (*flow)(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, ^
I DONT write in c/c++ although i did try something a few times
trail on error is not the best road
int32_t etc. are defined in stdint.h for C, and in cstdint for C++. You probably miss this:
#include
somewhere in the includes, as noted by Sepulep in the previous page.
Padding the input file making it longer would have solved...
Sorry, I'm not used to the forum software yet. I meant:
#include <cstdint>
Sorry, I'm not used to the forum software yet. I meant:
#include <cstdint>
Thank you pgimeno , wearing ZX outfit !! but now i get a new error log,
as it comments "This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental,.."
it might be a 'opensuse' clue like 'we do it a little bit different here'. i should try ubuntu or some else to.
I dont want to spoil this tread with long error messages:
ch@linux-6n36:~/Desktop/some-zx/dutchvox/pcmenc_msx_source/gcc> g++ pcmenc2.cpp resample.c -o pcmenc2 -O2 -Wall In file included from /usr/include/c++/4.8/cstdint:35:0, from pcmenc2.cpp:27: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ In file included from pcmenc2.cpp:118:0: st.h:25:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_size_t; ^ st.h:27:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_rate_t; ^
edit:
ok, i red the error message better and i changed the command line code
g++ pcmenc2.cpp resample.c -std=gnu++11 -o pcmenc2 -O2 -Wall
next error not in st.h but in pcmenc which i baptised to pcmenc2, a full error:
ch@linux-6n36:~/Desktop/some-zx/dutchvox/pcmenc_msx_source/gcc> g++ pcmenc2.cpp resample.c -std=gnu++11 -o pcmenc2 -O2 -Wall pcmenc2.cpp: In function ‘double* resample(double*, UInt32, UInt32, UInt32, UInt32*)’: pcmenc2.cpp:136:50: warning: narrowing conversion of ‘inRate’ from ‘UInt32 {aka long unsigned int}’ to ‘st_rate_t {aka unsigned int}’ inside { } [-Wnarrowing] st_signalinfo_t iinfo = { inRate, 4, 0, swap }; ^ pcmenc2.cpp:136:50: warning: narrowing conversion of ‘swap’ from ‘int’ to ‘signed char’ inside { } [-Wnarrowing] pcmenc2.cpp:137:51: warning: narrowing conversion of ‘outRate’ from ‘UInt32 {aka long unsigned int}’ to ‘st_rate_t {aka unsigned int}’ inside { } [-Wnarrowing] st_signalinfo_t oinfo = { outRate, 4, 0, swap }; ^ pcmenc2.cpp:137:51: warning: narrowing conversion of ‘swap’ from ‘int’ to ‘signed char’ inside { } [-Wnarrowing] pcmenc2.cpp:143:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] }; ^ pcmenc2.cpp:152:26: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] char* argv[] = {"-ql"}; ^ In file included from resample.c:56:0: st.h:25:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_size_t; ^ st.h:27:9: error: ‘uint32_t’ does not name a type typedef uint32_t st_rate_t; ^ st.h:65:5: error: ‘st_rate_t’ does not name a type st_rate_t rate; /* sampling rate */ ^ st.h:87:17: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:87:35: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:88:49: error: ‘st_size_t’ has not been declared int (*drain)(eff_t effp, st_sample_t *obuf, st_size_t *osamp); ^ st.h:99:5: error: ‘st_size_t’ does not name a type st_size_t odone, olen; /* consumed, total length */ ^ st.h:117:22: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:117:40: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp); ^ st.h:118:54: error: ‘st_size_t’ has not been declared int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp); ^ resample.c: In function ‘int st_resample_start(eff_t)’: resample.c:180:26: error: ‘struct st_signalinfo’ has no member named ‘rate’ if (effp->ininfo.rate == effp->outinfo.rate) ^ resample.c:180:48: error: ‘struct st_signalinfo’ has no member named ‘rate’ if (effp->ininfo.rate == effp->outinfo.rate) ^ resample.c:186:43: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate; ^ resample.c:186:71: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate; ^ resample.c:188:45: error: ‘struct st_signalinfo’ has no member named ‘rate’ gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate); ^ resample.c:188:71: error: ‘struct st_signalinfo’ has no member named ‘rate’ gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate); ^ resample.c:189:29: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->a = effp->ininfo.rate / gcdrate; ^ resample.c:190:30: error: ‘struct st_signalinfo’ has no member named ‘rate’ r->b = effp->outinfo.rate / gcdrate; ^ resample.c:251:21: error: ‘uint32_t’ was not declared in this scope r->Xsize = (uint32_t)(2*Xoff + i/(1.0+r->Factor)); ^ resample.c: At global scope: resample.c:269:22: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp) ^ resample.c:269:40: error: ‘st_size_t’ has not been declared st_size_t *isamp, st_size_t *osamp) ^ resample.c: In function ‘int st_resample_flow(eff_t, st_sample_t*, st_sample_t*, int*, int*)’: resample.c:279:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] i = (r->Ysize < *osamp)? r->Ysize : *osamp; ^ resample.c:289:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if ((unsigned long)Nx > *isamp) ^ resample.c: At global scope: resample.c:379:54: error: ‘st_size_t’ has not been declared int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp) ^ resample.c: In function ‘int st_resample_drain(eff_t, st_sample_t*, int*)’: resample.c:396:58: error: ‘st_size_t’ was not declared in this scope rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); ^ resample.c:396:69: error: expected primary-expression before ‘)’ token rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); ^ resample.c:396:90: error: expected primary-expression before ‘)’ token rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp); ^ resample.c: In function ‘int st_updateeffect(eff_t, st_signalinfo_t*, st_signalinfo_t*, int)’: resample.c:742:13: error: ‘st_signalinfo_t’ has no member named ‘rate’ if (in->rate != out->rate) ^ resample.c:742:26: error: ‘st_signalinfo_t’ has no member named ‘rate’ if (in->rate != out->rate) ^ resample.c:750:30: error: ‘struct st_signalinfo’ has no member named ‘rate’ effp->ininfo.rate = out->rate; ^ resample.c:750:42: error: ‘st_signalinfo_t’ has no member named ‘rate’ effp->ininfo.rate = out->rate; ^ resample.c:752:31: error: ‘struct st_signalinfo’ has no member named ‘rate’ effp->outinfo.rate = in->rate; ^ resample.c:752:42: error: ‘st_signalinfo_t’ has no member named ‘rate’ effp->outinfo.rate = in->rate; ^ ch@linux-6n36:~/Desktop/some-zx/dutchvox/pcmenc_msx_source/gcc>
I don't know how old your distro is, but it seems to be defaulting to g++-4.8, which is ancient... You need a newer compiler, I think. Or try adding -std=c++11 to the command line .
I don't know how old your distro is, but it seems to be defaulting to g++-4.8, which is ancient... You need a newer compiler, I think. Or try adding -std=c++11 to the command line .
Hi, i just changed the command line while you mentioned it, and it works.
About my distro, opensuse 42.3 with g++ 4.8.5
g++ (SUSE Linux) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
its 5 years old, you are right. i have leap15.1 installed but actualy i 'hate' the over computed way off deciding what i, being 'user' might want to do.
i prefer the simpelness off win 3.11 without any overcalculated hassel from the OS. But i should OR upgrade this g++ or make leap15 do like i want.