1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Waveファイルを一定間隔で分割する

Posted at

ブレイクビーツを作るためにちょっと書いた。

slicer.hs
-- Usage:
-- ./slice 32 amen_4bars.wav amenBreak

import System.Environment
import Data.WAVE

import Control.Monad
import System.FilePath.Posix
import Data.Maybe

create :: FilePath -> Int -> IO [WAVE]
create path n = do
	WAVE header samples <- getWAVEFile path
	let size = (fromJust $ waveFrames header) `div` n
	return $ map (WAVE $ WAVEHeader (waveNumChannels header) (waveFrameRate header) (waveBitsPerSample header) (Just size)) $ splitAts (replicate n size) samples
	
splitAts :: [Int] -> [a] -> [[a]]
splitAts (n:ns) xs = take n xs : splitAts ns (drop n xs)
splitAts _ xs = []

main = getArgs >>= \args -> case args of
	(n : path : out : _) -> do
		let base = takeBaseName path
		waves <- create path (read n)
		forM (zip [0..] waves) $ \(i,wave) ->
			putWAVEFile (out `combine` replaceBaseName path (base ++ show i)) wave
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?