Clarifying record_queue_f32

pull/5/head
Chip Audette 8 years ago
parent 33dfdcc328
commit 175c9f5b8f
  1. 15
      AudioConvert_F32.h
  2. 14
      record_queue_f32.cpp

@ -2,7 +2,6 @@
#ifndef _AudioConvert_I16toF32_h
#define _AudioConvert_I16toF32_h
#include <AudioStream_F32.h>
class AudioConvert_I16toF32 : public AudioStream_F32 //receive Int and transmits Float
@ -10,16 +9,19 @@ class AudioConvert_I16toF32 : public AudioStream_F32 //receive Int and transmits
//GUI: inputs:1, outputs:1 //this line used for automatic generation of GUI node
public:
AudioConvert_I16toF32(void) : AudioStream_F32(1, inputQueueArray_f32) { };
void update(void) {
void update(void) {
//get the Int16 block
audio_block_t *int_block;
int_block = AudioStream::receiveReadOnly(); //int16 data block
if (!int_block) return;
if (int_block==NULL) return;
//allocate a float block
audio_block_f32_t *float_block;
float_block = AudioStream_F32::allocate_f32();
if (float_block == NULL) return;
if (float_block == NULL) {
AudioStream::release(int_block);
return;
}
//convert to float
convertAudio_I16toF32(int_block, float_block, AUDIO_BLOCK_SAMPLES);
@ -57,7 +59,10 @@ class AudioConvert_F32toI16 : public AudioStream_F32 //receive Float and transmi
//allocate a Int16 block
audio_block_t *int_block;
int_block = AudioStream::allocate();
if (int_block == NULL) return;
if (int_block == NULL) {
AudioStream_F32::release(float_block);
return;
}
//convert back to int16
convertAudio_F32toI16(float_block, int_block, AUDIO_BLOCK_SAMPLES);

@ -43,13 +43,13 @@ void AudioRecordQueue_F32::clear(void)
uint32_t t;
if (userblock) {
release(userblock);
AudioStream_F32::release(userblock);
userblock = NULL;
}
t = tail;
while (t != head) {
if (++t >= 53) t = 0;
release(queue[t]);
AudioStream_F32::release(queue[t]);
}
tail = t;
}
@ -72,7 +72,7 @@ audio_block_f32_t * AudioRecordQueue_F32::getAudioBlock(void)
{
uint32_t t;
if (userblock) return NULL;
if (userblock != NULL) return NULL;
t = tail;
if (t == head) return NULL;
if (++t >= 53) t = 0;
@ -84,7 +84,7 @@ audio_block_f32_t * AudioRecordQueue_F32::getAudioBlock(void)
void AudioRecordQueue_F32::freeBuffer(void)
{
if (userblock == NULL) return;
release(userblock);
AudioStream_F32::release(userblock);
userblock = NULL;
}
@ -98,15 +98,15 @@ void AudioRecordQueue_F32::update(void)
uint32_t h;
block = receiveReadOnly_f32();
if (!block) return;
if (block==NULL) return;
if (!enabled) {
release(block);
AudioStream_F32::release(block);
return;
}
h = head + 1;
if (h >= 53) h = 0;
if (h == tail) {
release(block);
AudioStream_F32::release(block);
} else {
queue[h] = block;
head = h;

Loading…
Cancel
Save