summaryrefslogtreecommitdiff
path: root/src/Sound/RubberBand/Raw.chs
blob: 828913c5defa12b075a25b1c6c58dc4aeb489cdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
module Sound.RubberBand.Raw

( Stretcher(..)
, SampleRate, NumChannels, TimeRatio, PitchScale

, new, delete, p_delete, reset

, setTimeRatio, setPitchScale
, getTimeRatio, getPitchScale
, getLatency

, setTransientsOption
, setDetectorOption
, setPhaseOption
, setFormantOption
, setPitchOption

, setExpectedInputDuration
, getSamplesRequired

, setMaxProcessSize
, setKeyFrameMap

, study, process
, available, retrieve

, getChannelCount

, calculateStretch

, setDebugLevel
, setDefaultDebugLevel

) where

import Foreign.Ptr (Ptr, FunPtr)
import Foreign.C.Types
import Foreign.Marshal.Utils (fromBool)

import Sound.RubberBand.Option

#include <rubberband/rubberband-c.h>

fromOptions' :: (Integral a) => Options -> a
fromOptions' = fromIntegral . fromOptions

optionEnum' :: (Option o, Integral a) => o -> a
optionEnum' = fromIntegral . optionEnum

{#pointer RubberBandState as Stretcher newtype #}

{#context prefix="rubberband_"#}

-- | Samples per second of the input and output audio.
type SampleRate = Int

-- | The number of channels processed by a stretcher.
type NumChannels = Int

-- | A ratio of stretched duration to unstretched (original) duration.
type TimeRatio = Double

{- |
A ratio of output frequencies to input frequencies. For example, a ratio of
2 will increase the audio by one octave, and 0.5 will decrease it by one
octave.
-}
type PitchScale = Double

{#fun new as ^
  { fromIntegral `SampleRate'
  , fromIntegral `NumChannels'
  , fromOptions' `Options'
  , realToFrac `TimeRatio'
  , realToFrac `PitchScale'
  } -> `Stretcher' #}

{#fun delete as ^
  { `Stretcher' } -> `()' #}

-- | Suitable for a 'Foreign.ForeignPtr' finalizer.
foreign import ccall "&rubberband_delete"
  p_delete :: FunPtr (Ptr Stretcher -> IO ())

{#fun reset as ^
  { `Stretcher' } -> `()' #}

{#fun set_time_ratio as ^
  { `Stretcher', realToFrac `TimeRatio' } -> `()' #}
{#fun set_pitch_scale as ^
  { `Stretcher', realToFrac `PitchScale' } -> `()' #}

{#fun get_time_ratio as ^
  { `Stretcher' } -> `TimeRatio' realToFrac #}
{#fun get_pitch_scale as ^
  { `Stretcher' } -> `PitchScale' realToFrac #}

{#fun get_latency as ^
  { `Stretcher' } -> `Int' #}

{#fun set_transients_option as ^
  { `Stretcher', optionEnum' `Transients' } -> `()' #}
{#fun set_detector_option as ^
  { `Stretcher', optionEnum' `Detector' } -> `()' #}
{#fun set_phase_option as ^
  { `Stretcher', optionEnum' `Phase' } -> `()' #}
{#fun set_formant_option as ^
  { `Stretcher', optionEnum' `Formant' } -> `()' #}
{#fun set_pitch_option as ^
  { `Stretcher', optionEnum' `Pitch' } -> `()' #}

{#fun set_expected_input_duration as ^
  { `Stretcher', `Int' } -> `()' #}

{#fun get_samples_required as ^
  { `Stretcher' } -> `Int' #}

{#fun set_max_process_size as ^
  { `Stretcher', `Int' } -> `()' #}
{#fun set_key_frame_map as ^
  { `Stretcher', `Int', id `Ptr CUInt', id `Ptr CUInt' } -> `()' #}

{#fun study as ^
  { `Stretcher', id `Ptr (Ptr CFloat)', `Int', `Bool' } -> `()' #}
{#fun process as ^
  { `Stretcher', id `Ptr (Ptr CFloat)', `Int', `Bool' } -> `()' #}

{#fun available as ^
  { `Stretcher' } -> `Int' #}
{#fun retrieve as ^
  { `Stretcher', id `Ptr (Ptr CFloat)', `Int' } -> `Int' #}

{#fun get_channel_count as ^
  { `Stretcher' } -> `Int' #}

{#fun calculate_stretch as ^
  { `Stretcher' } -> `()' #}

{#fun set_debug_level as ^
  { `Stretcher', `Int' } -> `()' #}
{#fun set_default_debug_level as ^
  { `Int' } -> `()' #}