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

68 lines
1.6 KiB
C++
Raw Normal View History

//
// 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.
//
2017-07-04 15:50:02 +02:00
#include "AudioInputModule.h"
#include <stdio.h>
2017-06-22 14:48:52 +02:00
#include "../libtgvoip/logging.h"
using namespace tgvoip;
using namespace tgvoip::audio;
2017-07-09 21:12:01 +02:00
AudioInputModule::AudioInputModule(std::string deviceID, void *controller)
{
2017-07-04 15:50:02 +02:00
wrapper = (VoIP *)((VoIPController *)controller)->implData;
2017-07-09 21:12:01 +02:00
wrapper->inputCreated = true;
}
2017-07-09 21:12:01 +02:00
AudioInputModule::~AudioInputModule()
{
wrapper->inputConfigured = false;
wrapper->inputCreated = false;
}
2017-06-28 21:02:15 +02:00
2017-07-09 21:12:01 +02:00
void AudioInputModule::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels)
{
wrapper->inputSampleNumber = 960;
wrapper->inputSampleRate = sampleRate;
wrapper->inputBitsPerSample = bitsPerSample;
wrapper->inputChannels = channels;
wrapper->inputSamplePeriod = 1 / sampleRate * 1000000;
wrapper->inputWritePeriod = 1 / sampleRate * wrapper->inputSampleNumber * 1000000;
wrapper->inputSampleSize = wrapper->inputSampleNumber * wrapper->inputChannels * wrapper->inputBitsPerSample / 8;
2017-06-28 21:02:15 +02:00
2017-07-09 21:12:01 +02:00
wrapper->inputConfigured = true;
}
2017-07-09 21:12:01 +02:00
void AudioInputModule::Start()
{
if (wrapper->inputRunning)
2017-06-19 15:39:45 +02:00
return;
2017-07-09 21:12:01 +02:00
wrapper->inputRunning = true;
}
2017-07-09 21:12:01 +02:00
void AudioInputModule::Stop()
{
wrapper->inputRunning = false;
}
2017-07-09 21:12:01 +02:00
bool AudioInputModule::writeSamples(unsigned char *data)
{
if (wrapper->inputRunning)
{
2017-06-28 21:02:15 +02:00
LOGE("STARTED");
2017-07-09 21:12:01 +02:00
InvokeCallback(data, wrapper->inputSampleSize);
2017-06-28 21:02:15 +02:00
return true;
2017-07-09 21:12:01 +02:00
}
else
{
2017-06-28 21:02:15 +02:00
LOGE("NOT STARTED");
return false;
2017-07-09 21:12:01 +02:00
}
2017-06-19 23:38:03 +02:00
}
2017-07-04 15:50:02 +02:00
2017-07-09 21:12:01 +02:00
void AudioInputModule::EnumerateDevices(std::vector<AudioInputDevice> &devs)
{
2017-07-04 15:50:02 +02:00
}