mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Add mal_sine_wave_read_ex().
This commit is contained in:
@@ -2632,8 +2632,9 @@ typedef struct
|
|||||||
double time;
|
double time;
|
||||||
} mal_sine_wave;
|
} mal_sine_wave;
|
||||||
|
|
||||||
mal_result mal_sine_wave_init(double amplitude, double period, mal_uint32 sampleRate, mal_sine_wave* pSignWave);
|
mal_result mal_sine_wave_init(double amplitude, double period, mal_uint32 sampleRate, mal_sine_wave* pSineWave);
|
||||||
mal_uint64 mal_sine_wave_read(mal_sine_wave* pSignWave, mal_uint64 count, float* pSamples);
|
mal_uint64 mal_sine_wave_read(mal_sine_wave* pSineWave, mal_uint64 count, float* pSamples);
|
||||||
|
mal_uint64 mal_sine_wave_read_ex(mal_sine_wave* pSineWave, mal_uint64 frameCount, mal_uint32 channels, mal_stream_layout layout, float** ppFrames);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -27354,21 +27355,36 @@ mal_result mal_sine_wave_init(double amplitude, double periodsPerSecond, mal_uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
mal_uint64 mal_sine_wave_read(mal_sine_wave* pSineWave, mal_uint64 count, float* pSamples)
|
mal_uint64 mal_sine_wave_read(mal_sine_wave* pSineWave, mal_uint64 count, float* pSamples)
|
||||||
|
{
|
||||||
|
return mal_sine_wave_read_ex(pSineWave, count, 1, mal_stream_layout_interleaved, &pSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
mal_uint64 mal_sine_wave_read_ex(mal_sine_wave* pSineWave, mal_uint64 frameCount, mal_uint32 channels, mal_stream_layout layout, float** ppFrames)
|
||||||
{
|
{
|
||||||
if (pSineWave == NULL) {
|
if (pSineWave == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSamples != NULL) {
|
if (ppFrames != NULL) {
|
||||||
for (mal_uint64 i = 0; i < count; i += 1) {
|
for (mal_uint64 iFrame = 0; iFrame < frameCount; iFrame += 1) {
|
||||||
pSamples[i] = (float)(sin(pSineWave->time * pSineWave->periodsPerSecond) * pSineWave->amplitude);
|
float s = (float)(sin(pSineWave->time * pSineWave->periodsPerSecond) * pSineWave->amplitude);
|
||||||
pSineWave->time += pSineWave->delta;
|
pSineWave->time += pSineWave->delta;
|
||||||
|
|
||||||
|
if (layout == mal_stream_layout_interleaved) {
|
||||||
|
for (mal_uint32 iChannel = 0; iChannel < channels; iChannel += 1) {
|
||||||
|
ppFrames[0][iFrame*channels + iChannel] = s;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pSineWave->time += pSineWave->delta * count;
|
for (mal_uint32 iChannel = 0; iChannel < channels; iChannel += 1) {
|
||||||
|
ppFrames[iChannel][iFrame] = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pSineWave->time += pSineWave->delta * frameCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return frameCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -27387,6 +27403,7 @@ mal_uint64 mal_sine_wave_read(mal_sine_wave* pSineWave, mal_uint64 count, float*
|
|||||||
// Raspberry Pi experience.
|
// Raspberry Pi experience.
|
||||||
// - Fix a bug where an incorrect number of samples is returned from sinc resampling.
|
// - Fix a bug where an incorrect number of samples is returned from sinc resampling.
|
||||||
// - Add support for setting the value to be passed to internal calls to CoInitializeEx().
|
// - Add support for setting the value to be passed to internal calls to CoInitializeEx().
|
||||||
|
// - WASAPI and WinMM: Stop the device when it is unplugged.
|
||||||
//
|
//
|
||||||
// v0.8.4 - 2018-08-06
|
// v0.8.4 - 2018-08-06
|
||||||
// - Add sndio backend for OpenBSD.
|
// - Add sndio backend for OpenBSD.
|
||||||
|
|||||||
@@ -24,16 +24,14 @@ void on_stop(mal_device* pDevice)
|
|||||||
mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut)
|
mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut)
|
||||||
{
|
{
|
||||||
mal_assert(pDevice != NULL);
|
mal_assert(pDevice != NULL);
|
||||||
mal_assert(pDevice->channels == 1);
|
|
||||||
(void)pDevice;
|
|
||||||
|
|
||||||
//printf("TESTING: %d\n", frameCount);
|
//printf("TESTING: %d\n", frameCount);
|
||||||
return (mal_uint32)mal_sine_wave_read(&g_sineWave, frameCount, (float*)pFramesOut);
|
return (mal_uint32)mal_sine_wave_read_ex(&g_sineWave, frameCount, pDevice->channels, mal_stream_layout_interleaved, (float**)&pFramesOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
mal_backend backend = mal_backend_alsa;
|
mal_backend backend = mal_backend_wasapi;
|
||||||
|
|
||||||
mal_result result = mal_sine_wave_init(0.25f, 400, 48000, &g_sineWave);
|
mal_result result = mal_sine_wave_init(0.25f, 400, 48000, &g_sineWave);
|
||||||
if (result != MAL_SUCCESS) {
|
if (result != MAL_SUCCESS) {
|
||||||
@@ -42,7 +40,7 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
mal_context_config contextConfig = mal_context_config_init(on_log);
|
mal_context_config contextConfig = mal_context_config_init(on_log);
|
||||||
mal_device_config deviceConfig = mal_device_config_init_playback(mal_format_f32, 1, 48000, on_send);
|
mal_device_config deviceConfig = mal_device_config_init_playback(mal_format_f32, 0, 48000, on_send);
|
||||||
deviceConfig.onStopCallback = on_stop;
|
deviceConfig.onStopCallback = on_stop;
|
||||||
|
|
||||||
mal_device device;
|
mal_device device;
|
||||||
|
|||||||
Reference in New Issue
Block a user