Friday, November 30, 2007

copyright questions

[Where I say "can I" below, I'm asking not just about the current law in your region, but also whether you think someone has the moral right to do those things, whether the law should allow them.]

I buy a movie on DVD.

Do I have the right to watch it in the DVD drive of my PC?

Can I copy the DVD data onto my hard drive and watch the DVD from there? Perhaps my DVD drive doesn't play back smoothly.

What if I have to use software that breaks copy protection in order to copy it to my hard drive?

Can I make a compressed file of the DVD to watch on my PC? This saves hard drive space.

Can I download the DVD data from a friend who also bought it? Maybe my DVD drive is broken.

Via anonymous download?

Can I keep the data on my hard drive after I'm done watching?

Can I make a physical DVD copy for backup?

If my DVD is destroyed in a fire, do I have the right to download it?

If it is stolen but presumably still exists and might be watched?

If I also claim the loss on my insurance?

If I ordered a DVD but it hasn't arrived, can I download it?

If I preorder a DVD but it isn't out yet, and the movie is available online, can I download it?

If I'm going to buy a DVD, but it isn't available for preorder, and the movie is available online, can I download it?

Can I use an audio clip from the movie and make a ringtone for my phone?

Can my spouse watch the DVD on the TV while I watch the data on my PC?

Can I load my DVD to a friend?

Can I loan it if I also have a backup?

Can I watch my backup while it is loaned?

What if I call my friend to make sure they're not watching it at the same time?

What if my friend watches the loaned DVD at the same time I'm watching the backup?

Can I watch the DVD at my house with guests?

Can I stream the movie over the internet in order to watch with friends in other places?

Can I download subtitles in another language and overlay them with software?

Can I make a customized DVD with the extra subtitles and watch that?

If I translate the subtitles myself can I give them to a friend who also bought the DVD?

Can I upload the translated subtitles to a website for others to download?

Can I make a customized DVD which skips the menu and auto-plays the movie?

Can I make a customized DVD which skips parts of the movie? I want a kid-safe version.

Can I make a creative re-edit of the movie with scenes out of order?

Can I make a DVD with a wild re-edit, a custom musical soundtrack, and humorous replacement dialogue?

If not, can I watch the original DVD while music plays in the room, skip chapters at will, and joke about it with my friends?

Friday, November 16, 2007

Keep periodic unix processes from messing up your gigs

Sometimes while performing or working on audio/video, my hard disk activity light goes crazy. Top shows updatedb, makewhatis, and similar tasks running. With a well-tuned low-latency/realtime kernel the audio process should continue without dropouts... and indeed with the current ccrma kernels audio is fairly stable. But media access from disk can be slowed down (at least until preemption is perfected), and there's no need to be trying your luck. Keep the system load more constant and predictable by temporarily

These periodic (hourly/daily/monthly) processes are controlled by crond (old-school) and anachrond (new-school). Before a gig, run the following two commands as root:

[root@localhost]~# service crond stop
[root@localhost]~# service anacron stop

They'll be running again after a restart, which should be fine. Or run the above commands with "start" in place of "stop".

BTW, "service --display-all" gives a handy rundown of available services and prints detailed stats for some.

Thursday, November 8, 2007

Casio PG-380 program change

The Casio PG-380 midi guitar, and midi guitars in general, can be great interfaces. In fact, it's my interface of choice for my main music project. But the PG-380's interface for MIDI Program Change is baffling.

There is a 2-LED display which shows the current program. But this does not display the program in binary, octal, hex, or decimal. Rather it displays hexal, the low half of octal values but counting from 1; each LED displays 3 bits, counting from 1, with values 1-8. Apparently the designers thought counting from 0 would be confusing, but didn't go all the way making it display proper decimal (counting from 0 or 1) The default program, binary/decimal 0 according to MIDI spec, is displayed as "11": each of the 3-byte units is 0, so the LED displays two 1s. 11-18 progress as expected, representing MIDI decimal 0-7. The next program, represented with as a decimal 8 (9th program counting from 0) in MIDI spec is displayed as "21"... to reconstruct their logic, the binary representation is 00001000 grouping it into the 3-bit units that drive the LED's yields 00 (001) (000) which is 0 (1) (0). But Casio thinks 0s are confusing, so they add one to each and display "21". There are 8 buttons for entering the program, labeled 1-8. The labeling corresponds to the LED display; each represents 3 bits, counting from 0. The first press sets the the "high" unit, bits[3-5] the second press sets the lowest 3 bits. The maxium program, decimal 63 binary 00111111 grouped (00) (111) (111) equivalent to (0) (7) (7) is displayed as "88".

Phew! Translating between the the displayed values and the actual equivalent bytes is an obnoxious ordeal that slows down creation of MIDI binding patches. The display logic is too tied to the underlying binary system, but oddly they didn't go to decimal, counting from 0 or 1. Instead it sits in-between, with its own unique mapping scheme between the displayed value and the actual MIDI byte. Although I'm not an expert on old MIDI hear, I've never seen another piece of gear using this odd scheme. I imagine there is some other Casio gear from the era which displays in a similar way. Horribly non-intuitive and cumbersome.

Wednesday, June 6, 2007

upgrading fedocra 4 ccrma to 6

followed the yum upgrade procedure found by google. my biggest mistake was not upgrading to kernel > .14 before installing the rpm which changed the system and repositories to 5... it is mentioned (bottom of FAQ) that earlier kernels are incompatible with base RPM's.

Screw that, use a core 6 install DVD. Upgrade went smoothly, except that it replaced grub.conf!

Installed fedora 6 ccrma base. Installing ccrma-apps failed because of file conflicts... some packages, notable ladspa plugins, changed their name from version 4, and yum doesn't know to remove them. Installed apps in small batches, manually removing rhfc4.ccrma packages that conflicted (wasn't brave enough to remove *.rhfc4)

