9 ms·
Looping Music Seamlessly
- zwegner 7y agoMinor correction: the graph of the PCM data is displaying the data as unsigned instead of signed, so it has lots of discontinuities between ~0 and ~64k. Though, for the sake of showing the data as "raw", I guess it doesn't matter too much.
- saagarjha 7y agoRelated, but I was looking for an audio format that could embed these loop points inside of it so the file would be small but play infinitely. Is there anything "standard" that does this? I looked into WAV and AIFF, which seem to have "cue" points, but they don't seem to quite do what I want…
- Intermernet 7y agoThe "standard" is unfortunately (as far as I can determine) not open source, but it is an "open" standard. The REX2 file format from Propellerhead is documented somewhere at https://www.reasonstudios.com/developers https://www.reasonstudios.com/developers but you will need to sign up for a developer account. I'm pretty sure it's free to use, and it's supported by most serious DAWs. >"REX2 is a proprietary type of audio sample loop file format developed by Propellerhead, a Swedish music software company. It is one of the most popular and widely supported loop file formats for sequencer and digital audio workstation software. It is supported by PreSonus Studio One, Propellerhead Reason, Steinberg Cubase, Steinberg Nuendo, Cockos REAPER, Apple Logic, Digidesign Pro Tools, Ableton Live, Cakewalk Project5, Cakewalk Sonar, Image-Line FL Studio, MOTU Digital Performer, MOTU Mach 5 (software sampler), and Synapse Audio Orion Platinum, among others." https://en.wikipedia.org/wiki/REX2 https://en.wikipedia.org/wiki/REX2
- saagarjha 7y agoIdeally I'd be able to play this on an iPod :(
- Intermernet 7y agoThat's up to the media player (with standard WAV / AIFF etc). If it buffers the file and respects cue points, you should be able to have seamless playback, but very few media players get this 100% correct. See https://en.wikipedia.org/wiki/Gapless_playback https://en.wikipedia.org/wiki/Gapless_playback for mroe details.
- codetrotter 7y agoWhat are we meant to look for on that Wikipedia article page, and how does it relate to looping? The article says nothing about cue points as far as I can see.
- tempwaveinfo 7y agoJust because you have loop points defined doesn't automatically mean that every player will be able to process them in a seamless way.
- codetrotter 7y agoI responded to a sibling comment here with some more details about what I was wondering about: https://news.ycombinator.com/item?id=21384082 https://news.ycombinator.com/item?id=21384082 Basically, what I was wondering about was rather, even though that article tells us which players support gapless playback, it doesn't say which players support loop points.
- Intermernet 7y agoLooping (with normal WAV files etc) is gapless playback. You can get almost perfect looping if you use buffering. The wikipedia article is basically just illustrating that, to do looping on an iPod (as requested) you would just require sample accurate wav files, and a media player that supported gapless playback.
- codetrotter 7y ago
- tempwaveinfo 7y agoDid something change about their licensing? At least up until recently I remember that Propellerheads applied proprietary licensing terms and requiring every developer to be associated with a company for any of their third-party stuff including REX and ReWire.
- Intermernet 7y agoI think you're probably correct. They had a press release in 2004 talking about "opening" the format. It's a bit of a let down to tell the truth. "In the past, major Developers such as Steinberg and Emagic applied for and obtained a license to support REX playback in their applications. Now as an open format, any manufacturer, large or small, can support REX playback in their applications. Third-party manufacturers are encouraged to download REX2 developer documentation. Implementing the Propellerheads REX2 file format in other applications or hardware is free of charge. Further information about the REX2 file format is available at http://www.propellerheads.se/developer" http://www.propellerheads.se/developer" https://www.reasonstudios.com/press/21-propellerhead-software-opens-rex2-file-format-playback-to-third-party-manufacturers https://www.reasonstudios.com/press/21-propellerhead-softwar... A bit more info at https://www.reasonstudios.com/developer/index.cfm?fuseaction=get_article&article=rextechinfo https://www.reasonstudios.com/developer/index.cfm?fuseaction... EDIT: Speeling
- tempwaveinfo 7y agoWAV has also the info you need, in the "smpl" (Sampler information) chunk. You can also embed this into FLAC files as foreign metadata of type "riff". Reference: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/RIFFNEW.pdf http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Do...
- yyx 7y agoAlso see: http://infinitejukebox.playlistmachinery.com/ http://infinitejukebox.playlistmachinery.com/ https://eternalbox.dev/jukebox_index.html https://eternalbox.dev/jukebox_index.html
- M4v3R 7y agoI use mpv commandline tool to play music in a loop, seamlessly. You open an audio file, press “l” (lowercase L) at the starting point, then use arrow keys to go to the and point and press “l” again. That’s it. The only problem is to press the keys precisely at a music bar boundary, but with enough practice you can get pretty close so the seam is barely noticeable or not noticeable at all.
- evan_ 7y agoThere’s a great app for iOS called snesmusic which lets you download videogame music from a bunch of consoles including Nintendo 64 and play it straight through or looped endlessly using the “real” loop points. You can download music from within the app, and it’s all ripped directly from the ROMs. The playback sounds pretty accurate to my ears.
- PikachuEXE 7y agoDoes it work with GBA?
- joosters 7y agoWhat is a 'frame' in terms of PCM audio? If the raw data is just measures of amplitude at a set frequency, don't you have to pick an arbitrary time slice to examine (and so risk losing lower-frequency sounds)?
- tmpfs 7y agoA frame is a function of the encoding frequency and bit depth, these both determine how many raw PCM samples consititute a "frame".
- tmpfs 7y agoOops, and number of channels too!
- anon9001 7y ago> What is a 'frame' in terms of PCM audio? Sometimes people in the audio world use "frame" to mean "set of PCM samples per channel". So a typical stereo audio signal at 44100hz would be 44100 "frames" per second, even though it's really 88200 samples per second. The author seems to be using it that way, but it's confusing because he's also talking about sliding a FFT window over by frames. > If the raw data is just measures of amplitude at a set frequency LPCM is literally amplitude samples at a rate. Thinking of the sample rate as a 'set frequency' will lead to confusion (even though it obviously is a frequency). When you're thinking of samples as sequential amplitudes, you're thinking in the "time domain". For oscillations of the signal, that's the called the "frequency domain". Fourier transform is how you convert from time domain to frequency domain. > don't you have to pick an arbitrary time slice to examine (and so risk losing lower-frequency sounds)? You need at least 2 samples to make an audible frequency. If you only had 1 sample, you wouldn't hear anything, because nothing would be moving. So at 44100hz of sampling frequency, you can capture 0hz to 22050hz of audio frequency. That's called the Nyquist frequency, and it's always half of the sample rate.
- fdsa_889876 7y ago> You need at least 2 samples to make an audible frequency. That's not strictly true. An audio file with a single non-zero sample (usually set to full amplitude) is often used for testing -- usually called a Dirac impulse or similar. That impulse will be (necessarily) band-passed by the playback hardware and put out filtered "white" noise. That impulse can be recovered by a mic to show e.g., pre-ringing caused by (FIR) filters. An FFT of that impulse will show the playback hardware's response in the frequency domain vs full bandwidth. > Thinking of the sample rate as a 'set frequency' For e.g., a WAV file, that's a fixed number of samples per second (a frame being 1 sample x n channels). That is a set frequency, and deviating from it will alter the pitch of the music. There really is no case where sample rate varies, unless we're talking about minute variations between the clock signals of different hardware, which requires the use of sample rate conversion to match. A related concept is the bits-per-second of lossy formats (e.g., AAC) which may vary from frame to frame (and that frame will mean something different from a WAV frame). > You need at least 2 samples to make an audible frequency. I think you're confusing this with Nyquist being 1/2 of the sampling frequency. You can very much capture an audible signal with a single sample, but that signal will be limited (by hardware, by Nyquist, etc). [Edit] I should say that this single sample has to be non-zero and the playback system has to have a DC-offset that isn't equal to that sample's amplitude.
- thekegsi 7y agoCould you pick a frame of audio and then cross correlate it with the entire song? The peaks of the cross correlation should indicate when the segment of audio repeats, i.e. potential loop points.
- mosselman 7y agoCool and nicely illustrated article. It is also funny to me because in secondary school (high school) I used to edit certain songs manually in order to create x-hour versions of them. I'd manually look for repeat-points and just copy paste pieces of the song in Audacity (an audio editor). At some points people at school came to me asking if I could make multiple-hours versions of songs for them.
- rosstex 7y agoDid you have a YouTube channel? I used to do this and post them!
- mosselman 7y agoThat is cool! Back when I did this either YouTube didn't exist yet, or it wasn't a thing yet. So I never posted them. I probably would have worried about copyright things as well.
- rcthompson 7y agoReminds me of when I ripped the Ace Combat 4 and Ace Combat 5 soundtracks off the game DVDs. I forget the details, but basically it was possible to stick the DVD in a computer and play part it as ADPCM data and record it. The result was one big recording consisting of all the music tracks separated by short bursts of very loud static. The static was presumably the track metadata, which I didn't know how to decode, but it sure made it easy enough to find the track boundaries. In AC4, each mission's music was already looped out to the length of the mission (e.g. if the mission timer was 13 minutes, then the song was looped as many times as needed to go over 13 minutes), so I just had to find approximately where the first or second loop ended and fade it out after that to make an appropriate-length "album" version of the track. For AC5, there were a lot more missions, so I guess they didn't have the disc space to do this and had to get creative. Instead, each track cut off exactly at the loop point, so in order to make it loop and fade, I had to find the point near the beginning that it was meant to loop back to, copy the track, and manually line up that point with the end of the track and do a short cross-fade to hide the seam. Then I could fade it out a few seconds into the second loop to complete the "album" version. I believe at some point they released official OST albums for both games, but a few special tracks were missing from both, so my versions are slightly more complete. (Specifically, the AC4 OST was missing the version of the hangar music for the final mission that included someone giving a speech over the loudspeaker, while AC5 was missing the track of everyone singing together over the radio in the penultimate mission.)
- rosstex 7y agoOh man, this takes me back! I used the Echonest library and made a GUI interfacef or it in Max/MSP for a class back in undergrad... good times. https://www.youtube.com/watch?v=DL8vJO05DCs https://www.youtube.com/watch?v=DL8vJO05DCs
- BLKNSLVR 7y agoSemi-related and possibly not adding much other than an additional anecdote to the concept, but this is a full continuous album that loops from the end back to the beginning: https://en.wikipedia.org/wiki/Nonagon_Infinity https://en.wikipedia.org/wiki/Nonagon_Infinity I happen to like the music as well.
- guggle 7y ago[insert xkcd411 here]
- deleted 7y ago[deleted]
- klodolph 7y agoIf you’re going to do autocorrelation, why not just do it on the audio signal? Why go through all the trouble of doing a FFT on the input signal and extracting notes first? Just to give more details—you can do autocorrelation using the FFT. Autocorrelation is done by calculating the convolution of a signal with a reversed copy of itself. Convolution in the time domain is multiplication in the frequency domain. So you take the FFT, do a pointwise multiplication, and then reverse FFT. The loop points will be spikes in the result. There are some additional factors you will likely want to consider, like windowing, but this is a much more straightforward way to do things. (As an aside, I would probably put the G in the third measure on the left hand.)
- MadWombat 7y ago> If you’re going to do autocorrelation, why not just do it on the audio signal? Because audio signal is very sparse. On a decent quality file you have 41K or 48K samples per second and you need a window of at least half a second to pick a looping point.
- klodolph 7y agoAudio signals are not sparse at all, unless you are using a definition of “sparse” that I’m unfamiliar with. I also don’t understand your complaint about the looping point, or window size. If you don’t understand how autocorrelation works, I can provide some pseudocode to demonstrate the technique. This is not an esoteric or unusual way of finding a looping point.
- MadWombat 7y agoI might be misusing "sparse". What I meant was that in a sufficiently high sample rate music, there are a lot of samples between notes and a lot of the samples are noise and garbage. I do understand how autocorrelation works, to a reasonable degree. And that is the reason for the DFT. We are talking music, so we care about the frequencies more than about the immediate sample value. And the window is important because autocorrelating over individual data points is useless, sound signals are noisy and you get a lot of randomness. Also, I tried the code provided on a few pieces I thought would be appropriate and it didn't do a very good job. I might run a few experiments.
- AndrewStephens 7y agoThis takes me back to my days creating Amiga modules, desperately trying to find places in the samples that I could set the loop points so they wouldn't click annoyingly. I didn't have access to Fourier transformations back then, I would just keep setting the loop points in likely looking places and hope no-one would notice the pop.
- tenebrisalietum 7y agoSheesh even the Akai S1000 at the time had a crossfade option to blend the edges.
- AndrewStephens 7y agoThere may have been better options but I was 15 and didn't know anything. Unlike now, where I am 44 and don't know anything.
- sambe 7y agoMaybe iOS 13 should pay attention (single-track loops often stutter at the end).
- rmcclellan 7y agoAwesome project! As a professional audio developer, I was really blown away that this was the author's first project working with audio. For anyone interested, I'd recommend checking out "The Infinite Jukebox", which has a similar goal, but perhaps a more robust approach: http://infinitejukebox.playlistmachinery.com http://infinitejukebox.playlistmachinery.com If I had to guess at why your approach didn't work well on recorded music, it's probably because most of the time, there is more than a single event happening at a time, so picking out just the highest FFT bin is probably not a very robust "fingerprint" of that part of the music. The infinite jukebox uses timbral features as the fingerprint, rather than just a single note.
- michaelmior 7y agoThanks for the pointer to The Infinite Jukebox! It's impressive how well it does. It's biggest point of failure seems to be jumping to different parts of a verse or chorus and mixing up bits of lyrics. It makes that this would happen, but it would be really interesting to see what could be done to avoid this.
- tux1968 7y agoIt's a shame you can no longer upload music to the InfiniteJukebox. Apparently it relied on a Spotify API that was shut down October 1st. Best hope going forward is an open source library that can offer the same track analysis that used to be provided by that API.
- johnsoft 7y agoThe API was an Echo Nest API. Spotify acquired Echo Nest and shut down all their APIs in 2016. I'd love to see the app live on too! Spotify's API has similar functionality[1] to the old Echo Nest API, for now at least. (But I don't know if it returns all the same data.) Or, if you don't want to rely on Spotify, I bet Essentia[2][3] could do the job just as well. Essentia is the open-source brains behind AcousticBrainz[4]. So you could either use Essentia directly, or grab the data from the AcousticBrainz API. [1] https://developer.spotify.com/documentation/web-api/reference/tracks/get-audio-analysis/ https://developer.spotify.com/documentation/web-api/referenc... [2] https://github.com/MTG/essentia https://github.com/MTG/essentia [3] https://essentia.upf.edu/documentation/essentia_python_examples.html https://essentia.upf.edu/documentation/essentia_python_examp... [4] https://acousticbrainz.org/ https://acousticbrainz.org/
- deleted 7y ago[deleted]
- kenrick95 7y ago> This happened a few months ago to BrawlBRSTMs, one of the first accounts to do it for a lot of music tracks, and people were devastated. You can still access their website https://www.smashcustommusic.com/ https://www.smashcustommusic.com/ through the Internet Archive and can still download the BRSTM files that they use to generate those videos. BRSTM file is an audio file format that has loop points encoded in it[1]. Of course, you'll need a special program to play and loop it, like BrawlBox[2] or a web-based one that I created few months ago[3]. [1] https://wiibrew.org/wiki/BRSTM_file https://wiibrew.org/wiki/BRSTM_file [2] https://github.com/libertyernie/brawltools https://github.com/libertyernie/brawltools [3] https://github.com/kenrick95/nikku https://github.com/kenrick95/nikku
- beefhash 7y agoOn a related note: I've noticed that ffmpeg supports the BCSTM format, which has built-in loop points (unsurprisingly, since it's used for video game music). ffmpeg decodes and stores that information. mpv however doesn't take advantage of that. That's mildly unfortunate.
- EarthlyFireFly 7y agoBeware - the power of music isn't innocent: http://www.earthlyfireflies.org/government-use-of-music-to-influence-obedience/ http://www.earthlyfireflies.org/government-use-of-music-to-i.... And here we had an interesting discussion on LinkedIn of its influences: http://www.earthlyfireflies.org/linkedin-dialogue-on-music/ http://www.earthlyfireflies.org/linkedin-dialogue-on-music/.