Skip to content
Snippets Groups Projects
Commit 870aefa7 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3946] Init audio buffers after malloc

parent 82e195f9
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,9 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager)
AudioLayer::_echocancelstate = true;
AudioLayer::_noisesuppressstate = true;
// captureFile = new ofstream ("probeFile", ofstream::binary);
}
// Destructor
......@@ -76,6 +79,9 @@ AlsaLayer::~AlsaLayer (void)
delete _converter;
_converter = NULL;
}
// captureFile->close();
// delete captureFile;
}
bool
......@@ -95,6 +101,7 @@ AlsaLayer::closeLayer()
throw;
}
/* Then close the audio devices */
closeCaptureStream();
closePlaybackStream();
......@@ -934,6 +941,7 @@ void AlsaLayer::audioCallback (void)
// Urgent data (dtmf, incoming call signal) come first.
toGet = (urgentAvailBytes < (int) (playbackAvailBytes)) ? urgentAvailBytes : playbackAvailBytes;
out = (SFLDataFormat*) malloc (toGet);
memset (out, 0, toGet);
if (out) {
_urgentRingBuffer.Get (out, toGet, spkrVolume);
......@@ -953,6 +961,7 @@ void AlsaLayer::audioCallback (void)
if (tone && (normalAvailBytes <= 0)) {
out = (SFLDataFormat *) malloc (playbackAvailBytes);
memset (out, 0, playbackAvailBytes);
if (out) {
tone->getNext (out, playbackAvailSmpl, spkrVolume);
......@@ -965,6 +974,7 @@ void AlsaLayer::audioCallback (void)
} else if (file_tone && !_RingtoneHandle && (normalAvailBytes <= 0)) {
out = (SFLDataFormat *) malloc (playbackAvailBytes);
memset (out, 0, playbackAvailBytes);
if (out) {
file_tone->getNext (out, playbackAvailSmpl, spkrVolume);
......@@ -996,6 +1006,7 @@ void AlsaLayer::audioCallback (void)
toGet = (normalAvailBytes < (int) maxNbBytesToGet) ? normalAvailBytes : maxNbBytesToGet;
out = (SFLDataFormat*) malloc (maxNbBytesToGet);
memset (out, 0, maxNbBytesToGet);
if (normalAvailBytes) {
......@@ -1012,6 +1023,8 @@ void AlsaLayer::audioCallback (void)
if (rsmpl_out) {
rsmpl_out = (SFLDataFormat*) malloc (playbackAvailBytes);
memset (out, 0, playbackAvailBytes);
int nbSample = _converter->upsampleData ( (SFLDataFormat*) out, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_down);
write (rsmpl_out, nbSample*sizeof (SFLDataFormat), _PlaybackHandle);
free (rsmpl_out);
......@@ -1139,6 +1152,7 @@ void AlsaLayer::audioCallback (void)
if (filter_out) {
_audiofilter->processAudio (in, filter_out, toPut);
// captureFile->write ( (const char *) filter_out, toPut);
// int sampleready = AudioLayer::_echoCanceller->processAudio (filter_out, echoCancelledMic, toPut);
// getMainBuffer()->putData (echoCancelledMic, sampleready*sizeof (SFLDataFormat), 100);
getMainBuffer()->putData (filter_out, toPut, 100);
......
......@@ -37,6 +37,8 @@
#include "eventthread.h"
#include <alsa/asoundlib.h>
// #include <fstream>
class RingBuffer;
class ManagerImpl;
......@@ -350,6 +352,8 @@ class AlsaLayer : public AudioLayer
/** Sample rate converter object */
SamplerateConverter* _converter;
// ofstream *captureFile;
};
#endif // _ALSA_LAYER_H_
......@@ -33,9 +33,13 @@
#include "managerimpl.h"
// #include <fstream>
int framesPerBuffer = 2048;
static void playback_callback (pa_stream* s, size_t bytes, void* userdata)
{
......@@ -161,7 +165,7 @@ static void source_input_info_callback (pa_context *c UNUSED, const pa_source_in
}
static void context_changed_callback (pa_context* c, pa_subscription_event_type_t t, uint32_t idx, void* userdata)
static void context_changed_callback (pa_context* c, pa_subscription_event_type_t t, uint32_t idx UNUSED, void* userdata)
{
switch (t) {
......@@ -246,11 +250,10 @@ PulseLayer::PulseLayer (ManagerImpl* manager)
byteCounter = 0;
/*
captureFile = new ofstream("captureFile", ofstream::binary);
captureRsmplFile = new ofstream("captureRsmplFile", ofstream::binary);
captureFilterFile = new ofstream("captureFilterFile", ofstream::binary);
*/
// captureFile = new ofstream ("probeCaptureFile", ofstream::binary);
// spkrFile = new ofstream ("probeSpkrFile", ofstream::binary);
openLayer();
}
......@@ -276,15 +279,12 @@ PulseLayer::~PulseLayer (void)
delete AudioLayer::_audiofilter;
AudioLayer::_audiofilter = NULL;
/*
captureFile->close();
captureRsmplFile->close();
captureFilterFile->close();
delete captureFile;
delete captureRsmplFile;
delete captureFilterFile;
*/
// captureFile->close();
// spkrFile->close();
// delete captureFile;
// delete spkrFile;
}
void
......@@ -792,8 +792,11 @@ void PulseLayer::writeToSpeaker (void)
if (urgentAvailBytes > writeableSize) {
out = (SFLDataFormat*) pa_xmalloc (writeableSize);
memset (out, 0, writeableSize);
_urgentRingBuffer.Get (out, writeableSize, 100);
// spkrFile->write ( (const char *) out, writeableSize);
pa_stream_write (playback->pulseStream(), out, writeableSize, NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (out);
......@@ -818,8 +821,11 @@ void PulseLayer::writeToSpeaker (void)
if (playback->getStreamState() == PA_STREAM_READY) {
out = (SFLDataFormat*) pa_xmalloc (writeableSize);
memset (out, 0, writeableSize);
int copied = tone->getNext (out, writeableSize / sizeof (SFLDataFormat), 100);
//spkrFile->write ( (const char *) out, copied*sizeof (SFLDataFormat));
pa_stream_write (playback->pulseStream(), out, copied * sizeof (SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (out);
......@@ -857,6 +863,7 @@ void PulseLayer::writeToSpeaker (void)
byteToGet = byteToGet-1;
out = (SFLDataFormat*) pa_xmalloc (maxNbBytesToGet);
memset (out, 0, maxNbBytesToGet);
getMainBuffer()->getData (out, byteToGet, 100);
......@@ -868,6 +875,7 @@ void PulseLayer::writeToSpeaker (void)
if (_mainBufferSampleRate && ( (int) _audioSampleRate != _mainBufferSampleRate)) {
SFLDataFormat* rsmpl_out = (SFLDataFormat*) pa_xmalloc (writeableSize);
memset (out, 0, writeableSize);
// Do sample rate conversion
int nb_sample_down = byteToGet / sizeof (SFLDataFormat);
......@@ -877,14 +885,16 @@ void PulseLayer::writeToSpeaker (void)
if ( (nbSample*sizeof (SFLDataFormat)) > (unsigned int) writeableSize)
_warn ("Audio: Error: nbsbyte exceed buffer length");
// spkrFile->write ( (const char *) out, nbSample*sizeof (SFLDataFormat));
pa_stream_write (playback->pulseStream(), rsmpl_out, nbSample*sizeof (SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (rsmpl_out);
} else {
// spkrFile->write ( (const char *) out, byteToGet);
pa_stream_write (playback->pulseStream(), out, byteToGet, NULL, 0, PA_SEEK_RELATIVE);
}
......@@ -898,9 +908,9 @@ void PulseLayer::writeToSpeaker (void)
if (tone == 0) {
SFLDataFormat* zeros = (SFLDataFormat*) pa_xmalloc (writeableSize);
bzero (zeros, writeableSize);
// spkrFile->write ( (const char *) zeros, writeableSize);
pa_stream_write (playback->pulseStream(), zeros, writeableSize, NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (zeros);
......@@ -940,13 +950,12 @@ void PulseLayer::readFromMic (void)
if (_mainBufferSampleRate && ( (int) _audioSampleRate != _mainBufferSampleRate)) {
SFLDataFormat* rsmpl_out = (SFLDataFormat*) pa_xmalloc (readableSize);
memset (rsmpl_out, 0, readableSize);
int nbSample = r / sizeof (SFLDataFormat);
int nb_sample_up = nbSample;
// captureFile->write ((const char *)data, nbSample*sizeof(SFLDataFormat));
nbSample = _converter->downsampleData ( (SFLDataFormat *) data, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_up);
// captureRsmplFile->write ((const char *)rsmpl_out, nbSample*sizeof(SFLDataFormat));
......@@ -968,11 +977,15 @@ void PulseLayer::readFromMic (void)
} else {
SFLDataFormat* filter_out = (SFLDataFormat*) pa_xmalloc (r);
memset (filter_out, 0, r);
// remove dc offset
_audiofilter->processAudio ( (SFLDataFormat *) data, filter_out, r);
// captureFile->write ( (const char *) filter_out, r);
// echo cancellation processing
// int sampleready = _echoCanceller->processAudio((SFLDataFormat *)filter_out, echoCancelledMic, r);
......@@ -1007,6 +1020,8 @@ void PulseLayer::ringtoneToSpeaker (void)
if (ringtone->getStreamState() == PA_STREAM_READY) {
out = (SFLDataFormat *) pa_xmalloc (writableSize);
memset (out, 0, writableSize);
int copied = file_tone->getNext (out, writableSize/sizeof (SFLDataFormat), 100);
pa_stream_write (ringtone->pulseStream(), out, copied*sizeof (SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
......@@ -1018,6 +1033,7 @@ void PulseLayer::ringtoneToSpeaker (void)
out = (SFLDataFormat*) pa_xmalloc (writableSize);
memset (out, 0, writableSize);
pa_stream_write (ringtone->pulseStream(), out, writableSize, NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (out);
......
......@@ -292,11 +292,9 @@ class PulseLayer : public AudioLayer
int spkrVolume;
int micVolume;
/*
ofstream *captureFile;
ofstream *captureRsmplFile;
ofstream *captureFilterFile;
*/
// ofstream *captureFile;
// ofstream *spkrFile;
DeviceList _sinkList;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment