app = do
  rate <- option auto $ long "rate" <> help "sampling rate" <> value 44100
  buf <- option auto $ long "buffer" <> help "number of samples for the buffer" <> value 1024
  device <- option auto $ long "device" <> help "device index" <> value (-1)
  helper
  pure $ withPortAudio $ do
    (_, devs) <- getDevices
    if device < 0
      then forM_ (zip [0 :: Int ..] devs) $ \(i, dev) ->
        putStrLn $ show i ++ ": " ++ deviceName dev
      else do
        let dev = devs !! device
        phase <- newMVar 0