Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
65  src/file_loop.c
@@ -67,44 +67,28 @@ static void calculate_monome_pos(sf_count_t length, sf_count_t position, uint_t
67 67
 }
68 68
 
69 69
 static void file_process(file_t *self, jack_default_audio_sample_t **buffers, int channels, jack_nframes_t nframes, jack_nframes_t sample_rate) {
70  
-	sf_count_t i, o;
  70
+  sf_count_t i, o, j;
71 71
 
72 72
 #ifdef HAVE_SRC
73  
-	float b[2];
  73
+//	float b[2];
74 74
 	double speed;
75 75
 
76 76
 	speed = (sample_rate / (double) self->sample_rate) * (1 / self->speed);
77 77
 
78 78
 	if( self->speed != 1 || self->sample_rate != sample_rate ) {
79  
-		if( self->channels == 1 ) {
80  
-			for( i = 0; i < nframes; i++ ) {
81  
-				src_callback_read(self->src, speed, 1, b);
82  
-				buffers[0][i] += b[0] * self->volume;
83  
-				buffers[1][i] += b[0] * self->volume;
84  
-			}
85  
-		} else {
86  
-			for( i = 0; i < nframes; i++ ) {
87  
-				src_callback_read(self->src, speed, 1, b);
88  
-				buffers[0][i] += b[0] * self->volume;
89  
-				buffers[1][i] += b[1] * self->volume;
90  
-			}
  79
+		for( i = 0; i < nframes; i++ ) {
  80
+			src_callback_read(self->src, speed, 1, self->out_frame);
  81
+			buffers[0][i] += self->out_frame[0] * self->volume;
  82
+			buffers[1][i] += self->out_frame[1] * self->volume;
91 83
 		}
92 84
 	} else {
93 85
 #endif
94  
-		if( self->channels == 1 ) {
95  
-			for( i = 0; i < nframes; i++ ) {
96  
-				o = file_get_play_pos(self);
97  
-				buffers[0][i] += self->file_data[o]   * self->volume;
98  
-				buffers[1][i] += self->file_data[o]   * self->volume;
99  
-				file_inc_play_pos(self, 1);
100  
-			}
101  
-		} else {
102  
-			for( i = 0; i < nframes; i++ ) {
103  
-				o = file_get_play_pos(self);
104  
-				buffers[0][i] += self->file_data[o]   * self->volume;
105  
-				buffers[1][i] += self->file_data[++o] * self->volume;
106  
-				file_inc_play_pos(self, 1);
107  
-			}
  86
+		for( i = 0; i < nframes; i++ ) {
  87
+			o = file_get_play_pos(self);
  88
+                              for (j = 0; j < self->channels; ++j) {
  89
+                                 buffers[j][i] += self->deinterleaved_data[j][o]   * self->volume;
  90
+                               }
  91
+                        file_inc_play_pos(self, 1);
108 92
 		}
109 93
 #ifdef HAVE_SRC
110 94
 	}
@@ -120,7 +104,10 @@ static long file_src_callback(void *cb_data, float **data) {
120 104
 		return 0;
121 105
 
122 106
 	o = self->play_offset;
123  
-	*data = self->file_data + (o * self->channels);
  107
+//	*data = self->file_data + (o * self->channels);
  108
+        self->in_frame[0] = self->deinterleaved_data[0][o];
  109
+        self->in_frame[1] = self->deinterleaved_data[1][o];
  110
+        *data = self->in_frame;
124 111
 	file_inc_play_pos(self, 1);
125 112
 
126 113
 	return 1;
@@ -231,6 +218,13 @@ static void file_init(file_t *self) {
231 218
 }
232 219
 
233 220
 void file_free(file_t *self) {
  221
+  int i;
  222
+  for (i = 0; i < self->channels; ++i) {
  223
+    free(self->deinterleaved_data[i]);
  224
+  }
  225
+  free(self->deinterleaved_data);
  226
+  free(self->in_frame);
  227
+  free(self->out_frame);
234 228
 	free(self->file_data);
235 229
 	free(self);
236 230
 }
@@ -239,6 +233,7 @@ file_t *file_new_from_path(const char *path) {
239 233
 #ifdef HAVE_SRC
240 234
 	int err;
241 235
 #endif
  236
+        int i, j;
242 237
 	file_t *self;
243 238
 	SF_INFO info;
244 239
 	SNDFILE *snd;
@@ -269,6 +264,18 @@ file_t *file_new_from_path(const char *path) {
269 264
 		self = NULL;
270 265
 	}
271 266
 
  267
+        self->in_frame = calloc(sizeof(float), info.channels);
  268
+        self->out_frame = calloc(sizeof(float), info.channels);
  269
+	self->deinterleaved_data   = calloc(sizeof(float *), info.channels);
  270
+       for (j = 0; j < info.channels; ++j) {
  271
+         self->deinterleaved_data[j]   = calloc(sizeof(float), info.frames);
  272
+       }
  273
+        for (i = 0; i < info.frames; ++i) {
  274
+          for (j = 0; j < info.channels; ++j) {
  275
+            self->deinterleaved_data[j][i] = self->file_data[i * info.channels + j];
  276
+          }
  277
+        }
  278
+
272 279
 	sf_close(snd);
273 280
 
274 281
 	return self;
3  src/private/types.h
@@ -140,7 +140,10 @@ struct file {
140 140
 #endif
141 141
 	double speed;
142 142
 
  143
+	float **deinterleaved_data;
143 144
 	float *file_data;
  145
+	float *out_frame;
  146
+	float *in_frame;
144 147
 
145 148
 	int y;
146 149
 	int row_span;
13  src/session.c
@@ -56,7 +56,7 @@ static void file_section_callback(const conf_section_t *section, void *arg) {
56 56
 
57 57
 	unsigned int e, c, r, group, reverse, *v, this_y, loop;
58 58
 	file_t *f;
59  
-	double speed;
  59
+	double speed, volume;
60 60
 	char *path, *buf;
61 61
 
62 62
         double msec, bpm;
@@ -75,6 +75,7 @@ static void file_section_callback(const conf_section_t *section, void *arg) {
75 75
 	c       = 0;
76 76
 	reverse = 0;
77 77
 	speed   = 1.0;
  78
+	volume   = 1.0;
78 79
         loop  = 0;
79 80
 
80 81
 	while( (e = conf_getvar(section, &pair)) ) {
@@ -91,6 +92,10 @@ static void file_section_callback(const conf_section_t *section, void *arg) {
91 92
 			speed = strtod(pair->value, NULL);
92 93
 			continue;
93 94
 
  95
+		case 'a': /* volume */
  96
+			volume = strtod(pair->value, NULL);
  97
+			continue;
  98
+
94 99
 		case 'g': /* group */
95 100
 			v = &group;
96 101
 			break;
@@ -108,7 +113,7 @@ static void file_section_callback(const conf_section_t *section, void *arg) {
108 113
                         break;
109 114
 
110 115
                 case 'l':
111  
-                        loop = 1;
  116
+                  loop = strtod(pair->value, NULL);
112 117
                         continue;
113 118
 		}
114 119
 
@@ -144,6 +149,7 @@ static void file_section_callback(const conf_section_t *section, void *arg) {
144 149
 
145 150
 	f->path = buf;
146 151
 	f->speed = speed;
  152
+	f->volume = volume;
147 153
 	f->row_span = r;
148 154
 	f->columns  = (c) ? ((c - 1) & 0xF) + 1 : session->cols;
149 155
 	f->group = &state.groups[group - 1];
@@ -159,7 +165,7 @@ static void file_section_callback(const conf_section_t *section, void *arg) {
159 165
 
160 166
         if (loop) {
161 167
           msec = 1000*f->length / f->sample_rate;
162  
-          bpm = 8 * (60.0 * 1000) / msec;
  168
+          bpm = loop * (60.0 * 1000) / msec;
163 169
 
164 170
           printf("adjust speed to %lf @ %.2f bpm to loop at session bpm of %.2f\n", session->bpm/bpm, bpm, session->bpm);
165 171
           f->speed = session->bpm/bpm;
@@ -304,6 +310,7 @@ int session_load(const char *path) {
304 310
 		{"speed",   NULL, DOUBLE, 's'},
305 311
 		{"y",       NULL,    INT, 'y'},
306 312
 		{"loop",       NULL, BOOL, 'l'},
  313
+		{"volume",       NULL, BOOL, 'a'},
307 314
 		{NULL}
308 315
 	};
309 316
 

No commit comments for this range

Something went wrong with that request. Please try again.