-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundTouchDLL.cs
145 lines (117 loc) · 7.05 KB
/
SoundTouchDLL.cs
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
143
144
145
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace SoundTouchNet
{
public static class SoundTouch
{
const string soundTouchDLL = "soundtouch.dll";
/// Create a new instance of SoundTouch processor.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr soundtouch_createInstance();
/// Destroys a SoundTouch processor instance.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_destroyInstance(IntPtr h);
/// Get SoundTouch library version string
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPStr)]
private static extern String soundtouch_getVersionString();
/// Get SoundTouch library version Id
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern uint soundtouch_getVersionId();
/// Sets new rate control value. Normal rate = 1.0, smaller values
/// represent slower rate, larger faster rates.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setRate(IntPtr h, float newRate);
/// Sets new tempo control value. Normal tempo = 1.0, smaller values
/// represent slower tempo, larger faster tempo.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setTempo(IntPtr h, float newTempo);
/// Sets new rate control value as a difference in percents compared
/// to the original rate (-50 .. +100 %);
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setRateChange(IntPtr h, float newRate);
/// Sets new tempo control value as a difference in percents compared
/// to the original tempo (-50 .. +100 %);
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setTempoChange(IntPtr h, float newTempo);
/// Sets new pitch control value. Original pitch = 1.0, smaller values
/// represent lower pitches, larger values higher pitch.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setPitch(IntPtr h, float newPitch);
/// Sets pitch change in octaves compared to the original pitch
/// (-1.00 .. +1.00);
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setPitchOctaves(IntPtr h, float newPitch);
/// Sets pitch change in semi-tones compared to the original pitch
/// (-12 .. +12);
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setPitchSemiTones(IntPtr h, float newPitch);
/// Sets the number of channels, 1 = mono, 2 = stereo
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setChannels(IntPtr h, uint numChannels);
/// Sets sample rate.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_setSampleRate(IntPtr h, uint srate);
/// Flushes the last samples from the processing pipeline to the output.
/// Clears also the internal processing buffers.
//
/// Note: This function is meant for extracting the last samples of a sound
/// stream. This function may introduce additional blank samples in the end
/// of the sound stream, and thus it's not recommended to call this function
/// in the middle of a sound stream.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_flush(IntPtr h);
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
/// the input of the object. Notice that sample rate _has_to_ be set before
/// calling this function, otherwise throws a runtime_error exception.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_putSamples(IntPtr h,
[MarshalAs(UnmanagedType.LPArray)] short[] samples, ///< Pointer to sample buffer.
uint numSamples ///< Number of samples in buffer. Notice
///< that in case of stereo-sound a single sample
///< contains data for both channels.
);
/// Clears all the samples in the object's output and internal processing
/// buffers.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern void soundtouch_clear(IntPtr h);
/// Changes a setting controlling the processing system behaviour. See the
/// 'SETTING_...' defines for available setting ID's.
///
/// \return 'TRUE' if the setting was succesfully changed
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern bool soundtouch_setSetting(IntPtr h,
int settingId, ///< Setting ID number. see SETTING_... defines.
int value ///< New setting value.
);
/// Reads a setting controlling the processing system behaviour. See the
/// 'SETTING_...' defines for available setting ID's.
///
/// \return the setting value.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern int soundtouch_getSetting(IntPtr h,
int settingId ///< Setting ID number, see SETTING_... defines.
);
/// Returns number of samples currently unprocessed.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern uint soundtouch_numUnprocessedSamples(IntPtr h);
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
/// sample buffer without copying them anywhere.
///
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
/// with 'ptrBegin' function.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern uint soundtouch_receiveSamples(IntPtr h,
[MarshalAs(UnmanagedType.LPArray)] short[] outBuffer, ///< Buffer where to copy output samples.
uint maxSamples ///< How many samples to receive at max.
);
/// Returns number of samples currently available.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern uint soundtouch_numSamples(IntPtr h);
/// Returns nonzero if there aren't any samples available for outputting.
[DllImport(soundTouchDLL, CallingConvention = CallingConvention.StdCall)]
private static extern uint soundtouch_isEmpty(IntPtr h);
}
}