{-# LANGUAGE ForeignFunctionInterface #-}
module Foreign.Libcdio.Sector
(
SubchannelData ( .. )
, Flags
, Flag ( .. )
, Lba
, Lsn
, Msf ( .. )
, lbaToLsn
, lsnToLba
, lbaToMsf
, msfToLba
, lsnToMsf
, msfToLsn
, lbaToMsfStr
, msfToStr
, chunkSize
, minSessionNo, maxSessions
, pregapSectors, postgapSectors
, maxSectors
, framesizeSub
, chunksPerSector
, framesPerSec
, secsPerMin
, framesPerMin
, cdMins
, sectorSize
, syncedSize
, sectorSizeMax
, sectorSyncHeader
, syncSize
, headerSize
, subheaderSize
, headerSizeXa
, syncHeaderSizeXa
, dataSize
, dataSizeRaw
, dataSizeRawXa
, taggedDataSizeRaw
, errorDetectionSize
, errorCorrectionSize
, padSize
, padSizeXa
, tailSize
, tailSizeXa
) where
import qualified Data.Array.BitArray as A
import qualified Data.ByteString as BS
import qualified Foreign.C.String as C
import qualified Foreign.C.Types as C
import qualified Foreign.Ptr as C
import qualified Foreign.Marshal.Alloc as M
import qualified Foreign.Marshal.Utils as M
import qualified Foreign.Storable as S
import qualified System.IO.Unsafe as IO.Unsafe
import Foreign.Libcdio.Marshal
import Foreign.Libcdio.Types.Enums
import Foreign.Libcdio.Types.Internal
import Foreign.Libcdio.Types.Offsets
import Foreign.Libcdio.Util
type Flags = A.BitArray Flag
pregapSectors :: Word
pregapSectors :: Word
pregapSectors = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
pregapSectors'
foreign import ccall safe "cdio/compat/sector.h pregap_sectors"
pregapSectors' :: C.CUInt
postgapSectors :: Word
postgapSectors :: Word
postgapSectors = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
postgapSectors'
foreign import ccall safe "cdio/compat/sector.h postgap_sectors"
postgapSectors' :: C.CUInt
cdMins :: Word
cdMins :: Word
cdMins = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
cdMins'
foreign import ccall safe "cdio/compat/sector.h cd_mins"
cdMins' :: C.CUInt
secsPerMin :: Word
secsPerMin :: Word
secsPerMin = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
secsPerMin'
foreign import ccall safe "cdio/compat/sector.h secs_per_min"
secsPerMin' :: C.CUInt
framesPerSec :: Word
framesPerSec :: Word
framesPerSec = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
framesPerSec'
foreign import ccall safe "cdio/compat/sector.h frames_per_sec"
framesPerSec' :: C.CUInt
syncSize :: Word
syncSize :: Word
syncSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
syncSize'
foreign import ccall safe "cdio/compat/sector.h sync_size"
syncSize' :: C.CUInt
chunkSize :: Word
chunkSize :: Word
chunkSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
chunkSize'
foreign import ccall safe "cdio/compat/sector.h chunk_size"
chunkSize' :: C.CUInt
chunksPerSector :: Word
chunksPerSector :: Word
chunksPerSector = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
chunksPerSector'
foreign import ccall safe "cdio/compat/sector.h chunks_per_frame"
chunksPerSector' :: C.CUInt
framesizeSub :: Word
framesizeSub :: Word
framesizeSub = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
framesizeSub'
foreign import ccall safe "cdio/compat/sector.h framesize_sub"
framesizeSub' :: C.CUInt
headerSize :: Word
= CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
headerSize'
foreign import ccall safe "cdio/compat/sector.h header_size"
:: C.CUInt
subheaderSize :: Word
= CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
subheaderSize'
foreign import ccall safe "cdio/compat/sector.h subheader_size"
:: C.CUInt
errorDetectionSize :: Word
errorDetectionSize :: Word
errorDetectionSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
errorDetectionSize'
foreign import ccall safe "cdio/compat/sector.h edc_size"
errorDetectionSize' :: C.CUInt
padSize :: Word
padSize :: Word
padSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
padSize'
foreign import ccall safe "cdio/compat/sector.h mode1_pad_size"
padSize' :: C.CUInt
errorCorrectionSize :: Word
errorCorrectionSize :: Word
errorCorrectionSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
errorCorrectionSize'
foreign import ccall safe "cdio/compat/sector.h ecc_size"
errorCorrectionSize' :: C.CUInt
dataSize :: Word
dataSize :: Word
dataSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
dataSize'
foreign import ccall safe "cdio/compat/sector.h framesize"
dataSize' :: C.CUInt
sectorSize :: Word
sectorSize :: Word
sectorSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
sectorSize'
foreign import ccall safe "cdio/compat/sector.h framesize_raw"
sectorSize' :: C.CUInt
sectorSizeMax :: Word
sectorSizeMax :: Word
sectorSizeMax = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
sectorSizeMax'
foreign import ccall safe "cdio/compat/sector.h framesize_rawer"
sectorSizeMax' :: C.CUInt
syncedSize :: Word
syncedSize :: Word
syncedSize = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
syncedSize'
foreign import ccall safe "cdio/compat/sector.h framesize_raw1"
syncedSize' :: C.CUInt
dataSizeRaw :: Word
dataSizeRaw :: Word
dataSizeRaw = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
dataSizeRaw'
foreign import ccall safe "cdio/compat/sector.h framesize_raw0"
dataSizeRaw' :: C.CUInt
headerSizeXa :: Word
= CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
headerSizeXa'
foreign import ccall safe "cdio/compat/sector.h header_size_xa"
:: C.CUInt
tailSize :: Word
tailSize :: Word
tailSize = Word
errorDetectionSize Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
padSize Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
errorCorrectionSize
tailSizeXa :: Word
tailSizeXa :: Word
tailSizeXa = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
tailSizeXa'
foreign import ccall safe "cdio/compat/sector.h tail_size_xa"
tailSizeXa' :: C.CUInt
syncHeaderSizeXa :: Word
= CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
syncHeaderSizeXa'
foreign import ccall safe "cdio/compat/sector.h sync_size_xa"
:: C.CUInt
padSizeXa :: Word
padSizeXa :: Word
padSizeXa = Word
dataSizeRaw Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
taggedDataSizeRaw
sectorSyncHeader :: BS.ByteString
= IO ByteString -> ByteString
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO ByteString -> ByteString) -> IO ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$
CStringLen -> IO ByteString
BS.packCStringLen (Ptr CChar
sectorSyncHeader', Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
syncSize)
foreign import ccall safe "cdio/compat/sector.h sector_sync_header"
:: C.Ptr C.CChar
dataSizeRawXa :: Word
dataSizeRawXa :: Word
dataSizeRawXa = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
dataSizeRawXa'
foreign import ccall safe "cdio/compat/sector.h data_size_xa"
dataSizeRawXa' :: C.CUInt
taggedDataSizeRaw :: Word
taggedDataSizeRaw :: Word
taggedDataSizeRaw = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
taggedDataSizeRaw'
foreign import ccall safe "cdio/compat/sector.h tagged_size_xa"
taggedDataSizeRaw' :: C.CUInt
maxSessions :: Word
maxSessions :: Word
maxSessions = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
maxSessions'
foreign import ccall safe "cdio/compat/sector.h max_session"
maxSessions' :: C.CUInt
minSessionNo :: Word
minSessionNo :: Word
minSessionNo = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
minSessionNo'
foreign import ccall safe "cdio/compat/sector.h min_session"
minSessionNo' :: C.CUInt
framesPerMin :: Word
framesPerMin :: Word
framesPerMin = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
framesPerMin'
foreign import ccall safe "cdio/compat/sector.h frames_per_min"
framesPerMin' :: C.CUInt
maxSectors :: Word
maxSectors :: Word
maxSectors = CUInt -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
maxSectors'
foreign import ccall safe "cdio/compat/sector.h max_sectors"
maxSectors' :: C.CUInt
data Msf = Msf
{ Msf -> Word
minute :: Word
, Msf -> Word
second :: Word
, Msf -> Word
frame :: Word
}
deriving ( Int -> Msf -> ShowS
[Msf] -> ShowS
Msf -> String
(Int -> Msf -> ShowS)
-> (Msf -> String) -> ([Msf] -> ShowS) -> Show Msf
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Msf] -> ShowS
$cshowList :: [Msf] -> ShowS
show :: Msf -> String
$cshow :: Msf -> String
showsPrec :: Int -> Msf -> ShowS
$cshowsPrec :: Int -> Msf -> ShowS
Show, ReadPrec [Msf]
ReadPrec Msf
Int -> ReadS Msf
ReadS [Msf]
(Int -> ReadS Msf)
-> ReadS [Msf] -> ReadPrec Msf -> ReadPrec [Msf] -> Read Msf
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Msf]
$creadListPrec :: ReadPrec [Msf]
readPrec :: ReadPrec Msf
$creadPrec :: ReadPrec Msf
readList :: ReadS [Msf]
$creadList :: ReadS [Msf]
readsPrec :: Int -> ReadS Msf
$creadsPrec :: Int -> ReadS Msf
Read )
instance Eq Msf where
Msf
l == :: Msf -> Msf -> Bool
== Msf
r = Msf -> Msf -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Msf
l Msf
r Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ
instance Ord Msf where
compare :: Msf -> Msf -> Ordering
compare Msf
l Msf
r = case Msf -> Word
minute Msf
l' Word -> Word -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Msf -> Word
minute Msf
r' of
Ordering
EQ -> case Msf -> Word
second Msf
l' Word -> Word -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Msf -> Word
second Msf
r' of
Ordering
EQ -> Msf -> Word
frame Msf
l' Word -> Word -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Msf -> Word
frame Msf
r'
Ordering
x -> Ordering
x
Ordering
x -> Ordering
x
where l' :: Msf
l' = Msf -> Msf
normalize Msf
l
r' :: Msf
r' = Msf -> Msf
normalize Msf
r
normalize :: Msf -> Msf
normalize msf :: Msf
msf@(Msf Word
m Word
s Word
f)
| Word
f Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= Word
framesPerSec = Msf -> Msf
normalize (Msf -> Msf) -> Msf -> Msf
forall a b. (a -> b) -> a -> b
$ Word -> Word -> Word -> Msf
Msf Word
m (Word
s Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word -> Word -> Word
forall a. Integral a => a -> a -> a
div Word
f Word
framesPerSec) (Word -> Word -> Word
forall a. Integral a => a -> a -> a
mod Word
f Word
framesPerSec)
| Word
s Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= Word
secsPerMin = Word -> Word -> Word -> Msf
Msf (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word -> Word -> Word
forall a. Integral a => a -> a -> a
div Word
s Word
secsPerMin) (Word -> Word -> Word
forall a. Integral a => a -> a -> a
mod Word
s Word
secsPerMin) Word
f
| Bool
otherwise = Msf
msf
instance Bounded Msf where
minBound :: Msf
minBound = Word -> Word -> Word -> Msf
Msf Word
0 Word
0 Word
0
maxBound :: Msf
maxBound = Word -> Word -> Word -> Msf
Msf Word
forall a. Bounded a => a
maxBound (Word
secsPerMin Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1) (Word
framesPerSec Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1)
instance S.Storable Msf where
sizeOf :: Msf -> Int
sizeOf Msf
_ = Int
msfSizeOf
alignment :: Msf -> Int
alignment Msf
_ = Int
msfAlign
peek :: Ptr Msf -> IO Msf
peek Ptr Msf
c = do
Bcd
m <- Ptr Msf -> Int -> IO Bcd
forall a b. Storable a => Ptr b -> Int -> IO a
S.peekByteOff Ptr Msf
c Int
msfM
Bcd
s <- Ptr Msf -> Int -> IO Bcd
forall a b. Storable a => Ptr b -> Int -> IO a
S.peekByteOff Ptr Msf
c Int
msfS
Bcd
f <- Ptr Msf -> Int -> IO Bcd
forall a b. Storable a => Ptr b -> Int -> IO a
S.peekByteOff Ptr Msf
c Int
msfF
Msf -> IO Msf
forall (m :: * -> *) a. Monad m => a -> m a
return (Msf -> IO Msf) -> Msf -> IO Msf
forall a b. (a -> b) -> a -> b
$ Word -> Word -> Word -> Msf
Msf (Bcd -> Word
fromBcd8 Bcd
m) (Bcd -> Word
fromBcd8 Bcd
s) (Bcd -> Word
fromBcd8 Bcd
f)
poke :: Ptr Msf -> Msf -> IO ()
poke Ptr Msf
c Msf
hs = do
Ptr Msf -> Int -> Bcd -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
S.pokeByteOff Ptr Msf
c Int
msfM (Bcd -> IO ()) -> (Word -> Bcd) -> Word -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Bcd
toBcd8 (Word -> IO ()) -> Word -> IO ()
forall a b. (a -> b) -> a -> b
$ Msf -> Word
minute Msf
hs
Ptr Msf -> Int -> Bcd -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
S.pokeByteOff Ptr Msf
c Int
msfS (Bcd -> IO ()) -> (Word -> Bcd) -> Word -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Bcd
toBcd8 (Word -> IO ()) -> Word -> IO ()
forall a b. (a -> b) -> a -> b
$ Msf -> Word
second Msf
hs
Ptr Msf -> Int -> Bcd -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
S.pokeByteOff Ptr Msf
c Int
msfF (Bcd -> IO ()) -> (Word -> Bcd) -> Word -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Bcd
toBcd8 (Word -> IO ()) -> Word -> IO ()
forall a b. (a -> b) -> a -> b
$ Msf -> Word
frame Msf
hs
instance Enum Msf where
fromEnum :: Msf -> Int
fromEnum Msf
msf = Integer -> Int
forall a. Num a => Integer -> a
fromInteger
(Integer -> Int) -> Integer -> Int
forall a b. (a -> b) -> a -> b
$ Word -> Integer
forall a. Integral a => a -> Integer
toInteger (Msf -> Word
frame Msf
msf)
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Word -> Integer
forall a. Integral a => a -> Integer
toInteger (Msf -> Word
second Msf
msf) Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Word -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
framesPerSec
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Word -> Integer
forall a. Integral a => a -> Integer
toInteger (Msf -> Word
minute Msf
msf) Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Word -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
framesPerMin
toEnum :: Int -> Msf
toEnum Int
i = Msf :: Word -> Word -> Word -> Msf
Msf
{ minute :: Word
minute = Word -> Word -> Word
forall a. Integral a => a -> a -> a
div Word
i' Word
framesPerMin
, second :: Word
second = (Word -> Word -> Word) -> Word -> Word -> Word
forall a b c. (a -> b -> c) -> b -> a -> c
flip Word -> Word -> Word
forall a. Integral a => a -> a -> a
mod Word
secsPerMin (Word -> Word) -> Word -> Word
forall a b. (a -> b) -> a -> b
$ Word -> Word -> Word
forall a. Integral a => a -> a -> a
div Word
i' Word
framesPerSec
, frame :: Word
frame = Word -> Word -> Word
forall a. Integral a => a -> a -> a
mod Word
i' Word
framesPerSec
}
where i' :: Word
i' = Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i
pred :: Msf -> Msf
pred (Msf Word
0 Word
0 Word
0) = String -> Msf
forall a. HasCallStack => String -> a
error String
"Enum.pred(Msf): tried to take `pred' of minBound"
pred (Msf Word
m Word
s Word
f)
| Word
f Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= Word
framesPerSec = Msf -> Msf
forall a. Enum a => a -> a
pred (Msf -> Msf) -> Msf -> Msf
forall a b. (a -> b) -> a -> b
$ Word -> Word -> Word -> Msf
Msf Word
m (Word
s Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word -> Word -> Word
forall a. Integral a => a -> a -> a
div Word
f Word
framesPerSec) (Word -> Word -> Word
forall a. Integral a => a -> a -> a
mod Word
f Word
framesPerSec)
| Word
s Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= Word
secsPerMin = Msf -> Msf
forall a. Enum a => a -> a
pred (Msf -> Msf) -> Msf -> Msf
forall a b. (a -> b) -> a -> b
$ Word -> Word -> Word -> Msf
Msf (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word -> Word -> Word
forall a. Integral a => a -> a -> a
div Word
s Word
secsPerMin) (Word -> Word -> Word
forall a. Integral a => a -> a -> a
mod Word
s Word
secsPerMin) Word
f
| Word
f Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
0 Bool -> Bool -> Bool
&& Word
s Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
0 = Word -> Word -> Word -> Msf
Msf (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1) (Word
secsPerMin Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1) (Word
framesPerSec Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1)
| Word
f Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
0 = Word -> Word -> Word -> Msf
Msf Word
m (Word
s Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1) (Word
framesPerSec Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1)
| Bool
otherwise = Word -> Word -> Word -> Msf
Msf Word
m Word
s (Word
f Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1)
succ :: Msf -> Msf
succ msf :: Msf
msf@(Msf Word
m Word
s Word
f)
| Msf
msf Msf -> Msf -> Bool
forall a. Ord a => a -> a -> Bool
>= Msf
forall a. Bounded a => a
maxBound = String -> Msf
forall a. HasCallStack => String -> a
error String
"Enum.succ(Msf): tried to take `succ' of maxBound"
| Bool
otherwise = let (Word
fd, Word
fm) = Word -> Word -> Word -> (Word, Word)
forall a. (Bounded a, Integral a) => a -> a -> a -> (a, a)
overflow Word
f Word
1 Word
framesPerSec
(Word
sd, Word
sm) = Word -> Word -> Word -> (Word, Word)
forall a. (Bounded a, Integral a) => a -> a -> a -> (a, a)
overflow Word
s Word
fd Word
secsPerMin
in Word -> Word -> Word -> Msf
Msf (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
sd) Word
sm Word
fm
where
overflow :: a -> a -> a -> (a, a)
overflow a
x a
y a
b
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
forall a. Bounded a => a
maxBound a -> a -> a
forall a. Num a => a -> a -> a
- a
y = (a -> a -> a
forall a. Integral a => a -> a -> a
div (a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
y) a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
1, a -> a -> a
forall a. Integral a => a -> a -> a
mod (a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
y) a
b)
| Bool
otherwise = (a -> a -> a
forall a. Integral a => a -> a -> a
div (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
y) a
b, a -> a -> a
forall a. Integral a => a -> a -> a
mod (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
y) a
b)
lbaToMsfStr :: Lba -> String
lbaToMsfStr :: Lba -> String
lbaToMsfStr Lba
l = IO String -> String
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$
CLba -> IO (Ptr CChar)
lbaToMsfStr' (Lba -> CLba
forall a b. (Integral a, Num b) => a -> b
fromIntegral Lba
l) IO (Ptr CChar) -> (Ptr CChar -> IO String) -> IO String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO String
peekFString
foreign import ccall safe "cdio/compat/sector.h cdio_lba_to_msf_str"
lbaToMsfStr' :: CLba -> IO C.CString
msfToStr :: Msf -> String
msfToStr :: Msf -> String
msfToStr Msf
msf = IO String -> String
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$
Msf -> (Ptr Msf -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
M.with Msf
msf Ptr Msf -> IO (Ptr CChar)
msfToStr' IO (Ptr CChar) -> (Ptr CChar -> IO String) -> IO String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO String
C.peekCString
foreign import ccall safe "cdio/compat/sector.h cdio_msf_to_str"
msfToStr' :: C.Ptr Msf -> IO C.CString
lbaToLsn :: Lba -> Lsn
lbaToLsn :: Lba -> Lsn
lbaToLsn = CLba -> Lsn
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CLba -> Lsn) -> (Lba -> CLba) -> Lba -> Lsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CLba -> CLba
lbaToLsn' (CLba -> CLba) -> (Lba -> CLba) -> Lba -> CLba
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lba -> CLba
forall a b. (Integral a, Num b) => a -> b
fromIntegral
foreign import ccall safe "cdio/compat/sector.h cdio_lba_to_lsn"
lbaToLsn' :: CLba -> CLba
lbaToMsf :: Lba -> Msf
lbaToMsf :: Lba -> Msf
lbaToMsf Lba
l = IO Msf -> Msf
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO Msf -> Msf)
-> ((Ptr Msf -> IO Msf) -> IO Msf) -> (Ptr Msf -> IO Msf) -> Msf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr Msf -> IO Msf) -> IO Msf
forall a b. Storable a => (Ptr a -> IO b) -> IO b
M.alloca ((Ptr Msf -> IO Msf) -> Msf) -> (Ptr Msf -> IO Msf) -> Msf
forall a b. (a -> b) -> a -> b
$ \Ptr Msf
m' ->
CLba -> Ptr Msf -> IO ()
lbaToMsf' (Lba -> CLba
forall a b. (Integral a, Num b) => a -> b
fromIntegral Lba
l) Ptr Msf
m' IO () -> IO Msf -> IO Msf
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Msf -> IO Msf
forall a. Storable a => Ptr a -> IO a
S.peek Ptr Msf
m'
foreign import ccall safe "cdio/compat/sector.h cdio_lba_to_msf"
lbaToMsf' :: CLba -> C.Ptr Msf -> IO ()
lsnToLba :: Lsn -> Lba
lsnToLba :: Lsn -> Lba
lsnToLba = CLba -> Lba
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CLba -> Lba) -> (Lsn -> CLba) -> Lsn -> Lba
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CLba -> CLba
lsnToLba' (CLba -> CLba) -> (Lsn -> CLba) -> Lsn -> CLba
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lsn -> CLba
forall a b. (Integral a, Num b) => a -> b
fromIntegral
foreign import ccall safe "cdio/compat/sector.h cdio_lsn_to_lba"
lsnToLba' :: CLsn -> CLba
lsnToMsf :: Lsn -> Msf
lsnToMsf :: Lsn -> Msf
lsnToMsf Lsn
l = IO Msf -> Msf
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO Msf -> Msf)
-> ((Ptr Msf -> IO Msf) -> IO Msf) -> (Ptr Msf -> IO Msf) -> Msf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr Msf -> IO Msf) -> IO Msf
forall a b. Storable a => (Ptr a -> IO b) -> IO b
M.alloca ((Ptr Msf -> IO Msf) -> Msf) -> (Ptr Msf -> IO Msf) -> Msf
forall a b. (a -> b) -> a -> b
$ \Ptr Msf
m' ->
CLba -> Ptr Msf -> IO ()
lsnToMsf' (Lsn -> CLba
forall a b. (Integral a, Num b) => a -> b
fromIntegral Lsn
l) Ptr Msf
m' IO () -> IO Msf -> IO Msf
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Msf -> IO Msf
forall a. Storable a => Ptr a -> IO a
S.peek Ptr Msf
m'
foreign import ccall safe "cdio/compat/sector.h cdio_lsn_to_msf"
lsnToMsf' :: CLsn -> C.Ptr Msf -> IO ()
msfToLba :: Msf -> Lba
msfToLba :: Msf -> Lba
msfToLba = CLba -> Lba
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CLba -> Lba) -> (Msf -> CLba) -> Msf -> Lba
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO CLba -> CLba
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO CLba -> CLba) -> (Msf -> IO CLba) -> Msf -> CLba
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Msf -> (Ptr Msf -> IO CLba) -> IO CLba)
-> (Ptr Msf -> IO CLba) -> Msf -> IO CLba
forall a b c. (a -> b -> c) -> b -> a -> c
flip Msf -> (Ptr Msf -> IO CLba) -> IO CLba
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
M.with Ptr Msf -> IO CLba
msfToLba'
foreign import ccall safe "cdio/compat/sector.h cdio_msf_to_lba"
msfToLba' :: C.Ptr Msf -> IO CLsn
msfToLsn :: Msf -> Lsn
msfToLsn :: Msf -> Lsn
msfToLsn = CLba -> Lsn
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CLba -> Lsn) -> (Msf -> CLba) -> Msf -> Lsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO CLba -> CLba
forall a. IO a -> a
IO.Unsafe.unsafePerformIO (IO CLba -> CLba) -> (Msf -> IO CLba) -> Msf -> CLba
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Msf -> (Ptr Msf -> IO CLba) -> IO CLba)
-> (Ptr Msf -> IO CLba) -> Msf -> IO CLba
forall a b c. (a -> b -> c) -> b -> a -> c
flip Msf -> (Ptr Msf -> IO CLba) -> IO CLba
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
M.with Ptr Msf -> IO CLba
msfToLsn'
foreign import ccall safe "cdio/compat/sector.h cdio_msf_to_lsn"
msfToLsn' :: C.Ptr Msf -> IO CLsn