Playing audio from PSRAM (on Teensy 4.1)

Status
Not open for further replies.

littlepeople

New member
Hi

I recently purchased a Teensy 4.1 with the 8mb PSRAM chip. My idea is to try and play audio data saved to the PSRAM chip. To test the feasibility of this i've tried modifying the SamplePlayer example project to use EXTMEM instead of PROGMEM for the different samples. That swap didn't work at first so i used the PSRAM test to double check all was well with the PSRAM (it was). I had a dig into the play_memory.cpp file to see why no sound was being emitted. There are a few sections of code i'm struggling to make sense of...

Code:
void AudioPlayMemory::play(const unsigned int *data)
{
	uint32_t format;

	playing = 0;
	prior = 0;
	format = *data++;
	next = data;
	beginning = data;
	length = format & 0xFFFFFF;
	playing = format >> 24;
	

}

My c++ is not up to scratch so i'm not sure what is being achieved in these 3 particular lines of code:
Code:
   format = *data++;
   length = format & 0xFFFFFF;
   playing = format >> 24;

Could someone help explain what is going on here? The playing variable is then used in the update method in a switch-case section to determine the type of audio data being read. Audio data read from the PSRAM seem to have different playing values than if they being read from PROGMEM. I've checked and saving values as PROGMEM or EXTMEM variable match one another in terms of actual data.

I actually created a new switch case to catch the playing value pertaining to the sample on the PSRAM and i get some audio now... but it doesn't sound right. You can detect the attack of the sound but it is masked by a noisy short loop that plays constantly over the top.

I feel if i could make sense of the part of the code above, i could figure what's required to get it working. So would love some help here if possible.

Or am i barking up the wrong tree here. Is adapting the AudioPlayMemory class not good option for what i'm trying to achieve?
 
Could someone help explain what is going on here?

The sample player expects the first 4 bytes to specify the length of the data and details like whether it is 8 bit u-law or 16 bit linear, and the sample rate. For slower samples rate data, it's upscaled to 44.1 kHz using simple linear interpolation while playing.
 
Thanks for that Paul. I've now had a look at wav2sketch page on your site and what the data in the first 32 bits signify. So that all makes sense now, thank you. However I seem to have stumbled across some strange behaviour (on my end at least).

If i view the first 4 bytes after creating the EXTMEM sample array in my main program, the sample type and sample length are returned without any issues. However when the sample array (saved in SRAM) is passed to AudioPlayMemory:: play the value it points to is different - which then extracts incorrect playing and length values. But, it's consistently ok if i switch it back to PROGMEM. This is confusing me...
 
Status
Not open for further replies.
Back
Top