added test
This commit is contained in:
parent
c836357df0
commit
1d27f89869
BIN
.cache/clangd/index/alsa.c.E9442BF739A32DAC.idx
Normal file
BIN
.cache/clangd/index/alsa.c.E9442BF739A32DAC.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/alsa.h.161732E4A7520D3F.idx
Normal file
BIN
.cache/clangd/index/alsa.h.161732E4A7520D3F.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/atomics.h.785C0F1CDDE2B562.idx
Normal file
BIN
.cache/clangd/index/atomics.h.785C0F1CDDE2B562.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/channel_layout.c.64D21DB5795AE088.idx
Normal file
BIN
.cache/clangd/index/channel_layout.c.64D21DB5795AE088.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/dummy.c.A13755C057E9CFCE.idx
Normal file
BIN
.cache/clangd/index/dummy.c.A13755C057E9CFCE.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/dummy.h.B85A98BBCDCA6486.idx
Normal file
BIN
.cache/clangd/index/dummy.h.B85A98BBCDCA6486.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/endian.h.B74868773E34B088.idx
Normal file
BIN
.cache/clangd/index/endian.h.B74868773E34B088.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/list.h.72C529CD52DC5CCA.idx
Normal file
BIN
.cache/clangd/index/list.h.72C529CD52DC5CCA.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/main.c.98ECACE7E4074434.idx
Normal file
BIN
.cache/clangd/index/main.c.98ECACE7E4074434.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/os.c.1543346EE65249BE.idx
Normal file
BIN
.cache/clangd/index/os.c.1543346EE65249BE.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/os.h.190860774D90D7AE.idx
Normal file
BIN
.cache/clangd/index/os.h.190860774D90D7AE.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/ring_buffer.c.78A68183651F57E5.idx
Normal file
BIN
.cache/clangd/index/ring_buffer.c.78A68183651F57E5.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/ring_buffer.h.E994E73669C856D2.idx
Normal file
BIN
.cache/clangd/index/ring_buffer.h.E994E73669C856D2.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/sio_list_devices.c.41B16F9FB39E5969.idx
Normal file
BIN
.cache/clangd/index/sio_list_devices.c.41B16F9FB39E5969.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/sio_microphone.c.B1B14B81C6C433E6.idx
Normal file
BIN
.cache/clangd/index/sio_microphone.c.B1B14B81C6C433E6.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/sio_record.c.AB318A2A4AF3AB42.idx
Normal file
BIN
.cache/clangd/index/sio_record.c.AB318A2A4AF3AB42.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/sio_sine.c.BF427BE9158106BF.idx
Normal file
BIN
.cache/clangd/index/sio_sine.c.BF427BE9158106BF.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/soundio.c.CDCD219D69D50A52.idx
Normal file
BIN
.cache/clangd/index/soundio.c.CDCD219D69D50A52.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/soundio.h.C4B04A3719114854.idx
Normal file
BIN
.cache/clangd/index/soundio.h.C4B04A3719114854.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/soundio_internal.h.EFE947B56D4FF4BC.idx
Normal file
BIN
.cache/clangd/index/soundio_internal.h.EFE947B56D4FF4BC.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/soundio_private.h.175DDAA8E1121489.idx
Normal file
BIN
.cache/clangd/index/soundio_private.h.175DDAA8E1121489.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/util.c.86DA749D44B2A14D.idx
Normal file
BIN
.cache/clangd/index/util.c.86DA749D44B2A14D.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/util.h.EEFA3F4DAD203C75.idx
Normal file
BIN
.cache/clangd/index/util.h.EEFA3F4DAD203C75.idx
Normal file
Binary file not shown.
@ -20,6 +20,7 @@ set(BUILD_EXAMPLE_PROGRAMS OFF CACHE BOOL "")
|
|||||||
set(BUILD_DYNAMIC_LIBS ON CACHE BOOL "" FORCE)
|
set(BUILD_DYNAMIC_LIBS ON CACHE BOOL "" FORCE)
|
||||||
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
|
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
|
# libsoundio
|
||||||
add_subdirectory("${CMAKE_SOURCE_DIR}/extern/libsoundio")
|
add_subdirectory("${CMAKE_SOURCE_DIR}/extern/libsoundio")
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/extern/libsoundio")
|
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/extern/libsoundio")
|
||||||
|
|
||||||
@ -27,3 +28,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
|
|||||||
$<$<CONFIG:Debug>:libsoundio_shared>
|
$<$<CONFIG:Debug>:libsoundio_shared>
|
||||||
$<$<CONFIG:Release>:libsoundio_static>
|
$<$<CONFIG:Release>:libsoundio_static>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# math
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE m)
|
||||||
|
|||||||
106
src/main.c
106
src/main.c
@ -1,8 +1,108 @@
|
|||||||
|
#include <soundio/soundio.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
int
|
static const float PI = 3.1415926535f;
|
||||||
main(int argc, char *argv[]) {
|
static float seconds_offset = 0.0f;
|
||||||
printf("Hello, %s\n", argv[0]);
|
static void write_callback(struct SoundIoOutStream *outstream,
|
||||||
|
int frame_count_min, int frame_count_max)
|
||||||
|
{
|
||||||
|
const struct SoundIoChannelLayout *layout = &outstream->layout;
|
||||||
|
float float_sample_rate = outstream->sample_rate;
|
||||||
|
float seconds_per_frame = 1.0f / float_sample_rate;
|
||||||
|
struct SoundIoChannelArea *areas;
|
||||||
|
int frames_left = frame_count_max;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
while (frames_left > 0) {
|
||||||
|
int frame_count = frames_left;
|
||||||
|
|
||||||
|
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||||
|
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!frame_count)
|
||||||
|
break;
|
||||||
|
|
||||||
|
float pitch = 440.0f;
|
||||||
|
float radians_per_second = pitch * 2.0f * PI;
|
||||||
|
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||||
|
float sample = sin((seconds_offset + frame * seconds_per_frame) * radians_per_second);
|
||||||
|
for (int channel = 0; channel < layout->channel_count; channel += 1) {
|
||||||
|
float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);
|
||||||
|
*ptr = sample;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seconds_offset = fmod(seconds_offset + seconds_per_frame * frame_count, 1.0);
|
||||||
|
|
||||||
|
if ((err = soundio_outstream_end_write(outstream))) {
|
||||||
|
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
frames_left -= frame_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int err;
|
||||||
|
struct SoundIo *soundio = soundio_create();
|
||||||
|
if (!soundio) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((err = soundio_connect(soundio))) {
|
||||||
|
fprintf(stderr, "error connecting: %s\n", soundio_strerror(err));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
soundio_flush_events(soundio);
|
||||||
|
|
||||||
|
int default_out_device_index = soundio_default_output_device_index(soundio);
|
||||||
|
if (default_out_device_index < 0) {
|
||||||
|
fprintf(stderr, "no output device found\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);
|
||||||
|
if (!device) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Output device: %s\n", device->name);
|
||||||
|
|
||||||
|
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
|
||||||
|
if (!outstream) {
|
||||||
|
fprintf(stderr, "out of memory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
outstream->format = SoundIoFormatFloat32NE;
|
||||||
|
outstream->write_callback = write_callback;
|
||||||
|
|
||||||
|
if ((err = soundio_outstream_open(outstream))) {
|
||||||
|
fprintf(stderr, "unable to open device: %s", soundio_strerror(err));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outstream->layout_error)
|
||||||
|
fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));
|
||||||
|
|
||||||
|
if ((err = soundio_outstream_start(outstream))) {
|
||||||
|
fprintf(stderr, "unable to start device: %s\n", soundio_strerror(err));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
soundio_wait_events(soundio);
|
||||||
|
|
||||||
|
soundio_outstream_destroy(outstream);
|
||||||
|
soundio_device_unref(device);
|
||||||
|
soundio_destroy(soundio);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user