eventually i was able to install planetccrma-apps without error

used rpm -qai | grep rhfc4 to find packages eligible for update... even things as core and jack hadn't been upgraded to fc6! jack was particularly exciting because the upgrade pulled in freebob (firewire audio) support

the trickiest bit was
Transaction Check Error: file /usr/lib/libsndfile.so.1 from install of libsndfile-1.0.17-1.fc6 conflicts with file from package libsndfile1-1.0.13-7.rhfc4.at

because the package name changed from libsnd1 to libsnd. rather than force it, i removed libsndfile1, which removed a total of 58 audio packages. i put the list in a file to make sure i didn't lose anything

yum install planetccrma-apps again, pulled in the new libsndfile and a total of 53 packages

yum-update failed with file conflicts on kernel-headers, I didn't want to deal with it so I installed the rest in batches of a few dozen, nearly everything installed without conflict

my ipw2200 card broke, dmesg showed error -2 when installing firmware. i installed ipw2200-firmware packages and it worked again after restart

installing ntfs-g3 gave me ntfs support

Tuesday, June 5, 2007

Cloning lvm partition and booting from it

Problem: when bit-for-bit cloning a partition with a LVM system root results in duplicate physical volume ID's, and it is not possible to select which partition to boot into.

g4l partition clone hda2 into hda3

boot, will complain of duplicate PV ID but should load one of hda2/3

use vgscan to figure out which partition is in use (my case hda2)

edit /etc/lvm/lvm.conf find filter section and change filter to the following (my case, reject hda3):
filter = [ "r/hda3/", "a/.*/" ]

that will get rid of the warnings post-boot. to gain control over which is used at boot time, have to modify initrd. google "modify initrd", when you have it extracted edit its etc/lvm/lvm.conf as above. when you repack the img, name it _ignorehda3. put it into /boot/ next to the original.

do the same for _ignorehda2

edit grub.conf, copy the default/preferred option and paste it twice. change initrd to _ignorehda3 and _ignorehda2, give them nice display names such as "Original on hda2" and"Clone on hda3" respectively.

It is actually possible to change the uuid of the physical volume of the backup using pvchange -u, so that you can mount the backup. It is unclear whether this impacts your ability to boot off the backup.

Thursday, March 1, 2007

GDAM: time access

Once the beat (tempo and phase) of a song has been mapped via the Beat Calculator, time access can be very sophisticated. A number of these techniques seem to still be unique to GDAM, I am giving the descriptions here in hopes that all software might offer these powerful features.

Basic precision: position math is done inside the audio thread with sample accuracy. Although file playback may not start immediately(eg hard drive takes time to spin up), the server can keep track of how far behind it falls, and dump a little data to catch up... this makes the song start in synch regardless of file access/encoder delay.

