bucklespring icon indicating copy to clipboard operation
bucklespring copied to clipboard

The first press of a given key doesn’t play the right sound on a Mac.

Open mwichary opened this issue 8 years ago • 34 comments

Just installed this on a new Mac OS Sierra, on a new Touch Bar MacBook pro.

When I press an alphanumeric key for the first time, I hear the appropriate background noise, but not the main “click” component of the sound. If I press the same key again quickly, I get the expected clicky sound.

Arrow keys seem to exhibit the right behaviour.

I tried all the alternative options available in ~/.alsoftrc, but nothing helped.

mwichary avatar Jun 27 '17 19:06 mwichary

That's funny; if you get the background sound, but not the click, it seems that the start of the first sample is not properly played at startup; maybe there is some kind of issue in OpenAL or Alure on your platform, but I have no clue at this time why this is happening.

I'l keep this issue open, maybe there is someone else who can shed a light on this.

zevv avatar Jun 30 '17 11:06 zevv

I have downloaded the source and attempting some troubleshooting. I'm starting to think the problem is the Mac implementation of openAL. I am experiencing the same symptoms as mwichary. I've sprinkled a few printd around in main.c and mac.c, but so far haven't found a problem. I have also forced the same .wav files to play no matter which key is pressed and it doesn't help, so it doesn't look like a buffer issue. Still looking.

mactexan avatar Aug 12 '17 03:08 mactexan

Does anyone know which OpenAL implementation is used on Mac OS?

zevv avatar Aug 28 '17 06:08 zevv

