hydrogen-music / hydrogen

The advanced drum machine for Linux, macOS, and Windows
http://www.hydrogen-music.org
GNU General Public License v2.0
1.06k stars 173 forks source link

Playback-Track: Wrong speed for 48000 Hz #670

Closed desperateCoder closed 4 years ago

desperateCoder commented 5 years ago

Hydrogen version * : 1.0.0-beta1 Operating system + version : 3.16.0-7-amd64 #1 SMP Debian 3.16.59-1 (2018-10-03) x86_64 GNU/Linux Audio driver + version : PulseAudio 5.0


Hi, I was struggling over getting my playback to get tight to my grooves (see issue "playback offset"). I finally was able to find out, what went wrong, and i think it's a bug: The recording guy gave me his exported files at 48000 Hz. This leads to faster playback somehow, like 5 to 10 BPM faster (maybe see issue #37 ?)

what i did to resolve: sox myFancyFile.wav -r 44100 fancyFileWithRightTempo.wav this changes the Sample rate down to 44100 Hz, which gave me the constant right speed. This took me a couple of weeks to find out and drove me really crazy, since my old recordings ran like a charm (all @ 44100 Hz)

By the way, this happened also with the current master, i built HEAD and had the same result (except the fancy new colors :D )

Maybe you guys have a look at that? A quick win would be just showing a warning dialogue as a low hanging fruit, but in long term it would be nice if H2 would play it just like VLC does.

Thanks in advance and sorry for complainig so much :D

trebmuh commented 5 years ago

@desperateCoder : so, if I get it right, you're asking if Hydrogen could resample the playback-track?

desperateCoder commented 5 years ago

@trebmuh Not at all, it just should respect the sample rate of the playback as it plays, even if the drum-track has a different rate. Resampling could be a possible solution, but who am I to tell you what would be the best :grin:

All I'm saying is that a playback not matching the project sample rate results in pure chaos.

Did this clarify my problem?

theGreatWhiteShark commented 5 years ago

You have a valid point. I encountered this problem before too. But with another software and I would really liked to have some warning popping up.

Luckily checking the sample rate without converting it is something libsndfile can handle. We actually already do this in line 166 of the sample.cpp. I will introduce it to the playback-track as well including a pop-up for mismatches.

trebmuh commented 5 years ago

Did this clarify my problem?

Yes it does, thank you.

mauser commented 5 years ago

Hi everyone,

just stumbled upon this issue because of pullrequest #727 by @theGreatWhiteShark , who did a lot of work to implement the warning/error message when the sample rate does not match.

Maybe i understand sth. wrong, but Hydrogen is able to resample samples on the fly. This works for "normal" samples (and has worked for a long time), but it should also work for the playback-track (the resampling code is in Sampler::processPlaybackTrack). I've tested it some minutes ago with a 192khz flac file (and comparing that to flac files at lower sample rates). I've also deactived the re-sampling code which results in a drastic difference when listening to the 192khz flac. So this gives me the impression that at least for some situations, the resampling does work. For me it would be more interesting to understand why it does not work for @desperateCoder . I have the impression that mabye that bug would be easier to fix then to detect it as an error.

@desperateCoder : Could you check the files "Arnesen: MAGNIFICAT 4. Et misericordia" at 192khz / 96khz flac from http://www.2l.no/hires/ ? That's what i'm using here for audio testing, don't ask me why. Classic is not my style of music :) It would be interesting if the problem appears for you also with this files.

If the problem persists, the next would be to switch to another audio driver. Maybe you could try it with the alsa driver?

desperateCoder commented 5 years ago

Hi @mauser, sure, I'll try it as soon as I can, maybe this weekend, and I'll also verify the problem still persists, since I recently upgraded my OS to LMDE 3.

Can you tell me the BPM of the track so I can easily verify the "bug"?

Thanks in advance, and thanks for your help!

theGreatWhiteShark commented 5 years ago

@mauser Hmm, I missed this. Definitely a feature worth documenting. (The manual only hints at the interpolate resampling parameter in the settings. But I did not checked it beforehand since it does not cover the playback track at all)

@desperateCoder I will try to reproduce your issue with a couple of playback tracks during the next days

desperateCoder commented 5 years ago

@theGreatWhiteShark in case I can reproduce the issue, I'll upload my track somewhere for you guys.

desperateCoder commented 5 years ago

@theGreatWhiteShark ok then, i just tested one of my tracks again and the problem still persists. I uploaded them for you here: https://nextcloud.knecht.rocks/index.php/s/EnzXcCkYZbYw4jX This song is at 75 BPM, since i use a custom drumkit, you could maybe just make a quarters bassdrum loop forever to check if the BPM of the playback differs. Alternatively i added the drumkit and the h2song file to the share folder. The one working well for me is 44100 and the 48000 differs. Note, that there is silence at the beginning of the tracks, just in case you wonder :grin:

Please don't judge the music, i'm not claiming to be a good musican :laughing:

@mauser i tried your suggested tracks, but i had a hard time to figure out the BPM of them. it is approximately at 58, but not sure. Anyways, it seems to work well with the flac file. Although i didn't manage to get the beat really tight, i'd say they are most probably identical despite the sample rate. Maybe we should try it with an other song with a more significant beat and BPM?

Version information: Hydrogen 1.0.0-beta1 Linux Mint Debian edition 3 uname -a: 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1 (2019-04-12) pulseaudio 10.0

Note: I pulled the current master and i am now at commit c756049551652b27d001bb01783ee8d6714a0313 I then started the binary built by my old LMDE2 machine and the terminal printed Hydrogen 1.0.0-beta1 [Oct 27 2018]

Do i have to recompile the current master? I currently don't have set up the toolchain for compiling it, cmake woldn't be the problem, the QT-libs and other dependencies would (would be nice to know, what packages i'd need without having to find out by trial and error, maybe include them to the INSTALL.md file?) The version from the repo is 9.7.0 btw, it doesn't seem to have the playback-track feature yet.

theGreatWhiteShark commented 5 years ago

I can reproduce this issue with on current master:

  1. Start jackd with a sample rate of e.g. 48000Hz
  2. Create a very simplistic beat, like just four quarters of snare hits
  3. Capture the output with your favorite audio recorder/DAW, e.g. non-timeline
  4. Close Hydrogen and restart jackd with another sample rate, like 44100Hz
  5. Create the same beat in H2 and use the previous recording as playback track

I tried several combinations: 44,1, 48, and 94KHz with 120, 40, and 200 bpm and the resampling of H2 is always off by such a margin it is unusable. When I, instead, use sox for resampling, everything is perfectly aligned (at least for the ~10s snippets I produced).

I'll try to take a look at the resampling algorithm during the next weeks.

@desperateCoder Don't worry, you won't get judged ;)

We actually do already have an INSTALL.md file. You can find all dependencies listed in there.

mauser commented 4 years ago

@desperateCoder : I believe that this bug is fixed now, the root of the problem is that i made a very dumb math error in the implementation of the resampling code :)

I hope that i can work on other Playback track related bugs / oddities in the next days, so that the features gets a bit more usable for the release of Hydrogen 1.0.

mauser commented 4 years ago

Hi,

@desperateCoder : There are now also some other PlaybackTrack goodies available in the master branch:

mauser commented 4 years ago

I'm going to close this ticket since the original bug is now fixed. If something does not work with other aspects of the Playback track, just mention it!

desperateCoder commented 4 years ago

@mauser that's awesome! I just didn't want to handle two play buttons manually, now this is a full grown and fully integrated feature! Thank you so much for your effort!