Seeking smoothly: When seeking a song, it starts a new copy at the desired position. While that starts up, the current copy keeps playing. Once the new copy has started, data is dumped to make up for the small startup delay, a quick crossfade occurs, and the old copy is discarded. This keeps position seeks smooth while honoring the *exact* timing of the request.

Relative seeking: relative seeking is requested by the client, often seeking by an amount of time which is precisely calculated from the BPM to be an even number of beats. The jump is executed using the smooth seek functionality to keep sample accuracy. The medium-scale seek buttons seek anywhere from 1 to 32 beats forwards or backwards. Because the audio engine accounts for startup delay, the beat is *perfectly* maintained when relative seeking in this way. This gives incredible control over playback of the song... press "back 4 beats" every four beats, and you are looping a perfect bar. Because you are seeking by an amount, rather than to a position, you can time the jump however you want (at any point in the bar not just at an even bar boundary) while keeping the beat.

Jumping to any point in song while keeping beat: the client has an approximate idea of where song playback is... not sample accurate, but within 1/10th of a beat. The user can click on any point in a song, and jump there without dropping the beat. The client calculates the difference between where playback is and where you want it to be, rounds that difference to an even number of beats or bars, then issues a relative seek in that amount. This opens up music to be completely time-accessible, rearranged at will in real time, without dropping the beat.

Index points: When beatmatching, you can go beyond simple tempo and phase information, and add index points at certain places within the songs such as verse, chorus, breakdown, outro. These are clearly marked in the timeline, and you can jump to them in beat. When i'm playing a hip-hop song, I'll cut every chorus to half size and skip over the guest verse. I can edit a song down to just the meaty core, or do long remixes by extending each instrumental moment into 8 bars of beat juggling and effects.

Sub-beat time access: this is usually used to nudge a song into synch with another audio source. There is a ruler representing one beat, click anywhere along it to seek an amount between 1/2 beat back to 1/2 beat foward. The closer to the ruler's center mark, the smaller the seek. When I hear my song playing out of synch, I know from the rhythmic relationship (1/4 or 1/16 beat ahead or behind) where on the ruler to click. This allows me to instantly correct, rather than nudging it incrementally or guessing how far to seek.

Video Playback: volume compression

I live in an apartment, the walls are thin, and I enjoy my TV and movies late at night. The dynamic range is way too high, some dialogue is barely audible at full volume but sudden action explodes in a frantic dive for the volume control. Volume normalization can mitigate this somewhat at extreme settings, but it is imprecise and inaccessible.

A better model: interactive volume mode, simple controls which adjust expander / compressor / limiter to intuitively adjust dynamics. If I can't hear the dialogue, I indicate "too quiet". This boosts the input volume or otherwise adjust the dynamics to boost quiet parts. After the first car crash, I indicate "too loud". This looks at the maximum output volume during the last 10 seconds, and adjusts the compressor/limiter to guarantee that nothing will produce output louder than 90% of that. The system would quickly be tuned to the content and my environment.

Wednesday, February 28, 2007

HID

The Human Interface Device standard for USB devices is great. The obvious appeal of using them as controllers: there are a huge number of cheaply available keyboard, mice, trackpads, joysticks, jog wheels, etc, all of which can be understood without individual drivers. However using them as controllers is not straightforward because most audio software does not accept joystick input, and mice and keyboards just duplicate the normal mouse and keyboard.

In Linux, I wrote a GDAM input plugin for reading USB HID events. USB events show up on /dev/input/event* (if you have your kernel configured correctly, but these days it seems to be the default) The event interface is also great: you get 3 bytes, the first is event type (button vs axis vs relative etc) second is index (256 of each type max per device) 3rd is value. Implementing the OSX version involved many lines of dynamically allocating objects based on how big they were in the current version of OS.... linux was dead simple.

Recently revisiting some HID controllers, they were less convenient than MIDI. In particular, if I unplug the device /dev/input/eventN disappears and I get read errors. If I replug I have to reopen device. So I made a HID -> MIDI driver for linux. It hotplugs, and any USB HID device plugged in becomes a virtual ALSA MIDI port. So far I'm translating key and button presses, and absolute values (faders, analog joysticks) into MIDI notes and CC's. I haven't decided the best way to translate relative (mouse, touchpad) events into MIDI, there is no clear match. I refuse to convert to absolute by driving a virtual CC because that would be limiting. I may send note on with different velocities, or set CC value for each relative event but those are non-standard uses.

