Clarifying record_queue_f32

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

@ -2,7 +2,6 @@
#ifndef _AudioConvert_I16toF32_h #ifndef _AudioConvert_I16toF32_h
#define _AudioConvert_I16toF32_h #define _AudioConvert_I16toF32_h
#include <AudioStream_F32.h> #include <AudioStream_F32.h>
class AudioConvert_I16toF32 : public AudioStream_F32 //receive Int and transmits Float class AudioConvert_I16toF32 : public AudioStream_F32 //receive Int and transmits Float
@ -14,12 +13,15 @@ class AudioConvert_I16toF32 : public AudioStream_F32 //receive Int and transmits
//get the Int16 block //get the Int16 block
audio_block_t *int_block; audio_block_t *int_block;
int_block = AudioStream::receiveReadOnly(); //int16 data block int_block = AudioStream::receiveReadOnly(); //int16 data block
if (!int_block) return; if (int_block==NULL) return;
//allocate a float block //allocate a float block
audio_block_f32_t *float_block; audio_block_f32_t *float_block;
float_block = AudioStream_F32::allocate_f32(); float_block = AudioStream_F32::allocate_f32();
if (float_block == NULL) return; if (float_block == NULL) {
AudioStream::release(int_block);
return;
}
//convert to float //convert to float
convertAudio_I16toF32(int_block, float_block, AUDIO_BLOCK_SAMPLES); 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 //allocate a Int16 block
audio_block_t *int_block; audio_block_t *int_block;
int_block = AudioStream::allocate(); int_block = AudioStream::allocate();
if (int_block == NULL) return; if (int_block == NULL) {
AudioStream_F32::release(float_block);
return;
}
//convert back to int16 //convert back to int16
convertAudio_F32toI16(float_block, int_block, AUDIO_BLOCK_SAMPLES); convertAudio_F32toI16(float_block, int_block, AUDIO_BLOCK_SAMPLES);

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

Loading…
Cancel
Save