Has anyone had any luck fixing this? I got so used to bucklespring on linux (thank you zevv ♥️ ), can't live without it now that I've switched to mac :(

roko-p avatar Jul 19 '18 14:07 roko-p

I’m like you. I love Bucklespring on my Linux machines. I’ve found a similar product for the Mac called “Keyclick” ( http://www.sustworks.com/keyclick_pref/index.html http://www.sustworks.com/keyclick_pref/index.html ). It isn’t free, but it is reasonable at $9.99. It installs as a preference pane and works really well with lots of sound options including mouse clicks.

Joe Kelley [email protected] mailto:[email protected] http://www.mactexan.com http://www.mactexan.com/

http://www.mactexan.com/ http://www.mactexan.com/

On Jul 19, 2018, at 07:03, roko-p [email protected] wrote:

Has anyone had any luck fixing this? I got so used to bucklespring on linux (thank you zevv ♥️ ), can't live without it now that I've switched to mac :(

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zevv/bucklespring/issues/60#issuecomment-406287360, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHabLbZZ1LSqxeXtvxiyKOn6On58tdqks5uIJHDgaJpZM4OHFfc.

mactexan avatar Jul 19 '18 16:07 mactexan

Quoting Joe Kelley (2018-07-19 18:15:33)

I’ve found a similar product for the Mac called “Keyclick”. It isn’t free, but it is reasonable at $9.99. It installs as a preference pane and works really well with lots of sound options including mouse clicks.

What, $9.99 you say! I could have been rich! RICH!

zevv avatar Jul 19 '18 16:07 zevv

@mactexan Thank you for the alternative, I've tried KeyClick, not bad, fills a part of the hole in the heart, but definitely not as awesome as bucklespring.

@zevv How much do you ask to try to fix this issue for mac? 💰

roko-p avatar Jul 24 '18 13:07 roko-p

Quoting roko-p (2018-07-24 15:01:10)

@zevv How much do you ask to try to fix this issue for mac? 💰

Well, having a mac would help :)

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 24 '18 13:07 zevv

😄 damn.

roko-p avatar Jul 24 '18 13:07 roko-p

Really, if I had a mac this would have been fixed long ago. I created the mac port on a borrowed machine a long time ago, but unfortunately I don't have that any longer...

My guess is that the audio subsystem goes to some kind of idle state when no sound is playing, and only switches on when there is something to play. The switching on takes a short amount of time, and is a bit too late to play the actual click.

I could try to make a workaround for that by playing silence in the background all of the time, even when no keys are pressed, that might keep the audio driver awake and prevent the problem from happening.

Now that I think if it: having a kind of comfort noise on the background might be a good idea anyway to mask the starting and stopping of the individual samples.

I will see if I can hack something up one of these days.

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 24 '18 15:07 zevv

😍 😍 😍 😍 Sounds very viable! 🤞
Thank you!!!

roko-p avatar Jul 24 '18 15:07 roko-p

I've added a quick test in a branch:

https://github.com/zevv/bucklespring/tree/issue-60-test

This plays a (almost) silent sample in a continuous loop as long as buckle is running - does that solve the issue on the Mac>

zevv avatar Jul 24 '18 17:07 zevv

@zevv Still only the background sound without the main click on first press 😔 ...at least for me.

(To test it, I checked out the issue-60-test, ran make and then sudo ./buckle, not sure if I also should have done something else as well)

roko-p avatar Jul 25 '18 15:07 roko-p

Quoting roko-p (2018-07-25 17:19:09)

@zevv Still only the background sound without the main click on first press 😔 ...at least for me.

Hm, that's nasty, and I have no clue how to fix this then. If I would add leading silence to all individual wav files, we would end up with too much lag for the key presses, which is also unbearable.

My only hope is to wait for someone to show up with openAL experience on the mac, as there might be some tunables somewhere, but without having access to the hardware it is kind of hard for me to fix this...

(To test it, I checked out the issue-60-test, ran make and then sudo ./buckle, not sure if I also should have done something else as well)

Yes, that should do.

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 25 '18 15:07 zevv

Yeah, I understand 😔 ok, let's hope some openAL guru stumbles upon this. Thank you very much for giving it a blind try like that!

roko-p avatar Jul 26 '18 10:07 roko-p

I have a sneaking suspicion that it's because of all of the sample loading, what if we tried just caching the played keys in memory?

Another possible solution would be to load raw PCM instead of WAV files, then (programtically) add X amount of silent samples if it's compiled on a mac.

LunaTheFoxgirl avatar Jul 26 '18 13:07 LunaTheFoxgirl

Quoting Clipsey (2018-07-26 15:52:48)

I have a sneaking suspicion that it's because of all of the sample loading, what if we tried just caching the played keys in memory?

Well, it's not supposed to matter because the playing is only triggered after the sample is loaded - but I can give it a try. I'll hack something up!

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 26 '18 13:07 zevv

Aswell, a thing that could make code consistency; we could compile and link directly to openal-soft, which does support macOS.

LunaTheFoxgirl avatar Jul 26 '18 14:07 LunaTheFoxgirl

Quoting Clipsey (2018-07-26 15:52:48)

I have a sneaking suspicion that it's because of all of the sample loading, what if we tried just caching the played keys in memory?

Please try the preload-samples branch

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 26 '18 14:07 zevv

I do not have my hackintosh on me currently @zevv, so @roko-p could you try the preload-samples branch?

LunaTheFoxgirl avatar Jul 27 '18 11:07 LunaTheFoxgirl

Sorry for the late answer and thank you for the efforts, I've just tried the preload-samples branch, but still the same behaviour (only background sounds except for presses done very shortly after another press)

I haven't asked about the output I get when running make -- this is all normal, right?

cc  -O3 -g -Wall -Werror  -DVERSION=\"1.4.0\" -DPATH_AUDIO=\""./wav"\" -I/usr/local/Cellar/alure/1.2/include -c main.c -o main.o
cc  -O3 -g -Wall -Werror  -DVERSION=\"1.4.0\" -DPATH_AUDIO=\""./wav"\" -I/usr/local/Cellar/alure/1.2/include -c scan-mac.c -o scan-mac.o
cc -g -framework ApplicationServices -framework OpenAL -o buckle  main.o scan-mac.o -L/usr/local/Cellar/alure/1.2/lib -lalure

What is the difference between the background sounds and the actual clicking sounds?

roko-p avatar Jul 29 '18 16:07 roko-p

Quoting roko-p (2018-07-29 18:04:27)

Sorry for the late answer and thank you for the efforts, I've just tried the preload-samples branch, but still the same behaviour (only background sounds except for presses done very shortly after another press)

That's too bad - it seems that the AL implementation on Mac is simply dropping the first few milliseconds of every sample, making it kind of useless for real time audio.

I haven't asked about the output I get when running make -- this is all normal, right?

cc  -O3 -g -Wall -Werror  -DVERSION=\"1.4.0\" -DPATH_AUDIO=\""./wav"\" -I/usr/local/Cellar/alure/1.2/include -c main.c -o main.o
cc  -O3 -g -Wall -Werror  -DVERSION=\"1.4.0\" -DPATH_AUDIO=\""./wav"\" -I/usr/local/Cellar/alure/1.2/include -c scan-mac.c -o scan-mac.o
cc -g -framework ApplicationServices -framework OpenAL -o buckle  main.o scan-mac.o -L/usr/local/Cellar/alure/1.2/lib -lalure

Yes, that's all there is to it. Just two source files to compile...

What is the difference between the background sounds and the actual clicking sounds?

Well, the background sound is just the natural backround noise/hiss of the mic and the environment that is in every sample. I recorder all the keys for approx half a second to capture the reverb and the typical 'clanggg' sound of the springs, but after every sample there is still a bit of background hiss.

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 29 '18 16:07 zevv

Again @zevv we could force bucklespring to use openal-soft, which is free software (and works on mac), we'd have to change the buildfile, but i know that works properly.

LunaTheFoxgirl avatar Jul 30 '18 12:07 LunaTheFoxgirl

Quoting Clipsey (2018-07-30 14:14:21)

Again @zevv we could force bucklespring to use openal-soft, which is free software (and works on mac), we'd have to change the buildfile, but i know that works properly.

But as long as I don't have a mac, you're on your own here. I'd be happy to accept any pull request, though :)

-- :wq ^X^Cy^K^X^C^C^C^C

zevv avatar Jul 30 '18 12:07 zevv

But openal-soft is cross-platform? 😬

roko-p avatar Aug 06 '18 10:08 roko-p

@Member1221 I know C and openAL as much as I speak Swedish (I don't), but what would I have to do if I took this on me, and what do you think how difficult it would be for a web developer?

roko-p avatar Aug 06 '18 10:08 roko-p

You’d have to link the program against OpenAL soft by first compiling and installing openal-soft. Then change the makefile to link to the openal soft version

LunaTheFoxgirl avatar Aug 06 '18 12:08 LunaTheFoxgirl

It does require some knowledge of how makefiles work and such. But shouldn’t be too difficult

LunaTheFoxgirl avatar Aug 06 '18 12:08 LunaTheFoxgirl

Soo... I've installed openal-soft with brew install openal-soft

That produced this output:

==> Downloading https://homebrew.bintray.com/bottles/openal-soft-1.18.2.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/e1/e166ede768b1bdef14b5ae85043e05b34ac6c53e57bb6f73b4fc4b0954f8aab4?__gd
######################################################################## 100.0%
==> Pouring openal-soft-1.18.2.high_sierra.bottle.tar.gz
==> Caveats
openal-soft is keg-only, which means it was not symlinked into /usr/local,
because macOS provides OpenAL.framework.

If you need to have openal-soft first in your PATH run:
  echo 'export PATH="/usr/local/opt/openal-soft/bin:$PATH"' >> ~/.bash_profile

For compilers to find openal-soft you may need to set:
  export LDFLAGS="-L/usr/local/opt/openal-soft/lib"
  export CPPFLAGS="-I/usr/local/opt/openal-soft/include"

For pkg-config to find openal-soft you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openal-soft/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/openal-soft/1.18.2: 30 files, 902KB

...but I am now not sure how to merge that with:

 ifeq ($(OS), Darwin)
  BIN     := $(NAME)
  PKG_CONFIG_PATH := "./mac/lib/pkgconfig" 
  LIBS    += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs alure openal)
  CFLAGS  += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags alure openal)
  LDFLAGS += -framework ApplicationServices -framework OpenAL
  SRC     += scan-mac.c
 else

...to have bucklespring use openal-soft. (that is what I should do, right?)

roko-p avatar Sep 19 '18 15:09 roko-p

 ifeq ($(OS), Darwin)
  BIN     := $(NAME)
  PKG_CONFIG_PATH := "./mac/lib/pkgconfig" 
  LIBS    += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs alure openal)
  CFLAGS  += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags alure -I/usr/local/opt/openal-soft/include)
  LDFLAGS += -framework ApplicationServices -L/usr/local/opt/openal-soft/lib
  SRC     += scan-mac.c
 else

Something like this @roko-p

LunaTheFoxgirl avatar Sep 19 '18 15:09 LunaTheFoxgirl