Fisrt attempt to pause SdPlay ; AudioLib update

Status
Not open for further replies.

Jat

Member
Hi , I just played with Granular effect in audio lib on t3.5 native dacs output... then I needed to pause playSdRaw when granular freeze, and after red lot of toppic I succeed to corrupt the playsdRaw lib (I guess will work on playsdwav).
But I think it's not the right way to do it :
playSdRaw.h
Code:
#ifndef play_sd_raw_h_
#define play_sd_raw_h_

#include "AudioStream.h"
#include "SD.h"

class AudioPlaySdRaw : public AudioStream
{
public:
	AudioPlaySdRaw(void) : AudioStream(0, NULL) { begin(); }
	void begin(void);
	bool play(const char *filename);
        void pause(bool pst);/////////////////////// PAUSE TEST
        bool seek(const char *filename, uint32_t pos);
	void stop(void);
	bool isPlaying(void) { return playing; }
	uint32_t positionMillis(void);
        uint32_t positionBytes(void);
	uint32_t lengthMillis(void);
	uint32_t lengthBytes(void);
	virtual void update(void);
private:
	File rawfile;
	uint32_t file_size;
	volatile uint32_t file_offset;
	volatile bool playing;
	volatile bool paused = false; /////////////////////////PAUSE TEST
     uint32_t byte_offset;
};

#endif

and in playSdRaw.cpp
Code:
void AudioPlaySdRaw::update(void)
{
	unsigned int i, n;
	audio_block_t *block;

	// only update if we're playing
	if (!playing) return;

	// allocate the audio blocks to transmit
	block = allocate();
	if (block == NULL) return;

	if (rawfile.available()) { 
		// we can read more data from the file...
		if (paused == false){ ///////////////////////////////PAUSE TEST
                  n = rawfile.read(block->data, AUDIO_BLOCK_SAMPLES*2);
                  }
		 file_offset += n; 
		for (i=n/2; i < AUDIO_BLOCK_SAMPLES; i++) {
			block->data[i] = 0;
		}
		transmit(block);
	} else {
		rawfile.close();
		AudioStopUsingSPI();
		playing = false;
	}
	release(block);
}

void AudioPlaySdRaw::pause(bool pst){ ////////////////PAUSE TEST
paused = pst;
}

in my poor understand when I call : playSdRaw.pause(true); it stop the read head and playSdRaw.pause(false); release it...
For granular effect I call I call ' playSdRaw.pause(true); ' after a delay of the length of the grain. trig 'playSdRaw.pause(false);' just after stop ganular effect...
It work more or less, at least it freeze one block...
in my schetch :
Code:
if (button0.fallingEdge()) {
    float ax = sq(AcX/4+4000);
    float msec = ax/100000.0;
    msec = constrain(msec, 10, 550);
    granular.beginFreeze(msec); //msec
    Serial.print("Begin granular freeze using ");
    Serial.print(msec);
    Serial.println(" grains");
    delay(msec);
    playSdRaw.pause(true); /// start pause
  }
  if (button0.risingEdge()) {
    granular.stop();
    //freeze = 0;
    playSdRaw.pause(false); /// stop pause
  }

If anyone have time to improve and submit something...
 
I'd prefer to just stop the whole library with
AudioNoInterrupts
(); and

AudioInterrupts(); to resume.

- no changes to the library needed.
 
I'd prefer to just stop the whole library with
AudioNoInterrupts
(); and

AudioInterrupts(); to resume.

- no changes to the library needed.

Yes, but granular effect use Audiolib features, so... at least what I did work for my project, and I thinks it could be usefull for other applications to implement an offical pause process in all player libs.
 
Status
Not open for further replies.
Back
Top