Now, using qjackctl's patchbay to automatically restore MIDI routing, I can replug my HID controllers at will without doing a thing in software. Instead of working through a plugin specific to my software, the MIDI can be used with any software or even sent over a MIDI cable to drive hardware.

I made a quick GDAM binding file to make the MIDI notes correspond to qwerty layout. My laptop keyboard may or may not be implemented via USB, but it does show up in /dev/input/event* so I can run my driver on it. Now all my typing is rendered rhythmically and melodically. I've enjoyed some of the riffs that emerged while I code, newlines and braces resolve nicely.

GDAM: scratching

Scratching in GDAM is based on the Bender plugin - an inline filter which keeps a large buffer of audio and allows playback at any speed, backward or forward, from any point in the buffer. If you are familiar with the Buffer Override VST filter, I am told it uses this technique.

Bender plugin can manage the input to the buffer in various ways; it can keep the input at full speed, advance only when needed, or even drop bars of music to keep playing in beat, without making progress through the song.

Scratching in GDAM allows the user to set certain cuepoints in the audio stream, and jump to them, while playing backward or forward at any pitch. The ability to teleport between point in the audio stream breaks a major limitation of vinyl scratching: to get from one part of a sample to another, the vinyl DJ has to move the needle along the groove. To get there fast, the record spins fast and the sample plays at a higher pitch. The scratch DJ may selectively mute parts of the scratch to obscure some of the "incidental" pitch, but there is noneless a very rigid relationship between where in the sample you can be, how fast you are moving through the sample and what the pitch is at any moment.

GDAM's ability to jump to marks within the sample allows different parts of a sample to be played back-to-back in a way that is impossible in vinyls. On top of Bender, it is even possible to switch seamlessly into timestretching and pitch shifting, breaking the speed/pitch relationship. In theory a bit like going from pushing a car on a flat track to flying uninhibited through 3d space.

Another technique is to take timestretching to the extreme that position does not progress forward or backward on its own. It plays a microloop of the current position, and you can drag the playhead back and forth while changing the pitch independently. You can do a record stall in place by fading pitch down to 0, scratch back and forth at any consistent pitch, and all kinds of other tricks impossible with vinyl.

For MIDI control for scratching I like to use the pitchbend wheel - pulling it towards me to rewing and pushing it away from me to play > 100% speed. A nice thing about the pitch bend wheel is that it returns to its detente position when you remove your hand, in the same way that a record returns to full turntable speed when you remove your hand from it.

So of course pitchbend 0 always mapped to 100% speed. But I have a number of different mappings for the rest of pitchbend range. The two most common are 1) pulling back from detent slows from 100% to stalled then increases to -200% or -400% at pitchwheel full back 2) pulling back from detente instantly trigger 0% and from there increases to -400%. 1) gives a snappier scratch, 2) is useful if you want to stall a record but GDAM also offers plugins which do this perfectly so it didn't get as much use.

Although I've often dropped a bit of scratching into sets and demos, I never really spent time developing routines and pushing the limits of what is possible.

STC-1000

Another promising device, a pressure-sensitive Kaoss Pad without the audio circuitry or flashing lights. Elegant design. Has MIDI but no USB - less convenient but it is guaranteed to be standard compliant (kinda...)

When I received the unit in the mail, I eagerly hooked it into GDAM, dumped the MIDI, and made a binding file linking the MIDI signals to some effect parameters. But playing with it, something was not right... instead of sending straight X/Y/Z (pressure) coordinates, it sent relative values! This may help to adjust parameters smoothly, but it prevents the obvious application of tapping the center of the X axis to get 50% on parameter, far left to get 0%, etc. Again, relative motion with different levels of sensitivity, soft pickup, and all kinds of other behaviour would have been possible in standard software if they had just sent the pure XYZ coordinates as CC or Pitch Wheel (touchscreen resolution is greater than 7 bit CC value).

The company promised applications for configuing the unit, and the pure coordinates were packed into MIDI sysex data, but as I had no immediate need for the controller I didn't write a driver. Judging by the response to my post to their message board, and other posts, I was far from the only person disappointed by this. When I visited their site recently they seemed to provide software for programming the unit.

Beatmatching in GDAM


