Generating sound signals

97 views
Skip to first unread message

Alexandru

unread,
Sep 10, 2021, 8:48:42 AMSep 10
to
Hi,

After searching the web I found the Tcl package SNACK https://www.speech.kth.se/snack/download.html, that I could use the generate a sound signal (sinus shaped and wanted frequency).

On the other side, the project seems to be dead.
Are there other packages out there for sound signal generation.

Also interesting would be to generate superposed sound signals.

Many thanks
Alex

Scott Pitcher

unread,
Sep 10, 2021, 8:28:10 PMSep 10
to
On Friday, September 10, 2021 at 10:48:42 PM UTC+10, Alexandru wrote:
> After searching the web I found the Tcl package SNACK https://www.speech.kth.se/snack/download.html, that I could use the generate a sound signal (sinus shaped and wanted frequency).
>
> On the other side, the project seems to be dead.
> Are there other packages out there for sound signal generation.

I used Snack recently for making a "Pitch Pipe" Android app for tuning my guitar. It certainly works and ought to do what you want.

Alexandru

unread,
Sep 11, 2021, 6:37:38 AMSep 11
to
Thanks for the input.
That's good news.
Alexandru

Alexandru

unread,
Sep 20, 2021, 7:40:18 AMSep 20
to
scotty...@gmail.com schrieb am Samstag, 11. September 2021 um 02:28:10 UTC+2:
I tried to run snack on Windows 10 64bit and it fails with

couldn't load library "C:/Tcl/lib/snack2.2.10/libsnack.dll": Bad exe format. Possibly a 32/64-bit mismatch.

Does this mean I must compile from source?

Scott Pitcher

unread,
Sep 20, 2021, 4:58:51 PMSep 20
to
On Monday, September 20, 2021 at 9:40:18 PM UTC+10, Alexandru wrote:
> I tried to run snack on Windows 10 64bit and it fails with
>
> couldn't load library "C:/Tcl/lib/snack2.2.10/libsnack.dll": Bad exe format. Possibly a 32/64-bit mismatch.

Ok yes that looks to be true. I'm working on Windows 7 and it looks like 32 bit.

(bin) 2 % parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = intel
tcl_platform(os) = Windows NT
tcl_platform(osVersion) = 6.1
tcl_platform(pathSeparator) = ;
tcl_platform(platform) = windows
tcl_platform(pointerSize) = 4
tcl_platform(threaded) = 1
tcl_platform(user) = scottyw
tcl_platform(wordSize) = 4
(bin) 3 %

Scott Pitcher

unread,
Sep 20, 2021, 6:08:57 PMSep 20
to
The tcl/tk on my Linux system is 64 bit and Snack is available.

scotty@workshoppc:~$ wish
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = x86_64
tcl_platform(os) = Linux
tcl_platform(osVersion) = 4.20.17-042017-generic
tcl_platform(pathSeparator) = :
tcl_platform(platform) = unix
tcl_platform(pointerSize) = 8
tcl_platform(threaded) = 1
tcl_platform(user) = scotty
tcl_platform(wordSize) = 8
% package require snack
2.2
%

Over on Windows I'm building a 64 bit version of TclTk 8.6.10 using mingw64. I've got the snack source so I'll see if I can build and run it with a 64 bit wish.

Ralf Fassel

unread,
Sep 21, 2021, 12:10:00 PMSep 21
to
* Scott Pitcher <scotty...@gmail.com>
| Over on Windows I'm building a 64 bit version of TclTk 8.6.10 using
| mingw64. I've got the snack source so I'll see if I can build and run
| it with a 64 bit wish.

We're building snack on Windows for both 32bit and 64bit,
with msys/configure and MSVC 2019. We fiddle with the generated
Makefiles a bit (replace -I/c/some/path by -Ic:/some/path, -ltclstub by
tclstub.lib etc via sed), so it should be feasible with mingw, too.

R'

Scott Pitcher

unread,
Sep 21, 2021, 8:06:14 PMSep 21
to
On Wednesday, September 22, 2021 at 2:10:00 AM UTC+10, Ralf Fassel wrote:
> We're building snack on Windows for both 32bit and 64bit,
> with msys/configure and MSVC 2019. We fiddle with the generated
> Makefiles a bit (replace -I/c/some/path by -Ic:/some/path, -ltclstub by
> tclstub.lib etc via sed), so it should be feasible with mingw, too.

Ah, thanks Ralf. That's good to know. I had a couple of problems building that I had to patch around
1. KSDATAFORMAT_SUBTYPE_PCM redeclared in win/jkAudIO_win.c.
2. roundf() defined locally in generic/jkFormatMP3.c
3. Link errors with Tcl_SeekOld and Tcl_TellOld. These seem to be #undefined in Tcl 8.6 so I used the same definition as for TCL_MINOR_VERSION < 4 in jSound.h.

