mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
Reinitialize stream if format params change.
This commit is contained in:
parent
96be500dd1
commit
4c8123390c
@ -242,6 +242,8 @@ void PortAudioOut::Stop() {
|
||||
std::unique_lock<decltype(this->mutex)> lock(this->mutex);
|
||||
if (this->paStream) {
|
||||
logPaError("Pa_AbortStream", Pa_AbortStream(this->paStream));
|
||||
logPaError("Pa_AbortStream", Pa_CloseStream(this->paStream));
|
||||
this->paStream = nullptr;
|
||||
}
|
||||
this->state = StateStopped;
|
||||
this->buffers.swap(swap);
|
||||
@ -313,6 +315,11 @@ OutputState PortAudioOut::Play(IBuffer *buffer, IBufferProvider *provider) {
|
||||
return static_cast<OutputState>(retryMs);
|
||||
}
|
||||
|
||||
if (!this->formatContext.IsSame(buffer)) {
|
||||
this->Stop();
|
||||
this->formatContext.From(buffer);
|
||||
}
|
||||
|
||||
if (!this->paStream) {
|
||||
auto device = static_cast<PortAudioDevice*>(this->GetDefaultDevice());
|
||||
if (device) {
|
||||
|
@ -84,6 +84,20 @@ class PortAudioOut : public IOutput {
|
||||
StateDraining,
|
||||
};
|
||||
|
||||
struct FormatContext {
|
||||
bool IsSame(IBuffer* buffer) {
|
||||
return
|
||||
this->sampleRate == buffer->SampleRate() &&
|
||||
this->channels == buffer->Channels();
|
||||
}
|
||||
void From(IBuffer* buffer) {
|
||||
this->sampleRate = buffer->SampleRate();
|
||||
this->channels = buffer->Channels();
|
||||
}
|
||||
long sampleRate { 0 };
|
||||
long channels { 0 };
|
||||
};
|
||||
|
||||
struct BufferContext {
|
||||
BufferContext(IBuffer* buffer, IBufferProvider* provider) {
|
||||
this->buffer = buffer;
|
||||
@ -102,6 +116,7 @@ class PortAudioOut : public IOutput {
|
||||
PaStream* paStream { nullptr };
|
||||
IDeviceList* deviceList { nullptr };
|
||||
std::deque<std::shared_ptr<BufferContext>> buffers;
|
||||
FormatContext formatContext;
|
||||
State state;
|
||||
double volume;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user