@@ -70,10 +70,13 @@ namespace crone {
7070 virtual // from any thread
7171 void start () {
7272 if (isRunning) {
73+ std::cout << " Tape::SfStream::start(): already running" << std::endl;
7374 return ;
7475 } else {
76+ std::cout << " Tape::SfStream: starting..." << std::endl;
7577 envIdx = 0 ;
7678 envState = Starting;
79+
7780 this ->th = std::make_unique<std::thread>(
7881 [this ]() {
7982 this ->diskLoop ();
@@ -127,7 +130,7 @@ namespace crone {
127130 envIdx = 0 ;
128131 envState = Stopped;
129132 shouldStop = true ;
130- std::cerr << " Tape: fade-out finished; stopping" << std::endl;
133+ std::cout << " Tape: fade-out finished; stopping" << std::endl;
131134 }
132135 }
133136
@@ -164,7 +167,7 @@ namespace crone {
164167
165168 if (bytesToPush > bytesAvailable) {
166169#if 0
167- std::cerr << "Tape: writer overrun: "
170+ std::cout << "Tape: writer overrun: "
168171 << bytesAvailable << " bytes available; "
169172 << bytesToPush << " bytes to push; "
170173 << numFramesCaptured << " frames captured"
@@ -229,7 +232,7 @@ namespace crone {
229232
230233 if (framesToWrite > (int ) maxFramesToWrite) {
231234 // _really_ shouldn't happen
232- std::cerr << " warning: Tape::Writer has too many frames to write" << std::endl;
235+ std::cout << " warning: Tape::Writer has too many frames to write" << std::endl;
233236 framesToWrite = (int ) maxFramesToWrite;
234237 }
235238
@@ -243,22 +246,22 @@ namespace crone {
243246 if (sf_writef_float (this ->file , diskOutBuf, framesToWrite) != framesToWrite) {
244247 char errstr[256 ];
245248 sf_error_str (nullptr , errstr, sizeof (errstr) - 1 );
246- std::cerr << " error: Tape::writer failed to write (libsndfile: " << errstr << " )" << std::endl;
249+ std::cout << " error: Tape::writer failed to write (libsndfile: " << errstr << " )" << std::endl;
247250 this ->status = EIO;
248251 break ;
249252 }
250253
251254 numFramesCaptured += framesToWrite;
252255 if (numFramesCaptured >= maxFrames) {
253- std::cerr << " Tape: writer exceeded max frame count; aborting." ;
256+ std::cout << " Tape: writer exceeded max frame count; aborting." ;
254257 break ;
255258 }
256259
257260 }
258261
259- std::cerr << " Tape::writer closing file..." ;
262+ std::cout << " Tape::writer closing file..." ;
260263 sf_close (this ->file );
261- std::cerr << " done." << std::endl;
264+ std::cout << " done." << std::endl;
262265 SfStream::isRunning = false ;
263266 }
264267
@@ -267,6 +270,13 @@ namespace crone {
267270 size_t maxFrames = JACK_MAX_FRAMES, // <-- ridiculous big number
268271 int sampleRate = 48000 ,
269272 int bitDepth = 24 ) {
273+
274+ if (SfStream::isRunning) {
275+ std::cout << " Tape Writer::open(): stream is running; no action was taken" << std::endl;
276+ return false ;
277+ }
278+
279+
270280 SF_INFO sf_info;
271281 int short_mask;
272282
@@ -295,7 +305,7 @@ namespace crone {
295305 if ((this ->file = sf_open (path.c_str (), SFM_WRITE, &sf_info)) == NULL ) {
296306 char errstr[256 ];
297307 sf_error_str (nullptr , errstr, sizeof (errstr) - 1 );
298- std::cerr << " cannot open sndfile" << path << " for output (" << errstr << " )" << std::endl;
308+ std::cout << " cannot open sndfile" << path << " for output (" << errstr << " )" << std::endl;
299309 return false ;
300310 }
301311
@@ -337,6 +347,7 @@ namespace crone {
337347 private:
338348 // prime the ringbuffer
339349 void prime () {
350+ // std::cout << "priming tape reader" << std::endl;
340351 jack_ringbuffer_t *rb = this ->ringBuf .get ();
341352 size_t framesToRead = jack_ringbuffer_write_space (rb) / frameSize;
342353 if (framesToRead > maxFramesToRead) { framesToRead = maxFramesToRead; };
@@ -347,7 +358,7 @@ namespace crone {
347358
348359 // couldn't read enough, file is shorter than the buffer
349360 if (framesRead < framesToRead) {
350- std::cerr << " Tape::Reader: short file, disable loop" << std::endl;
361+ std::cout << " Tape::Reader: short file, disable loop" << std::endl;
351362 SfStream::shouldStop = false ;
352363 }
353364 }
@@ -425,22 +436,26 @@ namespace crone {
425436
426437 // from any thread
427438 bool open (const std::string &path) {
428- SF_INFO sfInfo;
439+ if (SfStream::isRunning) {
440+ std::cout << " Tape Reader::open(): stream is running; no action was taken" << std::endl;
441+ return false ;
442+ }
429443
444+ SF_INFO sfInfo;
430445 if ((this ->file = sf_open (path.c_str (), SFM_READ, &sfInfo)) == NULL ) {
431446 char errstr[256 ];
432447 sf_error_str (0 , errstr, sizeof (errstr) - 1 );
433- std::cerr << " Tape Reader:: cannot open sndfile" << path << " for output (" << errstr << " )" << std::endl;
448+ std::cout << " Tape Reader:: cannot open sndfile" << path << " for output (" << errstr << " )" << std::endl;
434449 return false ;
435450 }
436451
437452 if (sfInfo.frames < 1 ) {
438453
439- std::cerr << " Tape Reader:: error reading file " << path << " (no frames available)" << std::endl;
454+ std::cout << " Tape Reader:: error reading file " << path << " (no frames available)" << std::endl;
440455 return false ;
441456 }
442457 this ->frames = static_cast <size_t >(sfInfo.frames );
443- std::cerr << " Tape Reader:: file size " << this ->frames << " samples" << std::endl;
458+ std::cout << " Tape Reader:: file size " << this ->frames << " samples" << std::endl;
444459 inChannels = sfInfo.channels ;
445460 if (inChannels > NumChannels)
446461 return 0 ;// more than stereo is going to break things
@@ -498,12 +513,13 @@ namespace crone {
498513 if (loopFile) {
499514 // couldn't perform full read so must be end of file. Seek to start of file and keep reading
500515 while (framesRead < framesToRead) {
516+ // std::cout << "tape reader: couldn't perform full read; looping file..." << std::endl;
501517 sf_seek (this ->file ,0 , SEEK_SET);
502518 auto nextRead = (size_t ) sf_readf_float (this ->file , diskBufPtr, framesToRead-framesRead);
503519 if (nextRead < 1 )
504520 {
505521 // Shouldn't happen
506- std::cerr << " Tape::Reader: unable to read file" << std::endl;
522+ std::cout << " Tape::Reader: unable to read file" << std::endl;
507523 SfStream::shouldStop = true ;
508524 break ;
509525 }
@@ -514,7 +530,6 @@ namespace crone {
514530 }
515531 }
516532 else {
517- std::cerr << " Tape::Reader::diskloop() reached EOF" << std::endl;
518533 SfStream::shouldStop = true ;
519534 }
520535
@@ -525,7 +540,6 @@ namespace crone {
525540
526541 }
527542 sf_close (this ->file );
528- std::cerr << " Tape::reader closed file" << std::endl;
529543 }
530544
531545 }; // Reader class
0 commit comments