So then it would build although with plenty of warnings. But then it seg faults in jkFormatMP3.c. But it does this for both the 32 and 64 bit builds.

Thread 1 received signal SIGSEGV, Segmentation fault.
layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
2873 for (ch=0;ch<ext->nch;ch++) requantize_mono(ext, gr,ch,&info,header);
1: x/3i $pc
=> 0x39a45a0 <ReadMP3Samples+7904>: movl $0x0,(%rax)
0x39a45a6 <ReadMP3Samples+7910>: add $0x4,%rax
0x39a45aa <ReadMP3Samples+7914>: jmp 0x39a45a0 <ReadMP3Samples+7904>
Value can't be converted to integer.
(gdb) backtrace full no-filter
#0 layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873

Now, there was a warning from gcc when compiling this module:

gcc -g -O2 -O2 -fomit-frame-pointer -DHAVE_STDINT_H -IC:/Users/scottyw/Desktop/src/tcltk/tcltk-build/tcl8.6.9/generic -I/c/Users/scottyw/Desktop/src/tcltk/tcltk-build/tk8.6.9/generic -I/c/Users/scottyw/Desktop/src/tcltk/tcltk-build/tk8.6.9/xlib -I/mingw/dx6/include -I../win/../generic -DWIN -DUSE_TCL_STUBS -DUSE_TK_STUBS -DBUILD_snack -DTCL_81_API -c -o jkFormatMP3.o ../win/../generic/jkFormatMP3.c
../win/../generic/jkFormatMP3.c: In function 'requantize_mono':
../win/../generic/jkFormatMP3.c:774:26: warning: iteration 18 invokes undefined behavior [-Waggressive-loop-optimizations]
774 | ext->xr[ch][0][l]=FRAS2(ext->is[ch][l],a);
| ^
../win/../generic/jkFormatMP3.c:773:13: note: within this loop
773 | while (l<36) {
| ^

I decided to remove the -O2 optimisation from the Makefile, and I rebuilt the 32 bit version, and now it runs. The test I am using is a desktop stopwatch I use for metering our tasks in the workshop. It plays an MP3 at the alarm time and I use snack for this.

I'm still having a problem with a seg fault at the same place in the 64 bit version. I've turned off optimisaton with -O0 but I'm not sure this is working:

Thread 1 received signal SIGSEGV, Segmentation fault.
layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
warning: Source file is more recent than executable.
2873 if (header->mode!=1 || (header->mode==1 && header->mode_extension==0))
1: x/3i $pc
=> 0x3ab45a0 <ReadMP3Samples+7904>: movl $0x0,(%rax)
0x3ab45a6 <ReadMP3Samples+7910>: add $0x4,%rax
0x3ab45aa <ReadMP3Samples+7914>: jmp 0x3ab45a0 <ReadMP3Samples+7904>
(gdb) backtrace full no-filter
#0 layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
rest = <optimized out>
gr = <optimized out>
tmp = <optimized out>
fs = <optimized out>
hsize = <optimized out>
ch = 0
sb = <optimized out>
i = <optimized out>
mean_frame_size = <optimized out>
bitrate = <optimized out>
ssize = <optimized out>
cnt = <optimized out>
info = {main_data_begin = 15, scfsi = {{0, 0, 0, 0}, {0, 0, 0, 0}},
part2_3_length = {{940, 0}, {0, 0}}, big_values = {{107, 0}, {0,
0}}, global_gain = {{177, 0}, {0, 0}}, scalefac_compress = {{
223, 0}, {0, 0}}, window_switching_flag = {{1, 0}, {0, 0}},
block_type = {{3, 0}, {0, 0}}, mixed_block_flag = {{0, 0}, {0, 0}},
table_select = {{{15, 6, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}}},
subblock_gain = {{{0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}}},
region0_count = {{0, 0}, {0, 0}}, region1_count = {{0, 0}, {0, 0}},
preflag = {{0, 0}, {0, 0}}, scalefac_scale = {{1, 0}, {0, 0}},
count1table_select = {{0, 0}, {0, 0}}, error = {0, 0}}
gr = <optimized out>
ch = <optimized out>
sb = <optimized out>
i = <optimized out>
tmp = <optimized out>
mean_frame_size = <optimized out>
bitrate = <optimized out>
fs = <optimized out>
hsize = <optimized out>
ssize = <optimized out>
cnt = <optimized out>
rest = <optimized out>
win_type = <optimized out>
l = <optimized out>
l = <optimized out>

Scott Pitcher

unread,
Sep 21, 2021, 8:15:37 PMSep 21
to
Sorry, I'll correct that. After removing the old library from the Tcl/lib directory (I'd mistakenly renamed it with -old suffix but Tk was still picking it up), I ran my test and it passes. It's plays an MP3 file. So after turning off optimisation I am able to build and run both 32 and 64 bit builds. More work needs to be done to work out what level of optimisation will work and why, but it does work. I havn't tried Snack's tests yet either.

