CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

DLine.cpp
Go to the documentation of this file.
1 //
2 // DLine.h -- an Interpolating Delay Line
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 // This is a typical circular buffer with one writer and multiple readers (tap instances)
6
7 #include "DLine.h"
8 using namespace csl;
9
10 DLine :: DLine ( FrameStream &input, float max_delay ) : Processor(input),
11 max_delay_time(max_delay),
12 delay_time(0.5 * max_delay),
13 max_delay_in_frames( (unsigned) (_sampleRate * max_delay + CGestalt::block_size() ) ),
14 interp_type(kTruncate),
15 start_frame(0),
16 // end_frame(0),
17 write_frame(0),
18 ring_buffer(FrameStream::channels(), max_delay_in_frames)
19 {
20 // max_delay_in_frames = _sampleRate * max_delay;
21 ring_buffer.allocate_mono_buffers();
22 ring_buffer.zero_buffers();
23
24 }
25
26 DLine :: ~DLine() {
27 ring_buffer.freeMonoBuffers();
28 }
29
30 bool DLine :: init_delay_time( float dt ) {
31 if (dt > max_delay_time)
32 return false;
33 delay_time = dt;
34 return set_target_delay_time(dt);
35 }
36
37 bool DLine :: set_target_delay_time( float tdt ) {
38 if (tdt > max_delay_time)
39 return false;
40 target_delay_time = tdt;
41 return true;
42 }
43
44 bool DLine :: set_interp_type( InterpType it ) {
45 interp_type = it;
46 return true;
47 }
48
49 // Do the work
50
51 status DLine :: mono_next_buffer(Buffer & inputBuffer, Buffer & outputBuffer, unsigned inBufNum, unsigned outBufNum) {
52 unsigned temp_write_frame = write_frame;
53 sample * rbPtr = ring_buffer._monoBuffers[outBufNum] + temp_write_frame;
54 sample * outPtr = outputBuffer._monoBuffers[outBufNum];
55 /*
56 for (int i=0; i<outputBuffer._numFrames; i++){
57 // ring_buffer._monoBuffers[outBufNum][temp_write_frame] = outputBuffer._monoBuffers[outBufNum][i];
58 *rbPtr++ = *outPtr++
59 if (++temp_write_frame >= ring_buffer._numFrames)
60 temp_write_frame = 0;
61 rbPtr = ring_buffer._monoBuffers[outBufNum];
62 }
63 */
64 sample *tempSamplePtr;
65 outPtr = outputBuffer._monoBuffers[outBufNum];
66 float ramp_factor = 0.0001; // ??
67 rbPtr = ring_buffer._monoBuffers[outBufNum];
68 for (unsigned i = 0; i < outputBuffer._numFrames; i++) {
69 delay_time = (1.0 - ramp_factor) * delay_time + ramp_factor * target_delay_time;
70 float r_index_and_mant = (delay_time * _sampleRate);
71 unsigned index = (unsigned) floor(r_index_and_mant);
72 float mantissa = r_index_and_mant - index;
73 int read_frame = temp_write_frame - index;
74 while (read_frame < 0)
75 read_frame += ring_buffer._numFrames;
76 sample lower_read_value = *(rbPtr + read_frame);
77 tempSamplePtr = ((unsigned)(rbPtr + read_frame + 1)) % ring_buffer._numFrames;
78 sample upper_read_value = *tempSamplePtr;
79 if ( ++temp_write_frame >= ring_buffer._numFrames)
80 temp_write_frame -= ring_buffer._numFrames;
81 *outPtr++ = ((1.0 - mantissa) * lower_read_value) + (mantissa * upper_read_value);
82 }
83 write_frame = temp_write_frame;
84 }
85
86 // Call inherited version
87
88 status DLine :: next_buffer(Buffer & inputBuffer, Buffer & outputBuffer){
89 Processor :: pull_input( inputBuffer, outputBuffer );
90 FrameStream :: next_buffer( inputBuffer, outputBuffer );
91 // update_write_frame(outputBuffer._numFrames);
92 write_frame += outputBuffer._numFrames;
93 write_frame %= ring_buffer._numFrames;
94
95 }
96
97
98
99