At the end of the last century, as we developed GDAM, we got a lot of questions about automatic beatmatching. Non-DJ's wanted a solution to let them string songs together without error. And there was a growing body of academic work on automated pitch and rhythm tracking.

However, by that time I was listening to music complex enough that auto detection is, even today, far from sufficient to track it. Also, I wanted to have complete control over the music, and was willing to spend a bit of prep time on the music I was going to play. So I decided that regardless of any automated beatmatching, my software needed an ironclad solution for defining the rhythm of music which was too complex to rely on automatic beat detection.



The solution I came up with was the Beat Calculator a tool which assisted the user in
manually mapping out the beat for each song once, and a Song Database which stores and retrieves the beatmatching data for each file. Once you know tempo and phase of music, you have the ability to make perfect loops, synchronize effects, and even jump around in the song without dropping the beat. In fact, I'm shocked that I've still not seen another piece of DJ software which allows the user complete freedom to reorganize the song in real-time without ever dropping the beat. I get a lot of dropped jaws when I show this feature, but it is the simplest little bit of math and logic, which we've employed for over a decade.

We did at one point also support a bit of automated beat-tracking software, if i recall correctly it was called pitchtrack and was part of some grad student's paper. However by this point I had a huge library of perfectly-beatmapped files, and it was clear that automated beatmatching may be a good bullet point for selling an app to non-DJ's, but my simple assisted manual solution offered far better results.

USB A

The worst plug design I've come across. The team that approved the design should be ashamed. It is easy to try to plug in upside-down, and impossible to tell the difference in the dark or if you are pluggin in by touch.

USB B is much better, the difference between square and cut corners is easy to feel in both socket and plug, and it doesn't almost go in if you have it wrong.

Why are A/B different to begin with? Allowing for different form factors allow you to keep up with the times, eg mini-usb ports on cell phones and other tiny devices. And certainly A is an easier fit into the edge of a powerbook than B. But I suspect the standard of A on hosts and B on peripherals was adopted so that people were less likely to plug in hubs the wrong way. If the host, hub, and peripherals all used B then the user would have to pay attention to the routing, the ins and outs. But because in/out ports are differentiated by shape, it is impossible to connect peripherals through a hub incorrectly.

GDAM

GDAM is audio software I've been developing for almost a decade, and provides the foundation for a lot of my experiments in audio and control.

Dave Benson, a brilliant fellow who had ten times my programming experience, started the project with me around 1997. It began as an engine for crossfading playlists controlled by clients across the network, but very soon grew to encompass live mixing. The early GUI was written in JAVA, this was rewritten in GTK in 1998.

When we started, there weren't many options for digital DJ mixing software... if I recall, VTT by carrot interactive, virtual 1200s, maybe an early version of PCDJ. Early DJ software was either winamp with crossfades, or an attempt to clone vinyl turntables or CD decks. The field was young, there wasn't existing software to learn from, these were the first attempts. There was TerminatorX on linux, focused on scratching, but nothing which really treated the problem in terms of manipulating audio files with rhythmic content.

Although I had a turntable and sample, beat, and hip-hop records, I didn't have a large body of experience tied to the turntable interface. I wanted a tool geared towards arranging and presenting a mix of digital music files.

By 1999 we had a tool with a database of beatmaps for song files, sample-accurate beatmatching, and different techniques for arranging song files in real time. A number of GDAM's groundbreaking features have made their way into modern apps, but many still seem to be unique to GDAM.

At first we talked about "going beta" and the version number crept to 0.9, 0.912, 0.945... I think we were both interested in working on it for our own reasons, and didn't focus the effort on a single bugfree release with all the niceties of a finished product. GDAM is available in projects such as planetCCRMA and on bootable discs such as dynebolic. I've kept extending GDAM to accomodate my experiments and music projects. Although I haven't made a tarball release in years, I still commit new features to CVS and it keeps getting more powerful. There was an OSX version for a while, but as OSX grew from 10.0 to 10.1 and later versions, every minor update was breaking the install and I didn't feel it was worth the effort to keep up. Lately, GTK-based apps such as ARDOUR have been ported to native OSX versions, so an OSX install may be easy in the near future. I do still have instructions for compiling on OSX for the brave ones willing to type in terminal, these worked at least as recently as OSX 10.4.

Other posts detailing aspects of GDAM:
Beatmatching
Time Access