Alexandru would you like a copy of the -64 bit library to test?

Alexandru

unread,
Sep 21, 2021, 8:16:56 PMSep 21
to
scotty...@gmail.com schrieb am Mittwoch, 22. September 2021 um 02:15:37 UTC+2:
> Sorry, I'll correct that. After removing the old library from the Tcl/lib directory (I'd mistakenly renamed it with -old suffix but Tk was still picking it up), I ran my test and it passes. It's plays an MP3 file. So after turning off optimisation I am able to build and run both 32 and 64 bit builds. More work needs to be done to work out what level of optimisation will work and why, but it does work. I havn't tried Snack's tests yet either.
>
> Alexandru would you like a copy of the -64 bit library to test?
Hi Scotty,

of course. Thank you!

Scott Pitcher

unread,
Sep 21, 2021, 9:35:00 PMSep 21
to
I've put a copy of the 64 bit binary library on my Google Drive as snack2.2.10-Windows-amd64-debug-no_opt.tar.gz.

It's compiled without optimisation and with debug symbols.

Link: https://drive.google.com/file/d/1xuLFPS1sR-vrwMyRq3H_bYwLB3Sk2HCJ/view?usp=sharing

Alexandru

unread,
Sep 22, 2021, 1:15:49 AMSep 22
to
Works for me!
I tested this:

set f [snack::filter generator 440.0 30000 0.0 sine 8000]
set s [snack::sound]
$s play -filter $f

Ralf Fassel

unread,
Sep 22, 2021, 4:33:20 AMSep 22
to
* Scott Pitcher <scotty...@gmail.com>
| On Wednesday, September 22, 2021 at 2:10:00 AM UTC+10, Ralf Fassel wrote:
| > We're building snack on Windows for both 32bit and 64bit,
| > with msys/configure and MSVC 2019. We fiddle with the generated
| > Makefiles a bit (replace -I/c/some/path by -Ic:/some/path, -ltclstub by
| > tclstub.lib etc via sed), so it should be feasible with mingw, too.
>
| Ah, thanks Ralf. That's good to know. I had a couple of problems
| building that I had to patch around
--<snip-snip>--
| 3. Link errors with Tcl_SeekOld and Tcl_TellOld. These seem to be
| #undefined in Tcl 8.6 so I used the same definition as for
| TCL_MINOR_VERSION < 4 in jSound.h.

Ah, yes, now that you mention it...

I regularly patch the TCL sources to re-enable Tcl_TellOld and Tcl_SeekOld:

--- tcl8.6.11/generic/tclDecls.h.orig 2016-03-01 02:59:21.000000000 +0100
+++ tcl8.6.11/generic/tclDecls.h 2016-03-01 11:06:03.388180928 +0100
@@ -3866,8 +3866,10 @@
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

+#if 0
#undef Tcl_SeekOld
#undef Tcl_TellOld
+#endif

#undef Tcl_PkgPresent
#define Tcl_PkgPresent(interp, name, version, exact) \

Diff finished. Wed Aug 16 11:27:00 2017

| So then it would build although with plenty of warnings. But then it
| seg faults in jkFormatMP3.c. But it does this for both the 32 and 64
| bit builds.

*Blush* since we don't require mp3 in snack, we disable mp3 (for the
exact problem you encountered) by removing it from the list of file
formats.

Plus another patch which also resulted in SEGVs:

*** snack2.2.10/generic/jkSoundEngine.c~ Wed Dec 1 15:23:46 2004
--- snack2.2.10/generic/jkSoundEngine.c Tue Jun 14 11:56:19 2005
***************
*** 1694,1700 ****

if (soundQueue != NULL) {
for (p = soundQueue; p != NULL && p->sound != s; p = p->next);
! if (p->sound == s) {
n = p->startPos + p->nWritten;
}
}
--- 1694,1700 ----

if (soundQueue != NULL) {
for (p = soundQueue; p != NULL && p->sound != s; p = p->next);
! if (p && p->sound == s) {
n = p->startPos + p->nWritten;
}
}

HTH
R'

Scott Pitcher

unread,
Sep 22, 2021, 7:12:30 AMSep 22
to
On Wednesday, September 22, 2021 at 6:33:20 PM UTC+10, Ralf Fassel wrote:

> Plus another patch which also resulted in SEGVs:
>
> *** snack2.2.10/generic/jkSoundEngine.c~ Wed Dec 1 15:23:46 2004

Thanks for the additional patch :).

I might place the code on Github where it can be kept "alive".
Reply all
Reply to author
Forward
0 new messages