Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Initial Audio Recording implemented, using AudioQueue to transport a…
…udio to non-RT context, and create buffer & use it.
- Loading branch information
1 parent
cabcff1
commit 07a29e7
Showing
11 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
#include "audioqueue.hpp" | ||
|
||
using namespace std; | ||
|
||
AudioQueue::AudioQueue() | ||
{ | ||
//std::cout << "AudioQueue()" << std::flush; | ||
|
||
// initialize the ringbuffer to 100 elements | ||
buffer = jack_ringbuffer_create( 44100 * 100 * sizeof(float)); | ||
|
||
if ( buffer == 0 ) | ||
{ | ||
cout << "Error creating AudioQueue!" << endl; | ||
} | ||
|
||
// lock the buffer into memory | ||
int res = jack_ringbuffer_mlock(buffer); | ||
if ( res ) | ||
{ | ||
std::cout << "AudioQueue() Error locking memory!" << std::endl; | ||
} | ||
|
||
tempEvent = new float[100*44100]; | ||
} | ||
|
||
void AudioQueue::push(int nframes, float* audioPointer) | ||
{ | ||
unsigned int availableWrite = jack_ringbuffer_write_space(buffer); | ||
|
||
if (availableWrite >= sizeof(float) * nframes ) | ||
{ | ||
unsigned int written = jack_ringbuffer_write( buffer, (const char*)audioPointer , sizeof(float) * nframes ); | ||
|
||
if (written != sizeof(float) * nframes ) | ||
{ | ||
std::cout << "AudioQueue::push() ERROR! didn't write full event!" << std::endl; | ||
} | ||
} | ||
else | ||
{ | ||
std::cout << "AudioQueue::push() ERROR! RingBuffer FULL! Skipping event..." <<std::endl; | ||
} | ||
} | ||
|
||
int AudioQueue::writeSamplesTo(float *writeBuffer) | ||
{ | ||
// check if there's anything to read | ||
int availableRead = jack_ringbuffer_read_space(buffer); | ||
|
||
cout << "AudioQueue::pull() availableRead = " << availableRead << " writeLocation " << writeBuffer << endl; | ||
|
||
int returnValue = 0; | ||
|
||
if ( availableRead >= (long)sizeof(float) ) | ||
{ | ||
// read from the buffer | ||
int result = jack_ringbuffer_read(buffer, (char*)writeBuffer, sizeof(float) * availableRead); | ||
|
||
if ( result != availableRead ) | ||
{ | ||
std::cout << "AudioQueue::pull() WARNING! didn't read all contents! Result = " << result << std::endl; | ||
returnValue = -1; | ||
} | ||
} | ||
|
||
// reset the buffer, so that we start writing @ the start again next time | ||
jack_ringbuffer_reset(buffer); | ||
|
||
// nothing available | ||
return returnValue; | ||
} | ||
|
||
// this function checks if the GUI thread should push events to the Queue | ||
// so that the JACK thread will always have blank EE*'s available | ||
// it should *not* be used for any other purpose! | ||
int AudioQueue::readSpaceAvailable() | ||
{ | ||
int availableReadBytes = (int)jack_ringbuffer_read_space(buffer); | ||
return availableReadBytes; | ||
} | ||
|
||
|
||
AudioQueue::~AudioQueue() | ||
{ | ||
std::cout << "~AudioQueue()" << std::endl; | ||
jack_ringbuffer_free(buffer); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
#ifndef LUPPP_AUDIOQUEUE | ||
#define LUPPP_AUDIOQUEUE | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <iostream> | ||
|
||
#include <cstring> | ||
#include <jack/ringbuffer.h> | ||
|
||
class AudioQueue | ||
{ | ||
public: | ||
AudioQueue(); | ||
~AudioQueue(); | ||
|
||
void push(int,float*); | ||
int writeSamplesTo(float*); | ||
|
||
int readSpaceAvailable(); | ||
|
||
protected: | ||
jack_ringbuffer_t *buffer; | ||
float* tempEvent; | ||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ Top::Top() : | |
void Top::initialize() | ||
{ | ||
scopeVector.resize(bufferSize); | ||
inputScopeVector.resize(bufferSize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters