Skip to content

Commit

Permalink
AudioPlayMemory: clarify I16->F32, clarify wrapping of phaser
Browse files Browse the repository at this point in the history
  • Loading branch information
chipaudette committed Dec 13, 2023
1 parent d7bb902 commit c2f1997
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/AudioPlayMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ int AudioPlayMemoryI16_F32::setCurrentSampleFromQueue(int ind) {

//define CONVERT_I16_TO_F32(x) (((float32_t)x)/(16384.0f))
//define I16_TO_F32_NORM_FACTOR (3.051850947599719e-05) //which is 1/32767
#define I16_TO_F32_NORM_FACTOR (3.0517578125e-05) //which is 1/32768
#define CONVERT_I16_TO_F32(x) (x*I16_TO_F32_NORM_FACTOR)

//#define I16_TO_F32_NORM_FACTOR (3.0517578125e-05) //which is 1/32768
#define I16_TO_F32_NORM_FACTOR (1.0f/32768.0f)
#define CONVERT_I16_TO_F32(x) ( ((float)x) * ((float)I16_TO_F32_NORM_FACTOR) )
void AudioPlayMemoryI16_F32::update(void) {
if (state != PLAYING) return;

Expand All @@ -64,7 +64,6 @@ void AudioPlayMemoryI16_F32::update(void) {
float32_t AudioPlayMemoryI16_F32::getNextAudioValue(void) {
//Serial.println("AudioPlayMemoryI16_F32: update: data_phase = " + String(data_phase) + ", data_ind = " + String(data_ind));


if (data_ind >= data_len) { //have we reached the end of the current data buffer?
//yes, we've reached the end of the current buffer.

Expand Down Expand Up @@ -101,10 +100,12 @@ float32_t AudioPlayMemoryI16_F32::getNextAudioValue(void) {

//compute the data index for next time this gets called
data_phase += data_phase_incr; //increment the phase
uint32_t whole_step = (unsigned int)data_phase; //have we increased a whole step yet?
data_ind += whole_step; //increment the data index by any whole steps
data_phase -= (float32_t)whole_step; //remove the whole step from the data_phase to keep it well bounded

unsigned int whole_step = (unsigned int)data_phase; //have we increased a whole step yet?
if (whole_step > 0) {
data_ind += whole_step; //increment the data index by any whole steps
data_phase -= (float32_t)whole_step; //remove the whole step from the data_phase to keep it well bounded
}

return ret_val;
}

2 changes: 1 addition & 1 deletion src/AudioPlayMemory_F32.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ class AudioPlayMemoryI16_F32 : public AudioStream_F32
uint32_t data_len = 0;
float32_t data_sample_rate_Hz = ((float)AUDIO_SAMPLE_RATE_EXACT);
float sample_rate_Hz = ((float)AUDIO_SAMPLE_RATE_EXACT);
//int audio_block_samples = AUDIO_BLOCK_SAMPLES;

//related to the queue of audio samples
AudioPlayMemoryQueue playQueue;
float32_t getNextAudioValue(void);
int queue_ind;

};


Expand Down

0 comments on commit c2f1997

Please sign in to comment.