parse the desired cube side length for injected audio source

This commit is contained in:
Stephen Birarda 2013-06-03 15:38:12 -07:00
parent f3ce68e5e4
commit c55b6a20d7
5 changed files with 44 additions and 3 deletions

View file

@ -32,10 +32,11 @@ bool loopAudio = true;
float sleepIntervalMin = 1.00;
float sleepIntervalMax = 2.00;
char *sourceAudioFile = NULL;
const char *allowedParameters = ":rb::t::c::a::f::d:";
const char *allowedParameters = ":rb::t::c::a::f::d::s:";
float floatArguments[4] = {0.0f, 0.0f, 0.0f, 0.0f};
unsigned char volume = DEFAULT_INJECTOR_VOLUME;
float triggerDistance = 0;
float triggerDistance = 0.0f;
float cubeSideLength = 0.0f;
void usage(void) {
std::cout << "High Fidelity - Interface audio injector" << std::endl;
@ -46,6 +47,7 @@ void usage(void) {
std::cout << " -a 0-255 Attenuation curve modifier, defaults to 255" << std::endl;
std::cout << " -f FILENAME Name of audio source file. Required - RAW format, 22050hz 16bit signed mono" << std::endl;
std::cout << " -d FLOAT Trigger distance for injection. If not specified will loop constantly" << std::endl;
std::cout << " -s FLOAT Length of side of cube audio source. If not specified injected audio is point source" << std::endl;
}
bool processParameters(int parameterCount, char* parameterData[]) {
@ -92,6 +94,10 @@ bool processParameters(int parameterCount, char* parameterData[]) {
::triggerDistance = atof(optarg);
std::cout << "[DEBUG] Trigger distance: " << optarg << std::endl;
break;
case 's':
::cubeSideLength = atof(optarg);
std::cout << "[DEBUG] Cube side length: " << optarg << std::endl;
break;
default:
usage();
return false;
@ -163,6 +169,11 @@ int main(int argc, char* argv[]) {
injector.setPosition(glm::vec3(::floatArguments[0], ::floatArguments[1], ::floatArguments[2]));
injector.setBearing(*(::floatArguments + 3));
injector.setVolume(::volume);
if (::cubeSideLength > 0) {
// if we were passed a cube side length, give that to the injector
injector.setCubeSideLength(::cubeSideLength);
}
// register the callback for agent data creation
agentList->linkedDataCreateCallback = createAvatarDataForAgent;

View file

@ -19,6 +19,7 @@ const int MAX_INJECTOR_VOLUME = 0xFF;
AudioInjector::AudioInjector(const char* filename) :
_position(),
_cubeSideLength(0.0f),
_bearing(0),
_volume(MAX_INJECTOR_VOLUME),
_indexOfNextSlot(0),
@ -48,6 +49,7 @@ AudioInjector::AudioInjector(const char* filename) :
AudioInjector::AudioInjector(int maxNumSamples) :
_numTotalSamples(maxNumSamples),
_position(),
_cubeSideLength(0.0f),
_bearing(0),
_volume(MAX_INJECTOR_VOLUME),
_indexOfNextSlot(0),
@ -75,7 +77,9 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
unsigned char dataPacket[BUFFER_LENGTH_BYTES + leadingBytes];
dataPacket[0] = PACKET_HEADER_INJECT_AUDIO;
unsigned char *currentPacketPtr = dataPacket + 1;
// add the correct command for point source or cube of sound
dataPacket[1] = (_cubeSideLength > 0) ? INJECT_AUDIO_AT_CUBE_COMMAND : INJECT_AUDIO_AT_POINT_COMMAND;
unsigned char *currentPacketPtr = dataPacket + sizeof(PACKET_HEADER) + sizeof(INJECT_AUDIO_AT_POINT_COMMAND);
// copy the identifier for this injector
memcpy(currentPacketPtr, &_streamIdentifier, sizeof(_streamIdentifier));
@ -84,6 +88,13 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
memcpy(currentPacketPtr, &_position, sizeof(_position));
currentPacketPtr += sizeof(_position);
if (_cubeSideLength > 0) {
// if we have a cube half height we need to send it here
// this tells the mixer how much volume the injected audio will occupy
memcpy(currentPacketPtr, &_cubeSideLength, sizeof(_cubeSideLength));
currentPacketPtr += sizeof(_cubeSideLength);
}
*currentPacketPtr = _volume;
currentPacketPtr++;

View file

@ -39,6 +39,9 @@ public:
float getBearing() const { return _bearing; }
void setBearing(float bearing) { _bearing = bearing; }
float getCubeSideLength() const { return _cubeSideLength; }
void setCubeSideLength(float cubeSideLength) { _cubeSideLength = cubeSideLength; }
void addSample(const int16_t sample);
void addSamples(int16_t* sampleBuffer, int numSamples);
private:
@ -46,6 +49,7 @@ private:
int16_t* _audioSampleArray;
int _numTotalSamples;
glm::vec3 _position;
float _cubeSideLength;
float _bearing;
unsigned char _volume;
int _indexOfNextSlot;

View file

@ -17,6 +17,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
AgentData(NULL),
_ringBufferLengthSamples(ringSamples),
_bufferLengthSamples(bufferSamples),
_cubeSideLength(0.0f),
_endOfLastWrite(NULL),
_started(false),
_shouldBeAddedToMix(false),
@ -46,11 +47,21 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
// we've got a stream identifier to pull from the packet
memcpy(&_streamIdentifier, dataBuffer, sizeof(_streamIdentifier));
dataBuffer += sizeof(_streamIdentifier);
// push past the injection command
dataBuffer += sizeof(INJECT_AUDIO_AT_POINT_COMMAND);
}
memcpy(&_position, dataBuffer, sizeof(_position));
dataBuffer += (sizeof(_position));
if (sourceBuffer[0] == PACKET_HEADER_INJECT_AUDIO && sourceBuffer[1] == INJECT_AUDIO_AT_CUBE_COMMAND) {
// this is audio that needs to be injected as a volume (cube)
// parse out the cubeHalfHeight sent by the client
memcpy(&_cubeSideLength, dataBuffer, sizeof(_cubeSideLength));
dataBuffer += (sizeof(_cubeSideLength));
}
unsigned int attenuationByte = *(dataBuffer++);
_attenuationRatio = attenuationByte / 255.0f;

View file

@ -17,6 +17,9 @@
const int STREAM_IDENTIFIER_NUM_BYTES = 8;
const char INJECT_AUDIO_AT_POINT_COMMAND = 'P';
const char INJECT_AUDIO_AT_CUBE_COMMAND = 'C';
class AudioRingBuffer : public AgentData {
public:
AudioRingBuffer(int ringSamples, int bufferSamples);
@ -53,6 +56,7 @@ private:
int _ringBufferLengthSamples;
int _bufferLengthSamples;
glm::vec3 _position;
float _cubeSideLength;
float _attenuationRatio;
float _bearing;
int16_t* _nextOutput;