1
0
mirror of https://github.com/danog/php-libtgvoip.git synced 2024-12-03 09:47:51 +01:00
php-libtgvoip/audio/AudioOutputModule.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

2017-07-04 15:50:02 +02:00
//
// libtgvoip is free and unencumbered public domain software.
// For more information, see http://unlicense.org or the UNLICENSE file
// you should have received with this source code distribution.
//
#include "AudioOutputModule.h"
#include <stdio.h>
#include "../libtgvoip/logging.h"
using namespace tgvoip;
using namespace tgvoip::audio;
2017-07-09 21:12:01 +02:00
AudioOutputModule::AudioOutputModule(std::string deviceID, void *controller)
{
2017-07-04 15:50:02 +02:00
wrapper = (VoIP *)((VoIPController *)controller)->implData;
2017-07-10 12:30:13 +02:00
wrapper->out = this;
2017-07-10 00:06:50 +02:00
wrapper->outputState = AUDIO_STATE_CREATED;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
AudioOutputModule::~AudioOutputModule()
{
2017-07-10 00:06:50 +02:00
wrapper->outputState = AUDIO_STATE_NONE;
2017-07-10 12:30:13 +02:00
wrapper->out = NULL;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
void AudioOutputModule::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels)
{
wrapper->outputSampleNumber = 960;
wrapper->outputSampleRate = sampleRate;
wrapper->outputBitsPerSample = bitsPerSample;
wrapper->outputChannels = channels;
2017-07-11 14:58:04 +02:00
wrapper->outputSamplePeriod = 1.0 / sampleRate * 1000000;
wrapper->outputWritePeriod = 1.0 / sampleRate * wrapper->outputSampleNumber * 1000000;
wrapper->outputSamplesSize = (wrapper->outputSampleNumber * wrapper->outputChannels * wrapper->outputBitsPerSample) / 8;
2017-07-04 15:50:02 +02:00
2017-07-10 00:06:50 +02:00
wrapper->outputState = AUDIO_STATE_CONFIGURED;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
void AudioOutputModule::Start()
{
2017-07-10 00:06:50 +02:00
if (wrapper->outputState == AUDIO_STATE_RUNNING)
2017-07-04 15:50:02 +02:00
return;
2017-07-10 00:06:50 +02:00
wrapper->outputState = AUDIO_STATE_RUNNING;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
void AudioOutputModule::Stop()
{
2017-07-10 00:06:50 +02:00
if (wrapper->outputState != AUDIO_STATE_RUNNING)
2017-07-04 15:50:02 +02:00
return;
2017-07-10 00:06:50 +02:00
wrapper->outputState = AUDIO_STATE_CONFIGURED;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
bool AudioOutputModule::IsPlaying()
{
2017-07-10 00:06:50 +02:00
return wrapper->outputState == AUDIO_STATE_RUNNING;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
float AudioOutputModule::GetLevel()
{
return wrapper->outputLevel;
2017-07-04 15:50:02 +02:00
}
2017-07-09 21:12:01 +02:00
unsigned char *AudioOutputModule::readSamples()
{
2017-07-10 00:06:50 +02:00
unsigned char *buf = (unsigned char *)emalloc(wrapper->outputSamplesSize);
InvokeCallback(buf, wrapper->outputSamplesSize);
2017-07-04 15:50:02 +02:00
return buf;
}
2017-07-09 21:12:01 +02:00
void AudioOutputModule::EnumerateDevices(std::vector<AudioOutputDevice> &devs)
{
2017-07-04 15:50:02 +02:00
}