Add accessors to audio::mixer
This commit is contained in:
parent
dd16d8be84
commit
202692a56a
@ -44,7 +44,7 @@ namespace audio::impl{
|
|||||||
audio::stream m_output_sink;
|
audio::stream m_output_sink;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mixer(int output_channels, size_t channel_count);
|
mixer(int output_channels, size_t channel_count, size_t samplerate);
|
||||||
mixer(const mixer&) = delete;
|
mixer(const mixer&) = delete;
|
||||||
mixer(mixer&&) = delete;
|
mixer(mixer&&) = delete;
|
||||||
~mixer();
|
~mixer();
|
||||||
@ -67,6 +67,10 @@ namespace audio::impl{
|
|||||||
bool should_exit()const;
|
bool should_exit()const;
|
||||||
void exit();
|
void exit();
|
||||||
size_t output_channels()const;
|
size_t output_channels()const;
|
||||||
|
|
||||||
|
size_t get_samplerate()const;
|
||||||
|
size_t channel_count()const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int callback(const void* /*input*/, void* output, unsigned long frame_count, unsigned long flags, mixer& mix);
|
static int callback(const void* /*input*/, void* output, unsigned long frame_count, unsigned long flags, mixer& mix);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace audio{
|
|||||||
private:
|
private:
|
||||||
impl::mixer* m_mix;
|
impl::mixer* m_mix;
|
||||||
public:
|
public:
|
||||||
mixer(mode m, size_t channel_count);
|
mixer(mode m, size_t channel_count, size_t samplerate = 48000);
|
||||||
mixer(const mixer&) = delete;
|
mixer(const mixer&) = delete;
|
||||||
mixer(mixer&&) = delete;
|
mixer(mixer&&) = delete;
|
||||||
~mixer();
|
~mixer();
|
||||||
@ -56,6 +56,9 @@ namespace audio{
|
|||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
size_t get_samplerate()const;
|
||||||
|
size_t channel_count()const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,7 @@ namespace audio{
|
|||||||
detail::callback_iface* m_cb = nullptr;
|
detail::callback_iface* m_cb = nullptr;
|
||||||
PaStream* m_stream = nullptr;
|
PaStream* m_stream = nullptr;
|
||||||
mutable PaError m_err = paNoError;
|
mutable PaError m_err = paNoError;
|
||||||
|
double m_samplerate;
|
||||||
int m_in_channels;
|
int m_in_channels;
|
||||||
int m_out_channels;
|
int m_out_channels;
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ namespace audio{
|
|||||||
m_cb(new detail::callback_impl<Callback,Args...>(std::forward<Callback>(cb), std::forward<Args>(cbargs)...)),
|
m_cb(new detail::callback_impl<Callback,Args...>(std::forward<Callback>(cb), std::forward<Args>(cbargs)...)),
|
||||||
m_stream(initialize_global_instance()),
|
m_stream(initialize_global_instance()),
|
||||||
m_err(open_default_stream(&m_stream, in_c, out_c, paFloat32, samplerate, buffersize, m_cb)),
|
m_err(open_default_stream(&m_stream, in_c, out_c, paFloat32, samplerate, buffersize, m_cb)),
|
||||||
|
m_samplerate(samplerate),
|
||||||
m_in_channels(in_c),
|
m_in_channels(in_c),
|
||||||
m_out_channels(out_c){}
|
m_out_channels(out_c){}
|
||||||
|
|
||||||
@ -62,6 +64,8 @@ namespace audio{
|
|||||||
int input_count()const;
|
int input_count()const;
|
||||||
int output_count()const;
|
int output_count()const;
|
||||||
|
|
||||||
|
double get_samplerate()const;
|
||||||
|
|
||||||
error last_error()const;
|
error last_error()const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -28,13 +28,13 @@ namespace audio::impl{
|
|||||||
return (left < right) ? left : right;
|
return (left < right) ? left : right;
|
||||||
}
|
}
|
||||||
|
|
||||||
mixer::mixer(int output_channels, size_t channel_count):
|
mixer::mixer(int output_channels, size_t channel_count, size_t samplerate):
|
||||||
m_paused(false),
|
m_paused(false),
|
||||||
m_exit(false),
|
m_exit(false),
|
||||||
m_operating(false),
|
m_operating(false),
|
||||||
m_channels(channel_count),
|
m_channels(channel_count),
|
||||||
m_lk(m_copy_lock, std::defer_lock),
|
m_lk(m_copy_lock, std::defer_lock),
|
||||||
m_output_sink(0, output_channels, 44100, 0, callback, *this)
|
m_output_sink(0, output_channels, samplerate, 0, callback, *this)
|
||||||
{
|
{
|
||||||
m_output_sink.start();
|
m_output_sink.start();
|
||||||
}
|
}
|
||||||
@ -100,6 +100,12 @@ namespace audio::impl{
|
|||||||
size_t mixer::output_channels()const{
|
size_t mixer::output_channels()const{
|
||||||
return m_output_sink.output_count();
|
return m_output_sink.output_count();
|
||||||
}
|
}
|
||||||
|
size_t mixer::get_samplerate()const{
|
||||||
|
return m_output_sink.get_samplerate();
|
||||||
|
}
|
||||||
|
size_t mixer::channel_count()const{
|
||||||
|
return m_channels.size();
|
||||||
|
}
|
||||||
int mixer::callback(const void* /*input*/, void* output, unsigned long frame_count, unsigned long flags, mixer& mix){
|
int mixer::callback(const void* /*input*/, void* output, unsigned long frame_count, unsigned long flags, mixer& mix){
|
||||||
if(flags & paPrimingOutput)
|
if(flags & paPrimingOutput)
|
||||||
return paContinue;
|
return paContinue;
|
||||||
|
|||||||
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
namespace audio{
|
namespace audio{
|
||||||
|
|
||||||
mixer::mixer(mode m, size_t channel_count):
|
mixer::mixer(mode m, size_t channel_count, size_t samplerate):
|
||||||
m_mix(new impl::mixer(static_cast<int>(m), channel_count)){}
|
m_mix(new impl::mixer(static_cast<int>(m), channel_count, samplerate)){}
|
||||||
mixer::~mixer(){
|
mixer::~mixer(){
|
||||||
delete m_mix;
|
delete m_mix;
|
||||||
}
|
}
|
||||||
@ -60,4 +60,10 @@ namespace audio{
|
|||||||
m_mix->exit();
|
m_mix->exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t mixer::get_samplerate()const{
|
||||||
|
return m_mix->get_samplerate();
|
||||||
|
}
|
||||||
|
size_t mixer::channel_count()const{
|
||||||
|
return m_mix->channel_count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,9 @@ namespace audio{
|
|||||||
return m_out_channels;
|
return m_out_channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double stream::get_samplerate()const{
|
||||||
|
return m_samplerate;
|
||||||
|
}
|
||||||
|
|
||||||
error stream::last_error()const{
|
error stream::last_error()const{
|
||||||
return error(m_err);
|
return error(m_err);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user